-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Currently, I am seeing a new row added to pg_stat_activity
on every request. Once it reaches around 30 rows, I can no longer perform anymore queries. I could lower the idle timeout to like 1 second but it would still hit 30 rows if requests were made faster than the timeout. Here is my setup
// db.js
import { Pool } from 'pg';
const confings = { ... };
export const db = new Pool(configs);
// profile.js
import { db } from './configs/db';
import express from 'express';
const app = express();
app.post('/profile', async(req, resp, next) => {
const client = await db.connect();
try {
await client.query('BEGIN');
await client.query('COMMIT');
} catch (e) {
console.log(e);
} finally {
client.release();
}
});
If 30+ simultaneous requests hits this route, I would get a connection timeout error and my app would crash.
Is this the right way to do it? How can I handle more than 30+ requests at the same or short time?