Runtime Database Connection Configuration
Configure the runtime service's connection to its PostgreSQL database, including authentication modes (IAM, user/password), timeouts, and SSL settings.
Overview
This document describes the configuration properties for the runtime service's internal database connection. These properties, prefixed with s2r.db, control how the service connects to its PostgreSQL database, which it uses for its operational data, such as mapping SOAP requests to REST backends.
The configuration supports two primary authentication and connection methods:
- IAM Authentication: The default method, designed for use with managed cloud database services. It uses instance connection strings and automatically refreshed IAM tokens.
- Username/Password Authentication: A standard method using a hostname, port, username, and password for direct database connections.
Proper configuration is critical for service startup and resilience, especially the socket timeout settings, which prevent connection pool exhaustion during network partitions.
How it Works
The runtime service reads properties under the s2r.db prefix at startup to configure its database connection pool. The s2r.db.authMode property determines the connection strategy.
The diagram below illustrates the two main connection paths based on the configured authentication mode.
flowchart TD
subgraph "Runtime Service Startup"
direction TB
A(Read s2r.db.* properties) --> B{authMode == "iam"?};
end
subgraph "IAM Authentication Path"
direction TB
C(Connect via Cloud SQL Connector)
D(Use `instanceConnectionName` and `ipType`)
E(Refresh token every `iamTokenRefreshSeconds`)
end
subgraph "Username/Password Path"
direction TB
F(Connect via standard JDBC)
G(Use `host`, `port`, `user`, and `password`)
end
B -- Yes --> C --> D --> E;
B -- No --> F --> G;-
If
authModeis set toiam(the default), the service uses a dedicated Cloud SQL Java connector. It relies on theinstanceConnectionNameto identify the target database instance and authenticates using IAM. An authentication token is automatically managed and refreshed at the interval specified byiamTokenRefreshSeconds. -
If
authModeis set to any other value, the service attempts a direct connection using the standardhost,port,user, andpasswordproperties.
In both modes, socket-level timeouts (socketTimeoutSeconds and connectTimeoutSeconds) are applied to ensure that connections do not hang indefinitely during network instability, which is crucial for maintaining the health of the connection pool.
Configuration Reference
All properties are prefixed with s2r.db. For example, to set the host, the full property key is s2r.db.host.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
authMode | String | iam | No | Specifies the authentication mode. |
host | String | — | Yes (if authMode is not iam) | The hostname of the database server. |
port | Integer | 5432 | No | The port number of the database server. |
name | String | soap_to_rest | No | The name of the database to connect to. |
user | String | — | Yes (if authMode is not iam) | The username for database authentication. |
password | String | — | Yes (if authMode is not iam) | The password for the specified user. |
iamTokenRefreshSeconds | Integer | 2700 | No | The interval in seconds for refreshing the IAM authentication token. Relevant only when authMode is iam. (2700 seconds = 45 minutes) |
sslMode | String | require | No | The SSL mode for the database connection. |
instanceConnectionName | String | — | Yes (if authMode is iam) | The unique identifier for a managed database instance, in the format <project>:<region>:<instance>. Used by the Cloud SQL connector. |
ipType | String | PRIVATE | No | The IP type to use for the Cloud SQL connector. Valid values are PRIVATE, PUBLIC, and PSC. |
socketTimeoutSeconds | Integer | 30 | No | Socket-level read timeout in seconds. Must be longer than the slowest expected database query. |
connectTimeoutSeconds | Integer | — | No | The timeout in seconds for establishing a new database connection. The source does not specify a default value. |
Troubleshooting
Connection Pool Exhaustion During Network Partitions
Condition: The runtime service becomes unresponsive, and logs indicate an inability to acquire a database connection from the pool, even after network connectivity to the database has been restored.
Cause: If a network partition occurs between the runtime service and the database, active connections in the pool can get stuck waiting for a response on a dead socket. Without a socket timeout, these connections will never be terminated and returned to the pool. The connection pool will eventually be exhausted as all connections become permanently "borrowed" and unusable.
Solution: Configure the s2r.db.socketTimeoutSeconds property. This sets a timeout on socket-level read operations. If the database does not respond within this period, the driver will throw an exception, which terminates the dead connection and allows the connection pool to reclaim it. This ensures the pool can recover automatically once network connectivity is restored.
IMPORTANT
The socketTimeoutSeconds value must be set higher than the execution time of the slowest legitimate database query run by the service. The source suggests 30 seconds is an ample default for this service, as its runtime database operations are latency-bound.
