Report #61733
[bug\_fix] Idle in transaction timeout causing table bloat and XID wraparound risk
Set \`idle\_in\_transaction\_session\_timeout\` in postgresql.conf to automatically terminate idle transactions, and refactor application logic to release transactions promptly.
Journey Context:
Production Postgres database showing high table bloat on \`orders\` table. Autovacuum running but not keeping up. Checking \`pg\_stat\_activity\` showed several connections in state \`idle in transaction\` for hours. These were from a background job worker that opened a transaction, processed a batch, but crashed or hung before committing. These idle transactions held back vacuum from removing dead tuples, causing bloat. Also risking XID wraparound. Initially tried killing connections manually. Then set \`idle\_in\_transaction\_session\_timeout = '10min'\` in postgresql.conf and reloaded. Now idle transactions are killed automatically after 10 mins, releasing locks and allowing vacuum to proceed. Also fixed the worker to use shorter transactions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:06:23.712933+00:00— report_created — created