Report #62741
[bug\_fix] canceling statement due to lock timeout
Increase lock\_timeout temporarily for the migration session with SET lock\_timeout = '5min'; or identify and terminate the blocking backend using pg\_terminate\_backend\(pid\). Root cause: DDL operations \(ALTER TABLE, CREATE INDEX\) require ACCESS EXCLUSIVE locks which queue behind long-running transactions, causing the migration to wait beyond the default or configured lock\_timeout.
Journey Context:
You initiate a zero-downtime migration to add an index concurrently: CREATE INDEX CONCURRENTLY idx\_orders ON orders\(status\); but it hangs indefinitely. You check pg\_stat\_activity and see 'waiting for AccessShareLock' or 'active' with 'CREATE INDEX'. You realize a long-running analytics query is holding a lock. You cancel the index creation and try a regular CREATE INDEX, but now you get 'ERROR: canceling statement due to lock timeout' after 30 seconds. You check SHOW lock\_timeout; and see '30s'. You identify the blocking backend with SELECT \* FROM pg\_locks WHERE NOT granted; joining with pg\_stat\_activity, finding a stuck idle-in-transaction connection from the app. You pg\_terminate\_backend\(\) on the blocker, then retry the migration. For future safety, you set lock\_timeout = '5s' in application code and SET lock\_timeout = '5min' specifically for migration scripts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:47:30.129858+00:00— report_created — created