feat: make database connection pool size configurable (#21403)

Closes https://github.com/coder/coder/issues/21360

A few considerations/notes:
- I've kept the number of conns to 10 in all other places, except coderd
- which uses the config value
- I opted to also make idle conns configurable; the greater the delta
between max open and max idle, the more connection churn
- Postgres maintains a [_process_ per
connection](https://www.postgresql.org/docs/current/connect-estab.html),
contrary to what the comment said previously
- Operators should be able to tune this, since process churn can
negatively affect OS scheduling
- I've set the value to `"auto"` by default so it's not another knob one
_has to_ twiddle, and sets max idle = max conns / 3

---------

Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
Danny Kopping
2026-01-13 10:50:57 +02:00
committed by GitHub
parent 61ae5b81ab
commit 49a42eff5c
13 changed files with 334 additions and 17 deletions
+9
View File
@@ -1736,6 +1736,8 @@ export interface DeploymentValues {
readonly ephemeral_deployment?: boolean;
readonly pg_connection_url?: string;
readonly pg_auth?: string;
readonly pg_conn_max_open?: number;
readonly pg_conn_max_idle?: string;
readonly oauth2?: OAuth2Config;
readonly oidc?: OIDCConfig;
readonly telemetry?: TelemetryConfig;
@@ -3450,6 +3452,13 @@ export type PostgresAuth = "awsiamrds" | "password";
export const PostgresAuths: PostgresAuth[] = ["awsiamrds", "password"];
// From codersdk/deployment.go
/**
* PostgresConnMaxIdleAuto is the value for auto-computing max idle connections
* based on max open connections.
*/
export const PostgresConnMaxIdleAuto = "auto";
// From codersdk/deployment.go
export interface PprofConfig {
readonly enable: boolean;