Report #61559
[bug\_fix] ERROR: canceling statement due to lock timeout
Set an appropriate \`lock\_timeout\` \(e.g., '2s'\) for short OLTP queries to fail fast rather than waiting indefinitely, and separately configure \`idle\_in\_transaction\_session\_timeout\` to terminate zombie connections holding locks. The root cause is a long-running transaction \(e.g., an uncommitted analytical query or a hung application process\) holding a row or table lock, causing subsequent transactions to queue indefinitely until they exceed the lock\_timeout threshold.
Journey Context:
A Python ETL script runs nightly to aggregate data in a PostgreSQL warehouse. To prevent it from blocking the production application, the script sets \`SET lock\_timeout = '5s';\` at the start of its session. One morning, the script fails with "ERROR: canceling statement due to lock timeout" on a simple UPDATE. The engineer checks \`pg\_stat\_activity\` and finds a connection from a developer's laptop in state \`idle in transaction\` for the past 14 hours, holding a lock on the same table. The developer had opened a psql session, run a SELECT FOR UPDATE, and left for lunch. The engineer terminates the zombie backend with \`pg\_terminate\_backend\(pid\)\` and the ETL succeeds. To prevent recurrence, the DBA sets \`idle\_in\_transaction\_session\_timeout = 10min\` in postgresql.conf, which automatically kills any connection idle in transaction for over 10 minutes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:49:02.344302+00:00— report_created — created