Guide: Configuration Reference

August 19, 2026 · View on GitHub

Purpose

A complete reference of every DataSourceBuilder setting, its default value, and the equivalent property key for file-based / external configuration. Use this alongside the task-focused guides (pool creation, read-only pools, validation, Aurora) when you need to know exactly what a setting does or what it defaults to.


Two ways to configure

1. Programmatic (builder)

DataSourcePool pool = DataSourcePool.builder()
  .name("mypool")
  .url("jdbc:postgresql://localhost:5432/myapp")
  .username("app_user")
  .password("password")
  .minConnections(5)
  .maxConnections(50)
  .build();

2. Properties (external configuration)

The builder can load settings from java.util.Properties. There are three entry points:

Properties props = ...; // loaded from file, env, avaje-config, Spring, etc.

// (a) no prefix: keys are "username", "url", ...
DataSourcePool pool = DataSourcePool.builder().load(props).build();

// (b) custom prefix: keys are "my-db.username", "my-db.url", ...
DataSourcePool pool = DataSourcePool.builder().load(props, "my-db").build();

// (c) "datasource.<poolName>." prefix: keys are "datasource.hr.username", ...
DataSourcePool pool = DataSourcePool.builder().loadSettings(props, "hr").build();

Example properties file using the loadSettings convention with pool name hr:

datasource.hr.username=app_user
datasource.hr.password=password
datasource.hr.url=jdbc:postgresql://localhost:5432/myapp
datasource.hr.minConnections=5
datasource.hr.maxConnections=50
datasource.hr.leakTimeMinutes=30

When used through Ebean ORM, these datasource.<name>.* properties are typically placed in application.yaml / application.properties and loaded for you via avaje-config.

Property keys are matched case-insensitively.


Connection settings

Builder methodProperty keyDefaultDescription
url(String)url (or databaseUrl)JDBC URL.
username(String)usernameDatabase username.
password(String)passwordDatabase password.
readOnlyUrl(String)readOnlyUrlOptional separate URL for read-only connections.
driver(...) / driver(String)driver (or databaseDriver)auto from URLJDBC driver class / instance.
schema(String)schemadriver defaultDefault schema applied to connections.
catalog(String)catalogdriver defaultDefault catalog applied to connections.
isolationLevel(int)isolationLevelREAD_COMMITTEDTransaction isolation level. Property accepts names e.g. READ_COMMITTED.
autoCommit(boolean)autoCommitfalseAuto-commit mode for pooled connections.
readOnly(boolean)readOnlyfalseMark connections read-only (optimises read workloads).
applicationName(String)applicationNameApplication name reported to the driver where supported.
clientInfo(Properties)clientInfoClient info properties (semicolon separated key=value in properties form).
customProperties(Map) / addProperty(...)customPropertiesExtra JDBC driver connection properties (semicolon separated key=value in properties form).
initSql(List<String>)initSqlSQL run on each new connection (semicolon separated statements in properties form). See per-connection init below.

Pool sizing

Builder methodProperty keyDefaultDescription
minConnections(int)minConnections2Minimum connections maintained in the pool.
initialConnections(int)initialConnections= minConnectionsConnections created on startup. Set higher than min for smooth warm-up (Kubernetes).
maxConnections(int)maxConnections200Maximum connections. Threads block (up to waitTimeout) when this is reached.

Timeouts, trimming and ageing

Builder methodProperty keyDefaultDescription
waitTimeoutMillis(int)waitTimeout1000Millis a thread waits for a free connection once the pool is at max before throwing ConnectionPoolExhaustedException.
slowCreationMillis(int)slowCreationMillis100Log new physical connection creation at INFO when it exceeds this threshold. Set to 0 to disable slow creation logging.
maxInactiveTimeSecs(int)maxInactiveTimeSecs900Idle seconds after which a free connection can be trimmed back towards minConnections.
maxAgeMinutes(int)maxAgeMinutes0 (unlimited)Maximum age of a connection before it is trimmed regardless of activity.
trimPoolFreqSecs(int)trimPoolFreqSecs59How often the background trim check runs.

