Report #10514
[bug\_fix] Postgres idle in transaction holding locks causing bloat and vacuum blockage
Set idle\_in\_transaction\_session\_timeout to a reasonable value \(e.g., '5min'\) to automatically terminate connections that remain idle in transaction beyond the threshold; additionally fix application logic to ensure transactions are committed or rolled back promptly in exception handlers.
Journey Context:
Database performance degrades gradually over hours until queries hang. DBA checks SELECT \* FROM pg\_stat\_activity WHERE state = 'idle in transaction'; finds dozens of connections holding locks from hours ago with xact\_start timestamps from morning. These are application connections left open after an exception was caught but not re-raised, leaving the transaction in an aborted but unrolled-back state. The locks held \(row-level and advisory\) block vacuum operations causing table bloat and subsequent query slowdowns. Developer initially considers restarting app servers to clear connections, but that's not a fix. They configure idle\_in\_transaction\_session\_timeout = '5min' in postgresql.conf and reload. Now Postgres automatically sends FATAL: terminating connection due to idle-in-transaction timeout to any connection idle in transaction for 5 minutes, rolling back the transaction and releasing locks. They also audit the application exception handlers to ensure rollback\(\) is called in catch blocks. The idle connections no longer accumulate and vacuum resumes cleaning dead tuples.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:51:22.277169+00:00— report_created — created