Skip to content

Commit f093c69

Browse files
feat(db): add DB_POOL_SIZE environment variable for postgres connection pool (#2990)
1 parent 9b7b50b commit f093c69

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

compose.postgres.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
DB_NAME: 'seerr' # The name of the database to connect to
1515
DB_LOG_QUERIES: 'false' # Whether to log the DB queries for debugging
1616
DB_USE_SSL: 'false' # Whether to enable ssl for database connection
17+
DB_POOL_SIZE: '10' # The number of connections to maintain in the connection pool
1718
volumes:
1819
- .:/app:rw,cached
1920
- /app/node_modules

docs/extending-seerr/database-config.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ DB_PORT="5432" # (optional) The port to connect to. The default is "5432".
3535
DB_USER= # (required) Username used to connect to the database.
3636
DB_PASS= # (required) Password of the user used to connect to the database.
3737
DB_NAME="seerr" # (optional) The name of the database to connect to. The default is "seerr".
38+
DB_POOL_SIZE="10" # (optional) The number of connections to maintain in the connection pool. The default is "10".
3839
DB_LOG_QUERIES="false" # (optional) Whether to log the DB queries for debugging. The default is "false".
3940
```
4041

@@ -48,6 +49,7 @@ DB_SOCKET_PATH="/var/run/postgresql" # (required) The path to the PostgreSQL Uni
4849
DB_USER= # (required) Username used to connect to the database.
4950
DB_PASS= # (optional) Password of the user used to connect to the database, depending on the server's authentication configuration.
5051
DB_NAME="seerr" # (optional) The name of the database to connect to. The default is "seerr".
52+
DB_POOL_SIZE="10" # (optional) The number of connections to maintain in the connection pool. The default is "10".
5153
DB_LOG_QUERIES="false" # (optional) Whether to log the DB queries for debugging. The default is "false".
5254
```
5355

server/datasource.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ function boolFromEnv(envVar: string, defaultVal = false) {
1212
return defaultVal;
1313
}
1414

15+
function intFromEnv(envVar: string, defaultVal?: number): number | undefined {
16+
const val = process.env[envVar];
17+
if (val) {
18+
const parsed = parseInt(val, 10);
19+
return isNaN(parsed) ? defaultVal : parsed;
20+
}
21+
return defaultVal;
22+
}
23+
1524
function stringOrReadFileFromEnv(envVar: string): Buffer | string | undefined {
1625
if (process.env[envVar]) {
1726
return process.env[envVar];
@@ -87,6 +96,7 @@ const postgresDevConfig: DataSourceOptions = {
8796
password: process.env.DB_PASS,
8897
database: process.env.DB_NAME ?? 'seerr',
8998
ssl: buildSslConfig(),
99+
poolSize: intFromEnv('DB_POOL_SIZE'),
90100
synchronize: false,
91101
migrationsRun: true,
92102
logging: boolFromEnv('DB_LOG_QUERIES'),
@@ -105,6 +115,7 @@ const postgresProdConfig: DataSourceOptions = {
105115
password: process.env.DB_PASS,
106116
database: process.env.DB_NAME ?? 'seerr',
107117
ssl: buildSslConfig(),
118+
poolSize: intFromEnv('DB_POOL_SIZE'),
108119
synchronize: false,
109120
migrationsRun: false,
110121
logging: boolFromEnv('DB_LOG_QUERIES'),

0 commit comments

Comments
 (0)