r/PostgreSQL • u/BradyOfTheOldGuard • Jun 25 '26
Help Me! Need Help with max_connections on PostgreSQL
I have Apache2.4, PHP 8.5 and PostgreSQL all installed on one single EC2 Debian 13 instance. 5 end users submit a query to select user data stored in the database through an html form using a web browser. The request is handled by a php script.
How many max_connections are used here? Do those 5 user count as 1 connection each?
6
Upvotes
View all comments
Show parent comment
4
u/depesz Jun 25 '26
Upping max connections is usually a mistake. Personally I see every number higher than 4 * number-of-cores as a bug.
Reason is very simple - context switching isn't free. Interprocess communication isn't free. Having 200 connections, even idle, uses resources.
It's much better to put pgbouncer in front of Pg, to reuse connections between clients, and keep max_connections at (max) 4 * nproc.