Health checks / heartbeat

Builder methodProperty keyDefaultDescription
validateOnHeartbeat(boolean)validateOnHeartbeattrue (false in AWS Lambda)Enable the background heartbeat that validates the pool.
heartbeatFreqSecs(int)(builder only)30How often the heartbeat runs.
heartbeatTimeoutSeconds(int)heartbeatTimeoutSeconds30Query timeout for the heartbeat validation.
heartbeatSql(String)heartbeatSqlConnection.isValid() / platform defaultExplicit validation SQL. Rarely needed — see the validation guide.
heartbeatMaxPoolExhaustedCount(int)(builder only)10Consecutive heartbeat pool-exhaustion detections before the pool is reset (leak recovery).

See Connection Validation Best Practices for details.

Leak detection / diagnostics

Builder methodProperty keyDefaultDescription
leakTimeMinutes(int)leakTimeMinutes30A busy (checked-out) connection older than this is treated as a leak and force-closed during a pool reset.
captureStackTrace(boolean)captureStackTracefalseCapture the stack trace when a connection is obtained, to locate leaks. Has a performance cost.
maxStackTraceSize(int)maxStackTraceSize5Number of stack frames reported for busy connections.

See Troubleshooting Connection Leaks & Pool Exhaustion.

Statement caching

Builder methodProperty keyDefaultDescription
pstmtCacheSize(int)pstmtCacheSize300PreparedStatement cache size, per connection.
cstmtCacheSize(int)cstmtCacheSize20CallableStatement cache size, per connection.

Lifecycle / startup

Builder methodProperty keyDefaultDescription
failOnStart(boolean)failOnStarttrueWhen false, the pool starts even if the database is unavailable (it recovers later via heartbeat).
offline(boolean)offlinefalseStart the pool offline (no connections created until online()).
shutdownOnJvmExit(boolean)shutdownOnJvmExitfalseRegister a JVM shutdown hook to close the pool on exit.
enforceCleanClose(boolean)enforceCleanClosefalseThrow if a dirty (uncommitted) connection is closed. Recommended in tests. See issue #116.

Hooks and extension points

Builder methodProperty keyDescription
connectionInitializer(NewConnectionInitializer)(builder only)Hook called when each new connection is created (preInitialize / postInitialize).
defaultConnectionInitializer(NewConnectionInitializer)(builder only)Fallback initializer used only if one is not otherwise set.
listener(DataSourcePoolListener)(builder only)Callbacks on borrow (onAfterBorrowConnection) and return (onBeforeReturnConnection).
poolListener(String)poolListenerClass name of a DataSourcePoolListener to instantiate.
alert(DataSourceAlert)(builder only)Callbacks for dataSourceUp / dataSourceDown (outage alerting). See Monitoring.

Per-connection initialization

Use initSql for simple statements, or a NewConnectionInitializer for programmatic control. This is the right place to set things like a Postgres search_path or a per-session statement_timeout.

DataSourcePool pool = DataSourcePool.builder()
  .name("mypool")
  .url("jdbc:postgresql://localhost:5432/myapp")
  .username("app_user")
  .password("password")
  .initSql(List.of("set search_path to app, public"))
  .connectionInitializer(new NewConnectionInitializer() {
    @Override
    public void postInitialize(Connection connection) {
      try (Statement st = connection.createStatement()) {
        st.execute("set statement_timeout to '30s'");
      } catch (SQLException e) {
        throw new IllegalStateException(e);
      }
    }
  })
  .build();

Deprecated setXxx methods

Many settings historically used a setXxx name (e.g. setMinConnections). These remain for backwards compatibility but are deprecated — prefer the fluent forms shown above (minConnections, maxConnections, heartbeatFreqSecs, etc.).


Next Steps