Postgresql – How large should the pool size be? And should I use pgbouncer

concurrencypgpoolpostgresql

I have a Rails application with 4 Unicorn workers. How do I determine what postgresql database pool size I should use?

And if I have 6 applications connecting to this postgres database, would that be too many connections? And should I use pgbouncer instead? If so, why?

Best Answer

There really isn't enough to go on here. 10 concurrent connections isn't a lot for most setups.

The best advice I can give is start simple and when you start to run into cases where performance is starting to become an issue then look at more complex solutions unless you know it will be an issue (say 1000 concurrent users and millions of queries from the web every day). Otherwise you build in complexity you may never need. However, by all means monitor and keep an eye out for scaling out solutions that work for you (I recommend keeping an eye on Slony and Postgres-XC in this regard in addition to other solutions). They are at the upper end of complexity but if you need something that can do anything you need it to, they are the solutions.

As it is though, generally for the number of concurrent connections you are talking about, there is no need to consider something complicated until you start to need it. Then you will have a better idea of what you need in a solution.

Premature optimization is the root of all evil.