Hands-on Lab·PostgreSQL
PostgreSQL Connection Limits and PgBouncer
Fill every slot and read the error PostgreSQL actually gives - it is not the one everybody quotes. Then 60 clients through PgBouncer become 5 server backends.
Monitoring and Operations Guide 42 of 47 Intermediate
- OSUbuntu 26.04 LTS
- PostgreSQL18.6-0ubuntu0.26.04.1
- Host2 core / 4 GB, 400,000-row test table
- TimeAbout 20 min
reserved_connections is separate from superuser_reserved_connections and was added in PostgreSQL 16, for members of pg_use_reserved_connections. PgBouncer here is 1.25.1.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when connections run out. This matters because raising max_connections is the wrong answer - it needs a restart, it costs memory per slot, and a pooler is what actually fixes it.
- counting the budget across four settings, every one needing a restart
- lowering it, and watching a reload fail to apply the change
- filling every slot, and reading the error PostgreSQL actually gives
- limiting a role rather than the whole server
- installing PgBouncer, configuring transaction pooling, and serving sixty clients from five backends
Before you start
- A cluster you can restart -
max_connectionsneeds one. - The
appdbdatabase.
-
Count the budget
-
Lower it, and watch the reload not work
-
Fill every slot
-
Limit a role rather than the server
-
Install PgBouncer and point it at the cluster
-
Configure transaction pooling
-
Sixty clients, five backends
-
Put the cluster back