PG bouncer with node-postgres
Hi! We have a large number of databases present in a single instance of PG. Currently pooling is implemented in node-postgres, but max_connections is hitting soon. We are considering using pgbouncer. Has anyone implemented node-postgres with pgbouncer? Any pointers / best practices would help. Thanks!
I'd recommend against using pg-bouncer. We've run into issues on this project in the past where pg-bouncer doesn't implement all of the protocol properly. That being said those issues were a long time ago. Might be worth trying.
On Thu, Jul 23, 2015 at 9:04 AM, linpy [email protected] wrote:
I am out of the office until 2015/07/24.
I would on leave from 2015/1/22~1/25. Please drop me mail if anything. Thanks.
Note: This is an automated response to your message "[node-postgres] PG bouncer with node-postgres (#817)" sent on 23/07/2015 20:30:50.
This is the only notification you will receive while this person is away.
— Reply to this email directly or view it on GitHub https://github.com/brianc/node-postgres/issues/817#issuecomment-124118271 .
@ranode ,
In just about every case when someone tells about running out of connections, it boils down to not releasing the connections correctly in some cases. Try to use pg-promise, see if the connection issue is still there, and if it is gone, then you will know the problem was with your connection management.
@brianc , thanks for your reply. Would you recommend some other light weight connection pooler in place of pgbouncer?
@vitaly-t , thanks for your reply. Each tenant is a separate process, with its own pool (by node-postgres). Our problem perhaps is not connection leaking, but hitting the max connections because of the increasing number of tenants, thereby the number of connections in the pool. Would you have any specific recommendations to help this case?
Each tenant has a separate db, and each one has a separate pool (with 10 connections). So a mere 30 tenants is causing the number connections to go beyond 300!
If you are running 30+ databases at a time, then the solution to such problem should be architectural, not just through connection pool manipulation, although you can can increase it to anything you want, of course.
@vitaly-t : thanks for your prompt responses. Would you have any pointers for an appropriate architecture?
@ranode not without intimately knowing the system. This will have to be an internal research.
Hey @ranode - I'm not sure of anything other than pgbouncer actually. The last time I had an issue reported related to it though was I think 2 years ago so chances are its improved a lot since then. Definitely interested in your experience if you try it out & it works for you. Off the top of my head I recall they had not implemented parameterized queries (which use a different protocol message) a few years ago.
Thanks Brian for sharing. Will try pgbouncer and post my experiences.
On Mon, Jul 27, 2015 at 8:32 PM, Brian C [email protected] wrote:
Hey @ranode https://github.com/ranode - I'm not sure of anything other than pgbouncer actually. The last time I had an issue reported related to it though was I think 2 years ago so chances are its improved a lot since then. Definitely interested in your experience if you try it out & it works for you. Off the top of my head I recall they had not implemented parameterized queries (which use a different protocol message) a few years ago.
— Reply to this email directly or view it on GitHub https://github.com/brianc/node-postgres/issues/817#issuecomment-125238193 .
pgbouncer is a standard de facto these days and a lot of huge projects use it. A lot of. I can provide a huge list of names, with numbers.
But you should be aware that pgbouncer has one important issue. It won't work correctly with Postgres prepared stmts, if you run it in "statement" and "transaction" pooling modes (see for example this: http://blog.luisico.net/2013/06/01/pgbouncer-and-prepared-statements/) – so if you use prepareds, you should stick to "session" pooling mode, which could be less productive in terms of performance
I also use PGBouncer and never ran into any problems.
@brianc this can probably be closed.
Thanks for the update @joskuijpers - as you can tell I'm pretty bad about closing issues, so anything I can close like this I appreciate! 😉 ❤️