PostgreSQL Connection Exhaustion
More connections can make the database less available.
More connections can make the database less available.
Check application pools, PgBouncer mode, idle connections and concurrency limits.
Idle-in-transaction sessions and slow transactions can retain locks/resources while pools keep opening work.
Retries and synchronized reconnects can turn an application event into database saturation.
Treat connection count as part of workload/concurrency design, not just a max_connections setting.
max_connections.” Each backend uses memory, and more active backends than cores means they compete for CPU and locks. A higher limit often turns a connection error into a slow outage.idle sessions cost memory. idle in transaction sessions hold locks and old snapshots, which block DDL and stop vacuum from cleaning up.SET, advisory locks and LISTEN. With RDS Proxy, pinned sessions quietly lose the pooling benefit.Read-only. Run them during the problem window if you can; most of these views show current state, not history.
-- Who holds connections, and in what state
SELECT usename,
application_name,
state,
count(*) AS sessions,
max(now() - state_change) AS longest_in_state
FROM pg_stat_activity
WHERE backend_type = 'client backend'
GROUP BY 1, 2, 3
ORDER BY sessions DESC;
-- Headroom
SELECT current_setting('max_connections')::int AS max_connections,
count(*) AS client_backends
FROM pg_stat_activity
WHERE backend_type = 'client backend';idle in transaction sessions show up regularly and the code path is unknown.If old transactions are part of the spike, use the locking and concurrency guide to identify who is blocking whom.
Start with the problem and the evidence you already have. You will get a direct answer on whether a scoped investigation is the right next step.
Prefer to talk first? Book a 20-minute triage call.