PostgreSQL · Connection planning
PostgreSQL connection limits: a visual budget check
See how rollout overlap can exceed a connection budget, then check pools, reserved slots and resource headroom.
A deployment can exhaust PostgreSQL connections even when each application pool looks small. Count what the whole deployment can request before raising the server limit. The diagram shows why temporary overlap matters.
The short version
What to take away
- Budget ordinary slots after reserved access, then set operating headroom separately.
- Multiply direct pools by peak instance and process counts, including rollout overlap.
- A connection budget that fits still needs workload and resource validation.
Read the example in one minute
This hypothetical PostgreSQL 18 setup has 100 total slots, with 5 reserved for superusers and 3 for roles allowed to use reserved connections. That leaves 92 ordinary slots.
Assume one direct pool per application instance, no overflow, and a budget of 10 connections for other ordinary clients. Six instances capped at 12 connections each can request 6 × 12 + 10 = 82 connections. Ten ordinary slots remain unused.
During a rolling deployment, eight instances overlap. The same pool setting permits 8 × 12 + 10 = 106 connections, exceeding the ordinary budget by 14.
To retain 10 slots of additional operating headroom during that overlap, the illustrative application budget is 92 − 10 other clients − 10 headroom = 72. Across eight instances, a candidate cap of 9 gives 8 × 9 + 10 = 82.
That is arithmetic, not a sizing recommendation. It does not prove the smaller pool can meet latency targets or that the server can sustain 82 busy sessions. Headroom is separate from PostgreSQL’s reserved-access settings.
Check these before changing anything
- Capture the exact error. A server rejection differs from an application waiting too long to borrow a pooled connection. Role and database limits can also restrict access.
- Inventory every independent pool, process, worker and rollout instance. Include overflow and autoscaling. With an external pooler, count its server-side connections separately.
- Review session states and resource trends. Idle is not automatically a leak; an old idle-in-transaction session deserves investigation. More admitted work can increase contention and memory demand.
Raising max_connections requires a restart and increases some resource allocations. Test any proposed change in an appropriate environment, with validation criteria and a separately approved rollout.
Sources and next step
Official PostgreSQL documentation: connection settings, session activity and resource consumption. The reserved_connections mechanism requires PostgreSQL 16 or later; check your installed version.