What this thread does
Do first: run SHOW max_connections, SHOW reserved_connections and SHOW superuser_reserved_connections, then count peak server connections across every pool instance.
Short answer
As of November 2026, use PostgreSQL 18 semantics and PgBouncer 1.26.1 as the pooler baseline. Fit total backend demand below the ordinary-slot budget; bound client queues separately. Increasing the server cap consumes resources and requires a restart (connection settings).
Choose / don't choose
- Application/session pooling: choose when callers require connection-local state; don't return a dirty connection to another request.
- Transaction pooling: choose when requests can scope all state to one transaction; don't rely on session settings surviving checkout changes. PgBouncer's normal session-reset query does not run in transaction mode (config).
- Extra pooler replicas: choose for observed pooler CPU/throughput limits; don't assume more replicas create more server capacity. Elizabeth Christensen's November 14, 2022 report describes the added pool-management burden.
Not for: ORM checkout errors; see sqlalchemy-queuepool-timeout-session-lifetime-capacity.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
max_connections | Typically default 100; choose from measured server capacity and total pool demand, not request count | Server start | connections |
reserved_connections | Default 0; reserved slots are accessible only to authorized reserved-slot roles | Server start | connections |
superuser_reserved_connections | Default 3; preserve emergency capacity | Server start | connections |
idle_in_transaction_session_timeout | Default 0 disables; terminates sessions idle inside an open transaction | Pooled app sessions | timeouts |
max_db_connections | Set finite backend cap per PgBouncer database; default 0 means unlimited | PgBouncer database | config |
server_reset_query | Default DISCARD ALL; session-pool release with no active transaction | PgBouncer session mode | config |
Example capacity arithmetic, not a sizing recommendation: cap 100 minus 3 superuser slots minus 5 operational slots leaves 92 ordinary slots. Four poolers capped at 20 backends each consume at most 80, leaving 12 for direct clients and other traffic. Count database aliases, users, burst reserves, rolling-deployment overlap and autoscaling peaks. A backend cap on each replica is not a global cap.
Order of operations
1. Enumerate applications, workers, migrations, monitoring, direct clients and all pooler replicas. Record maximum backend demand and a headroom allowance; measure database throughput before raising concurrency. 2. Cap acquisition queues and wait deadlines in the driver/pooler below the request deadline. The concrete driver option is application-specific. A large number of queued clients does not justify opening one backend each. 3. On 53300, reject or queue only within a finite admission budget. Retry connection establishment with capped exponential backoff, jitter and a deadline; cap simultaneous reconnect attempts. Do not create a fresh pool per request or replay uncertain writes blindly. The linked SQLSTATE reference identifies the error code; the bounded retry and jitter policy above is application-specific. 4. For application-managed session reuse, first COMMIT/ROLLBACK and await completion; then issue DISCARD ALL outside a transaction. Only return the connection after reset succeeds. Discard the connection on reset failure. Reset releases temporary resources and resets the session to its initial state, so rebuild deliberate per-checkout state afterward (DISCARD). 5. Know which pool layer owns reset. PgBouncer session reset occurs when its client session releases the server connection; an application request returning to a still-open driver connection may need its own reset contract (config). 6. Exercise peak replicas plus a rolling deployment; inspect queue latency, backend count and operational login access. Exercise the idle-transaction timeout and ensure closed connections are removed from pools.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
25P03 idle_in_transaction_session_timeout | App leaves a transaction idle beyond configured limit | Remove terminated connection, correct transaction ownership and ensure rollback/close on failure | SQLSTATE, timeouts |
Missing
- The linked source does not confirm: the five-slot operational reserve and idle_in_transaction_session_timeout='30s' application policy.
- Hardware, peak replica count, driver and legitimate transaction duration are unknown; the numeric examples cannot determine production sizing.
- Timeout termination frees abandoned resources but does not replace application cleanup.
Started from a post by @Elizabeth Christensen, packaged by the editor. Original post