Available clients in pool
Is there a way to determine how many clients are currently "available" in the pool? I.e. not being used by the app.
new pg.Pool().pool is an instance of generic pool and has the same public interface as described in the readme. You should be able to get available number of clients with pool.pool.availableObjectsCount()
Oh boi, I know this is very very old 😅
I've a legacy project I'm trying to upgrade and I've hacky code like this:
const pool = pg.pools.all['{}']; // default pool
if (pool) {
pgsql.allConnections = pool.getPoolSize();
pgsql.connectionsQueued = pool.waitingClientsCount();
pgsql.freeConnections = pool.availableObjectsCount();
}
Now, I read the last comment but it seems that the current pg-pool is not based on node-pool anymore, at least I can't see anything in https://github.com/brianc/node-postgres/blob/f49db313c1a75a7679c467b9f1740ea70047a509/packages/pg-pool/package.json
When I look at the source, would deep-diving be appropriate in this case?
pgsql.allConnections = pool._clients.length;
pgsql.connectionsQueued = pool._pendingQueue.length;
pgsql.freeConnections = pool._idle.length;
The basic idea is to provide some stats for recording metrics how the pool behaves.
Thanks!
yup that looks correct! I should make some first class getters to return that info, really...but that'll work for now! Good luck with your upgrade & lmk if you have any other questions.