Report #23096
[bug\_fix] canceling statement due to lock timeout during DDL migration
The migration requires an ACCESS EXCLUSIVE lock on the table, but long-running queries or idle transactions are blocking it. The fix is to use CREATE INDEX CONCURRENTLY for index creation, which takes only a SHARE UPDATE EXCLUSIVE lock, allowing reads and writes. For non-concurrent DDL, set a short lock\_timeout \(e.g., SET lock\_timeout = '2s'\) so the migration fails fast rather than queueing indefinitely, then retry during low traffic. Alternatively, terminate blocking queries before migration.
Journey Context:
You run 'rails db:migrate' to add an index on a 100GB table during business hours. The command hangs. In another terminal, SELECT \* FROM pg\_stat\_activity shows the migration blocked by an idle transaction holding a RowExclusiveLock. The migration waits for ACCESS EXCLUSIVE. You cancel it, kill the idle transaction, and re-run with CREATE INDEX CONCURRENTLY \(ActiveRecord's algorithm: :concurrently\), which completes without locking the table. Alternatively, you set lock\_timeout to 30s and schedule retries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:10:21.600965+00:00— report_created — created