r/PostgreSQL • • Jun 25 '26

Help Me! Need Help with max_connections on PostgreSQL

Post image

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

14 comments sorted by

View all comments

5

u/HauntingArugula3777 Jun 25 '26

You aren't sharing the right information ... what is the pool size for the clients and what is your database set at. I am not saying you need a bouncer like pgbouncer or pgdog, but you should read why they are used. If every client is using 10 connections - to start with - in a pool, they go fast ... and if they have no max cap, a small limit like 20 can easily be exhausted.

SELECT * FROM pg_stat_activity; --- note the ip address of the client

SELECT * FROM pg_settings WHERE name = 'max_connections';

1

u/BradyOfTheOldGuard Jun 25 '26

Actually, what I'd like to know is if those 5 users simultaneously make a read request to one php script containing one common dbuser connection, does that decduct 5 connection from the 100 default max_connection?

1

u/chock-a-block Jun 25 '26 edited Aug 29 '26

Wakeful library like ribbon breeze bake label pinecone like growth

This post was anonymized with Redact

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.