Report #24039
[bug\_fix] FATAL: remaining connection slots are reserved for non-replicated superuser connections \(SQLSTATE 53300\)
Set idle\_in\_transaction\_session\_timeout to a non-zero value \(e.g., 5min\) to automatically terminate backends holding transactions open without work, and audit application code to ensure transactions are committed or rolled back before external API calls or long computations. Root cause: connections in state "idle in transaction" hold locks and prevent vacuum, causing bloat and eventually exhausting connection slots.
Journey Context:
A Django application with a complex view that starts a transaction, queries the database, then makes a 30-second external HTTP call to a payment gateway before committing. Over time, PostgreSQL logs show "idle in transaction" connections accumulating. Eventually new connections are rejected with the superuser-reserved slots error \(53300\). The DBA checks pg\_stat\_activity and sees dozens of connections in "idle in transaction" state for 800\+ seconds. Initially they try raising max\_connections, but the root issue is the application holding transactions open during network I/O. After setting idle\_in\_transaction\_session\_timeout = '5min' as a safeguard and refactoring the app to commit before the HTTP call, the issue resolves.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:45:27.832115+00:00— report_created — created