From f093c697235f46bf0a34c896e4a21b971caf606c Mon Sep 17 00:00:00 2001 From: Burak Emir Sezen Date: Thu, 7 May 2026 22:11:36 +0200 Subject: [PATCH] feat(db): add DB_POOL_SIZE environment variable for postgres connection pool (#2990) --- compose.postgres.yaml | 1 + docs/extending-seerr/database-config.mdx | 2 ++ server/datasource.ts | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/compose.postgres.yaml b/compose.postgres.yaml index 288b4cf54..3cf845f5d 100644 --- a/compose.postgres.yaml +++ b/compose.postgres.yaml @@ -14,6 +14,7 @@ services: DB_NAME: 'seerr' # The name of the database to connect to DB_LOG_QUERIES: 'false' # Whether to log the DB queries for debugging DB_USE_SSL: 'false' # Whether to enable ssl for database connection + DB_POOL_SIZE: '10' # The number of connections to maintain in the connection pool volumes: - .:/app:rw,cached - /app/node_modules diff --git a/docs/extending-seerr/database-config.mdx b/docs/extending-seerr/database-config.mdx index 59684161c..edf101afd 100644 --- a/docs/extending-seerr/database-config.mdx +++ b/docs/extending-seerr/database-config.mdx @@ -35,6 +35,7 @@ DB_PORT="5432" # (optional) The port to connect to. The default is "5432". DB_USER= # (required) Username used to connect to the database. DB_PASS= # (required) Password of the user used to connect to the database. DB_NAME="seerr" # (optional) The name of the database to connect to. The default is "seerr". +DB_POOL_SIZE="10" # (optional) The number of connections to maintain in the connection pool. The default is "10". DB_LOG_QUERIES="false" # (optional) Whether to log the DB queries for debugging. The default is "false". ``` @@ -48,6 +49,7 @@ DB_SOCKET_PATH="/var/run/postgresql" # (required) The path to the PostgreSQL Uni DB_USER= # (required) Username used to connect to the database. DB_PASS= # (optional) Password of the user used to connect to the database, depending on the server's authentication configuration. DB_NAME="seerr" # (optional) The name of the database to connect to. The default is "seerr". +DB_POOL_SIZE="10" # (optional) The number of connections to maintain in the connection pool. The default is "10". DB_LOG_QUERIES="false" # (optional) Whether to log the DB queries for debugging. The default is "false". ``` diff --git a/server/datasource.ts b/server/datasource.ts index 0e3126f84..699c0bfeb 100644 --- a/server/datasource.ts +++ b/server/datasource.ts @@ -12,6 +12,15 @@ function boolFromEnv(envVar: string, defaultVal = false) { return defaultVal; } +function intFromEnv(envVar: string, defaultVal?: number): number | undefined { + const val = process.env[envVar]; + if (val) { + const parsed = parseInt(val, 10); + return isNaN(parsed) ? defaultVal : parsed; + } + return defaultVal; +} + function stringOrReadFileFromEnv(envVar: string): Buffer | string | undefined { if (process.env[envVar]) { return process.env[envVar]; @@ -87,6 +96,7 @@ const postgresDevConfig: DataSourceOptions = { password: process.env.DB_PASS, database: process.env.DB_NAME ?? 'seerr', ssl: buildSslConfig(), + poolSize: intFromEnv('DB_POOL_SIZE'), synchronize: false, migrationsRun: true, logging: boolFromEnv('DB_LOG_QUERIES'), @@ -105,6 +115,7 @@ const postgresProdConfig: DataSourceOptions = { password: process.env.DB_PASS, database: process.env.DB_NAME ?? 'seerr', ssl: buildSslConfig(), + poolSize: intFromEnv('DB_POOL_SIZE'), synchronize: false, migrationsRun: false, logging: boolFromEnv('DB_LOG_QUERIES'),