Report #14315
[bug\_fix] idle in transaction timeout / lock wait timeout - long-running transaction locks
Set idle\_in\_transaction\_session\_timeout to kill stale transactions automatically, and implement application-level lock\_timeout to fail fast on contention; ensure transactions are committed/rolled back promptly in application code.
Journey Context:
Your application starts experiencing sporadic 30-second hangs on simple SELECT queries. You check pg\_stat\_activity and see several rows with state='idle in transaction' and xact\_start from 10 minutes ago. These idle transactions are holding RowExclusiveLocks on critical tables, blocking your new queries. You investigate the application code and find that in an error handling path, a transaction is started but never rolled back or committed due to an early return. You kill the idle transactions with pg\_terminate\_backend\(\), which unblocks the queue. To prevent recurrence, you set 'idle\_in\_transaction\_session\_timeout = 300000' \(5 minutes\) in postgresql.conf to automatically kill idle transactions. You also set 'lock\_timeout = 10s' in the application connection string to ensure queries fail fast if they can't acquire locks, preventing cascade failures. The root cause is connection leaks where transactions are left open, holding locks indefinitely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:15:47.928968+00:00— report_created — created