File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ PG_PASSWORD=postgres
5
5
PG_DATABASE = stacks_blockchain_api
6
6
PG_SCHEMA = public
7
7
PG_SSL = false
8
+ # Idle connection timeout in seconds, defaults to 30
9
+ # PG_IDLE_TIMEOUT=30
10
+ # Max connection lifetime in seconds, defaults to 60
11
+ # PG_MAX_LIFETIME=60
8
12
9
13
# Can be any string, use to specify a use case specific to a deployment
10
14
PG_APPLICATION_NAME = stacks-blockchain-api
@@ -27,12 +31,13 @@ PG_APPLICATION_NAME=stacks-blockchain-api
27
31
# PG_PRIMARY_DATABASE=
28
32
# PG_PRIMARY_SCHEMA=
29
33
# PG_PRIMARY_SSL=
34
+ # PG_PRIMARY_IDLE_TIMEOUT=
35
+ # PG_PRIMARY_MAX_LIFETIME=
30
36
# The connection URI below can be used in place of the PG variables above,
31
37
# but if enabled it must be defined without others or omitted.
32
38
# PG_PRIMARY_CONNECTION_URI=
33
39
34
40
# Limit to how many concurrent connections can be created, defaults to 10
35
- # See https://node-postgres.com/api/pool
36
41
# PG_CONNECTION_POOL_MAX=10
37
42
38
43
# If specified, controls the Stacks Blockchain API mode. The possible values are:
Original file line number Diff line number Diff line change @@ -138,6 +138,8 @@ export function getPostgres({
138
138
ssl : pgEnvValue ( 'SSL' ) ,
139
139
schema : pgEnvValue ( 'SCHEMA' ) ,
140
140
applicationName : pgEnvValue ( 'APPLICATION_NAME' ) ,
141
+ idleTimeout : parseInt ( pgEnvValue ( 'IDLE_TIMEOUT' ) ?? '30' ) ,
142
+ maxLifetime : parseInt ( pgEnvValue ( 'MAX_LIFETIME' ) ?? '60' ) ,
141
143
poolMax : parseInt ( process . env [ 'PG_CONNECTION_POOL_MAX' ] ?? '10' ) ,
142
144
} ;
143
145
const defaultAppName = 'stacks-blockchain-api' ;
@@ -180,6 +182,8 @@ export function getPostgres({
180
182
host : pgEnvVars . host ,
181
183
port : parsePort ( pgEnvVars . port ) ,
182
184
ssl : parseArgBoolean ( pgEnvVars . ssl ) ,
185
+ idle_timeout : pgEnvVars . idleTimeout ,
186
+ max_lifetime : pgEnvVars . maxLifetime ,
183
187
max : pgEnvVars . poolMax ,
184
188
types : PG_TYPE_MAPPINGS ,
185
189
connection : {
Original file line number Diff line number Diff line change @@ -196,6 +196,8 @@ describe('postgres datastore', () => {
196
196
PG_SSL : 'true' ,
197
197
PG_SCHEMA : 'pg_schema_schema1' ,
198
198
PG_APPLICATION_NAME : 'test-env-vars' ,
199
+ PG_MAX_LIFETIME : '5' ,
200
+ PG_IDLE_TIMEOUT : '1' ,
199
201
} ,
200
202
( ) => {
201
203
const sql = getPostgres ( { usageName : 'tests' } ) ;
@@ -205,6 +207,8 @@ describe('postgres datastore', () => {
205
207
expect ( sql . options . host ) . toStrictEqual ( [ 'pg_host_host1' ] ) ;
206
208
expect ( sql . options . port ) . toStrictEqual ( [ 9876 ] ) ;
207
209
expect ( sql . options . ssl ) . toBe ( true ) ;
210
+ expect ( sql . options . max_lifetime ) . toBe ( 5 ) ;
211
+ expect ( sql . options . idle_timeout ) . toBe ( 1 ) ;
208
212
expect ( sql . options . connection . search_path ) . toBe ( 'pg_schema_schema1' ) ;
209
213
expect ( sql . options . connection . application_name ) . toBe ( 'test-env-vars:tests' ) ;
210
214
}
You can’t perform that action at this time.
0 commit comments