Loading…
Loading…
Configure the Admin API's primary database connection, including authentication (IAM or password), pooling, timeouts, and SSL settings.
This document describes the configuration properties for the Admin API's primary database connection. These properties are prefixed with s2r.db and allow an operator to control how the Admin API connects to its PostgreSQL database, which is used for functions such as serving dashboard aggregations.
Configuration covers several key areas:
These settings are loaded by the Admin API at startup and are critical for establishing and maintaining a stable connection to the application's database.
The Admin API uses a connection pool to efficiently manage database connections. The properties defined here configure that pool and the underlying JDBC driver.
The s2r.db.authMode property determines the authentication strategy.
flowchart TD
A[Admin API Starts] --> B{Read `s2r.db.authMode`};
B -- "iam" (default) --> C[IAM Authentication];
C --> C1["Uses Cloud SQL Connector with<br/>`instanceConnectionName`"];
B -- other --> D[Password Authentication];
D --> D1["Uses standard JDBC driver with<br/>`host`, `user`, `password`"];
C1 --> E[Connection Pool Initialized];
D1 --> E;iam): This is the default mode. It uses the Cloud SQL Java connector for authentication. This method requires the s2r.db.instanceConnectionName property to be set. An IAM token is automatically managed and refreshed based on the s2r.db.iamTokenRefreshSeconds setting.authMode is set to a value other than iam, the system uses standard username and password authentication. This requires the s2r.db.host, s2r.db.user, and s2r.db.password properties.The Admin API maintains a connection pool for application queries, such as those that populate dashboards. The size and timeout behavior of this pool are configured by properties like maxPoolSize, connectionTimeoutMs, and socketTimeoutSeconds.
The socketTimeoutSeconds and connectTimeoutSeconds are particularly important for operational resilience, as they prevent the application from hanging indefinitely if the database becomes unresponsive at the network level. The default socket timeout for the Admin API is higher than for other services to accommodate slower dashboard aggregation queries.
IMPORTANT
The timeout settings described here apply only to the main application connection pool. Schema migrations are executed using a separate, deliberately un-timed connection pool. This ensures that long-running Data Definition Language (DDL) statements, such as CREATE INDEX CONCURRENTLY, are not terminated prematurely by a socket timeout.
The following example shows a typical configuration for connecting to a database using IAM authentication. These properties would be set in the Admin API's configuration file.
s2r:
db:
authMode: "iam"
instanceConnectionName: "<project>:<region>:<instance>"
ipType: "PRIVATE"
name: "soap_to_rest"
maxPoolSize: 24
socketTimeoutSeconds: 60
All properties are prefixed with s2r.db.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
authMode | String | iam | No | The authentication mode. Set to iam for IAM-based authentication or another value for username/password authentication. |
host | String | — | Conditionally | The database host name or IP address. Required when authMode is not iam. |
port | int | 5432 | No | The database server port. |
name | String | soap_to_rest | No | The name of the database to connect to. |
user | String | — | Conditionally | The username for database authentication. Required when authMode is not iam. |
password | String | — | Conditionally | The password for database authentication. Required when authMode is not iam. |
iamTokenRefreshSeconds | int | 2700 | No | The interval, in seconds, at which IAM authentication tokens are refreshed. Applies only when authMode is iam. |
sslMode | String | require | No | The SSL mode for the database connection. |
instanceConnectionName | String | — | Conditionally | The Cloud SQL instance connection name in the format <project>:<region>:<instance>. Required when authMode is iam. |
ipType | String | PRIVATE | No | The IP type to use for the Cloud SQL Java connector. Valid values are PRIVATE, PUBLIC, or PSC. Applies only when authMode is iam. |
maxPoolSize | int | 24 | No | The maximum number of connections in the database pool. |
minIdle | int | 2 | No | The minimum number of idle connections that the pool attempts to maintain. |
connectionTimeoutMs | long | 8000 | No | The maximum time in milliseconds that the application will wait for a connection from the pool. |
validationTimeoutMs | long | 3000 | No | The maximum time in milliseconds that the pool will wait for a connection to be validated. |
socketTimeoutSeconds | int | 60 | No | The socket-level read timeout in seconds. This helps prevent the application from hanging on an unresponsive database connection. |
connectTimeoutSeconds | int | DbSocketResilience.DEFAULT_CONNECT_TIMEOUT_SECONDS | No | The socket-level connect timeout in seconds. Defaults to a system-defined constant for connection resilience. |
The Admin API will fail to start if the database configuration is invalid. Common causes include:
authMode is set to iam, but instanceConnectionName is not provided.authMode is not iam, but host, user, or password are missing.host or instanceConnectionName values.The socketTimeoutSeconds is set to 60 seconds by default to accommodate potentially slow dashboard aggregation queries. If queries are consistently timing out, it may indicate a performance issue with the database itself. Increasing this timeout should be done with caution, as it can increase the time the application waits for a non-responsive database.