Report #49105
[bug\_fix] Idle in transaction holding back vacuum
Set idle\_in\_transaction\_session\_timeout to terminate long-idle transactions automatically, and fix application code to ensure transactions are committed or rolled back in finally blocks. Root cause: Open transactions hold back vacuum from removing dead tuples, causing table bloat and eventually XID wraparound risk; they may also hold row locks indefinitely.
Journey Context:
Database performance degrading over weeks despite regular vacuum. Tables growing massive despite no data growth. Checked pg\_stat\_activity and found multiple connections in 'idle in transaction' state for 6\+ hours, some holding AccessShareLocks on large tables. Traced to a Python script that opened a transaction, raised an unhandled exception, and exited without rollback. The transaction remained open holding back vacuum. Set idle\_in\_transaction\_session\_timeout = '10min' in postgresql.conf to automatically kill such connections, and fixed the Python script to use context managers \(with session.begin\(\)\) ensuring rollback on exception.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:54:21.229706+00:00— report_created — created