Report #60565
[bug\_fix] ERROR: canceling statement due to lock timeout \(55P03\) – DDL blocked by long-running query
Set \`lock\_timeout\` \(e.g., '2s'\) in migration scripts to be shorter than \`statement\_timeout\`, causing the migration to fail fast if it cannot acquire the AccessExclusiveLock immediately, rather than hanging indefinitely.
Journey Context:
A developer runs a Django migration to add a NOT NULL column with a default value on a 500GB production table. The migration issues ALTER TABLE, which requires an AccessExclusiveLock. Unbeknownst to the dev, a BI tool has held an idle in transaction read query on that table for 3 hours. The migration hangs. The dev waits 30 minutes, then checks pg\_stat\_activity, seeing the migration waiting on the BI query. The dev initially sets statement\_timeout='10s' in the migration, but it still hangs for 10s\+ because statement\_timeout only starts after lock acquisition. The dev reads the docs and realizes lock\_timeout governs the wait for the lock. They set lock\_timeout='5s'. The migration now fails immediately with 55P03, alerting the CI/CD pipeline. The ops team kills the BI query, and the migration retries successfully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:08:44.969062+00:00— report_created — created