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

Pool min size

Open krabradosty opened this issue 6 years ago • 5 comments

Hi. It seems that min parameter of Pool configuration is not used.

Code

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

Expected: At least one connection is always established

Actual: I receive a removed event with pool.totalCount equals to zero. After that my process is terminated.

krabradosty avatar Apr 04 '19 18:04 krabradosty

min doesn’t exist. I don’t think nolimit does either.

charmander avatar Apr 05 '19 16:04 charmander

Strange, I think it can be useful: e.g. I want to know that there is a problem with a connection to DB before my app come in a state when it needs to perform a query. Right now when I detect that pool.totalCount is zero, I send SELECT now() to DB to maintain the connection.

krabradosty avatar Apr 06 '19 09:04 krabradosty

I also have a requirement to maintain a given, minimum number of connections to the database. Is there a known workaround to achieve this? I noticed that PgBouncer supports this but i prefer to use node-postgres if a viable workaround is available.

champikasam avatar Mar 02 '22 12:03 champikasam

@brianc This would be a nice feature. Any reason it isn't supported given that we can just leverage generic-pool functionality for this?

Would be nice to have this for compatibility with postgres.

https://github.com/gajus/postgres-bridge/commit/2463f7fcb4fad147eadbfbbdf6683b838c53c9e2

gajus avatar Aug 03 '22 19:08 gajus

Upon a second look, it looks like Pool is not using generic-pool, contrary to what I thought.

gajus avatar Aug 03 '22 19:08 gajus

Hi @brianc Is there any future roadmap to support this feature??

Smriti-OSS avatar Jun 05 '23 15:06 Smriti-OSS