Skip to content

Commit

Permalink
add env var for changing the database pool size (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
ichub authored Nov 12, 2024
1 parent 0ac1684 commit 1304398
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apps/passport-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,6 @@ IS_LOCAL_HTTPS=false
# `next` field in its response, we instead know that we've loaded all orders when
# there are 404 errors for pages that are not the first page, and no other errors.
# PRETIX_BATCH_ENABLED_FOR=[""]

# The number of database connections to keep open.
# DB_POOL_SIZE=32
11 changes: 10 additions & 1 deletion apps/passport-server/src/database/postgresConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export function getDatabaseConfiguration(): PoolOptionsExplicit & SslSettings {
throw new Error("Missing or incorrect env variable: DATABASE_SSL");
}

let poolSize = 32;
if (process.env.DB_POOL_SIZE !== undefined) {
poolSize = parseInt(process.env.DB_POOL_SIZE, 10);
if (isNaN(poolSize)) {
poolSize = 32;
}
poolSize = Math.min(Math.max(poolSize, 32), 70);
}

// defaults here: https://github.com/postgres-pool/postgres-pool/blob/9d623823dc365b5edea3303cab6ae519bfaa94f7/src/index.ts#L264C10-L290
// docs here: https://github.com/postgres-pool/postgres-pool/blob/9d623823dc365b5edea3303cab6ae519bfaa94f7/src/index.ts#L29-L130
return {
Expand All @@ -43,7 +52,7 @@ export function getDatabaseConfiguration(): PoolOptionsExplicit & SslSettings {
// Pool configuration
connectionTimeoutMillis: 16_000,
idleTimeoutMillis: 8_000,
poolSize: 32, // max connection # on render is 97
poolSize: poolSize, // max connection # on render is 97
waitForAvailableConnectionTimeoutMillis: 30_000,
databaseStartupTimeoutMillis: 30_000,
readOnlyTransactionReconnectTimeoutMillis: 30_000,
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
"SELF_HOSTED_PODBOX_MODE",
"GENERIC_ISSUANCE_TEST_MODE",
"PRETIX_BATCH_ENABLED_FOR",
"DB_POOL_SIZE",
"//// add env vars above this line ////"
]
}

0 comments on commit 1304398

Please sign in to comment.