node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Support Min connection pool parameter

Open Smriti-OSS opened this issue 2 years ago • 3 comments

Hey @brianc @charmander ,

Problem Statement: I have an application which is currently using the default configuration of node-postgres pool to connect to postgres. I have noticed that whenever we query the application - node-postgres connection pool always creates a new connection and so the total time taken for query execution is always between 3-5sec. If we re-use an idle connection for query execution - it just takes 2 millisecond to 300 millisecond.

Proposed Solution: I am thinking of keeping some idle connections in the pool - so that they could be used whenever the database is queried. Something like this -

let pool = new Pool({
        database: connectionConfig.database,
        port: connectionConfig.port,
        user: connectionConfig.user,
        password: connectionConfig.password,
        host: connectionConfig.host,
        min: 1,
        max: 10
    });

I am open to submitting a PR for the above feature but thought of first discussing it with the community whether this would be a feature worth exploring.

Smriti-OSS avatar Jun 13 '23 13:06 Smriti-OSS

I experienced the same problem. each initial set of connections takes more than 200 ms, so the api response time becomes > 1s

khoirulamri avatar Jan 12 '24 15:01 khoirulamri