From a948fd2f9e82c240c6aece1af75c6ca5ac4e545e Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Mon, 17 Apr 2023 11:22:00 +0800 Subject: [PATCH 1/2] chore: add new env vars for db --- .env-example | 2 ++ src/config/config.ts | 12 ++++++++++++ src/database/config.js | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/.env-example b/.env-example index 985336c7b..3c23c0dd6 100644 --- a/.env-example +++ b/.env-example @@ -36,6 +36,8 @@ export E2E_TEST_GH_TOKEN="" export DB_URI="postgres://isomer:password@localhost:15432/isomercms_dev" export DB_MIN_POOL="1" export DB_MAX_POOL="10" +export DB_ACQUIRE="60000" +export DB_TIMEOUT="30000" export DB_ENABLE_LOGGING="" export LOCAL_SITE_ACCESS_TOKEN="" diff --git a/src/config/config.ts b/src/config/config.ts index 522fc8f67..5ab4ddb80 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -327,6 +327,18 @@ const config = convict({ format: "required-positive-number", default: 10, }, + dbAcquire: { + doc: "", + env: "DB_ACQUIRE", + format: "required-positive-number", + default: 60000, + }, + dbTimeout: { + doc: "", + env: "DB_TIMEOUT", + format: "required-positive-number", + default: 10000, + }, dbEnableLogging: { doc: "Enable database logging", env: "DB_ENABLE_LOGGING", diff --git a/src/database/config.js b/src/database/config.js index 43ded8222..f4e50e34d 100644 --- a/src/database/config.js +++ b/src/database/config.js @@ -10,6 +10,8 @@ const { parse } = require("pg-connection-string") const { DB_URI } = process.env const DB_MIN_POOL = parseInt(process.env.DB_MIN_POOL, 10) const DB_MAX_POOL = parseInt(process.env.DB_MAX_POOL, 10) +const DB_ACQUIRE = parseInt(process.env.DB_ACQUIRE, 10) +const DB_TIMEOUT = parseInt(process.env.DB_TIMEOUT, 10) const parsed = parse(DB_URI) const port = parsed.port ? parseInt(parsed.port, 10) : 5432 @@ -27,6 +29,7 @@ module.exports = { dialectOptions: { useUTC: false, timezone: "+08:00", + idle_in_transaction_session_timeout: DB_TIMEOUT, }, timezone: "+08:00", define: { @@ -38,5 +41,6 @@ module.exports = { pool: { min: DB_MIN_POOL, max: DB_MAX_POOL, + acquire: DB_ACQUIRE, }, } From a1c63d74eeba49bcf491a66f148c002524c1beb5 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Mon, 17 Apr 2023 11:35:53 +0800 Subject: [PATCH 2/2] chore: add description for env vars --- src/config/config.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 5ab4ddb80..be5bd885f 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -328,13 +328,15 @@ const config = convict({ default: 10, }, dbAcquire: { - doc: "", + doc: + "The maximum time, in milliseconds, that pool will try to get connection before throwing error", env: "DB_ACQUIRE", format: "required-positive-number", default: 60000, }, dbTimeout: { - doc: "", + doc: + "The maximum time, in milliseconds, before an idle session within an open transaction will be terminated", env: "DB_TIMEOUT", format: "required-positive-number", default: 10000,