Report #15880
[bug\_fix] canceling statement due to lock timeout during DDL migration
Increase lock\_timeout for the migration session, or terminate blocking idle transactions before running migrations. Root cause: DDL statements \(ALTER TABLE\) require ACCESS EXCLUSIVE locks which queue behind existing long-running queries or idle-in-transaction connections; default lock\_timeout \(0 = infinite\) or statement\_timeout kills the migration before the lock is acquired.
Journey Context:
Running Alembic migration to add index on 500GB table during business hours. Migration failed after 60 seconds with 'canceling statement due to lock timeout'. Checked pg\_stat\_activity and saw an idle-in-transaction connection from a developer's psql session holding a lock on the table for 3 hours. Realized the migration's ALTER TABLE ... ADD INDEX was waiting in the lock queue and hitting the application-configured lock\_timeout of 60s. Killed the idle session, increased lock\_timeout to '5min' for the migration user, and re-ran during maintenance window with application shutdown to ensure no lock contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:17:30.223934+00:00— report_created — created