Skip to content

Commit 4700580

Browse files
committed
Tweak connection pools
1 parent 068e7ab commit 4700580

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

api/db/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { metrics } from '../metrics/index.js';
44
// pools will use environment variables
55
// for connection information (from .env or a ConfigMap)
66
export const pool = new pg.Pool({
7-
max: 8,
7+
max: 4,
88
ssl: process.env.PGSSL ? process.env.PGSSL === 'true' : { rejectUnauthorized: false },
99
connectionTimeoutMillis: 500,
10-
// Statement timeout is at the Postgres side, times out any individual query
11-
// statement_timeout: 750, // TODO: doesn't work with pgbouncer?
1210
// Query timeout is on the NodeJS side, it times out the an operation on the client
13-
query_timeout: 1000,
11+
query_timeout: 2000,
1412
});
1513

1614
pool.on('connect', () => {
@@ -45,6 +43,7 @@ export async function transaction<T>(fn: (client: ClientBase) => Promise<T>) {
4543
const client = await pool.connect();
4644
try {
4745
await client.query('BEGIN');
46+
await client.query("SET LOCAL statement_timeout = '2s';");
4847

4948
const result = await fn(client);
5049

@@ -65,11 +64,11 @@ export async function transaction<T>(fn: (client: ClientBase) => Promise<T>) {
6564
export async function readTransaction<T>(fn: (client: ClientBase) => Promise<T>) {
6665
const client = await pool.connect();
6766
try {
68-
// We used to wrap multiple reads in a transaction but I'm not sure it matters all that much.
69-
// await client.query('BEGIN');
67+
await client.query('BEGIN');
68+
await client.query("SET LOCAL statement_timeout = '2s';");
7069
return await fn(client);
7170
} finally {
72-
// await client.query('ROLLBACK');
71+
await client.query('ROLLBACK');
7372
client.release();
7473
}
7574
}

0 commit comments

Comments
 (0)