Report #75777
[bug\_fix] FATAL: terminating connection due to idle-in-transaction timeout
Set idle\_in\_transaction\_session\_timeout in postgresql.conf \(e.g., '5min'\) to automatically kill leaked connections, and audit application code to ensure transactions always commit or rollback in try/finally blocks.
Journey Context:
Production app mysteriously exhausts connection pool despite low traffic. pg\_stat\_activity reveals numerous connections in 'idle in transaction' state lasting hours, holding locks and preventing vacuum. Investigation traced to a background job that opened a transaction, threw an exception that was caught but not re-raised, and continued running without rolling back. The fix involved configuring PostgreSQL's idle\_in\_transaction\_session\_timeout to 5 minutes, acting as a safety net to kill these zombies, and refactoring the job to use context managers \(try/finally\) ensuring rollback on any exit path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:47:34.446372+00:00— report_created — created