Data Sources¶
Warning
This document is only applicable to the API server component.
Data sources are logical objects through which database connections can be acquired.
How It Works¶
Data sources are configured using properties in the following format:
For available properties, and their environment variable equivalents, refer to the configuration reference.
Tip
When <name> is omitted, default is assumed.
This means that dt.datasource.url and dt.datasource.default.url are treated equally.
The default data source is required. It's used to serve the REST API,
as well as the vast majority of background processing.
Certain features of Dependency-Track can be configured to use
a different data source than default. For example, the
database secret management provider.
Instead of database connection details, they accept a data source name, e.g. via
dt.secret-management.database.datasource.name.
The main use case for this capability is to prevent features from
saturating the default connection pool and vice versa. In the future,
this mechanism may also be used to allow configuration of read-replicas
to serve certain data faster without impacting the primary database.
Here's how configuring multiple data sources would look in practice:
Note
Data sources are instantiated on first use. You can configure as many data sources as you like, but unless they're being used by a feature, they will not be created.
Connection Pooling¶
Local¶
Local connection pooling involves each Dependency-Track instance maintaining its own pool of database connections. This works well for small to medium deployments (i.e., 1-5 instances).
Connection pooling can be configured using the following properties:
dt.datasource.<name>.pool.enableddt.datasource.<name>.urldt.datasource.<name>.usernamedt.datasource.<name>.passworddt.datasource.<name>.password-filedt.datasource.<name>.pool.max-sizedt.datasource.<name>.pool.min-idledt.datasource.<name>.pool.max-lifetime-msdt.datasource.<name>.pool.idle-timeout-ms
If you plan on deploying multiple instances, make sure your PostgreSQL database can handle the sum of connections from all connection pools.
Say you configure dt.datasource.pool.max-size=30, and you deploy 5 instances,
your database should be configured to handle up to 30 * 5 = 150 connections.
By default, PostgreSQL limits connections to 100. You can tweak this using
the max_connections setting.
Centralised¶
For large deployments (i.e., upwards of 5 instances), it can become undesirable for each instance to maintain its own connection pool. In this case, you can leverage centralised connection pools such as PgBouncer.
Warning
When using a central connection pooler, you must disable local connection pooling
for all data sources, using dt.datasource.<name>.pool.enabled=false.
Constraints¶
Before proceeding, take note of the following constraints:
- Only
sessionandtransactionpooling modes are supported.transactionis recommended. - Initialisation tasks, which include database migrations, must connect to the
database directly, bypassing the connection pooler, when using pooling mode
transaction.- To prevent concurrent initialisation, session-level PostgreSQL advisory locks are used,
which are not supported with the
transactionpooling mode. - To facilitate this, initialisation tasks can be executed in dedicated containers, and / or using separate data sources.
- To prevent concurrent initialisation, session-level PostgreSQL advisory locks are used,
which are not supported with the