Report #53909
[bug\_fix] canceling statement due to lock timeout \(SQLSTATE 55P03\) or indefinite hang during DDL
Set lock\_timeout in the migration session to a low value \(e.g., '2s'\) so the migration fails fast if blocked, rather than hanging indefinitely. Before migrating, terminate long-running queries that hold locks on the table, or use CREATE INDEX CONCURRENTLY and ALTER TABLE ... ADD COLUMN without DEFAULT \(or with safe defaults\) to avoid heavy locking.
Journey Context:
Running a Django migration to add an index to a 500GB table causes the migration to hang for hours. Querying pg\_stat\_activity shows the ALTER TABLE waiting for AccessExclusiveLock on the table, blocked by a 6-hour-old analytics query. The developer reads about Postgres locking queues: once the ALTER is in the queue, even readers behind it block. They cancel the migration, set lock\_timeout = '10s' in the migration script so it fails fast with 'canceling statement due to lock timeout'. They then schedule the migration during a maintenance window after killing long queries, and switch to CREATE INDEX CONCURRENTLY for future index additions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:58:55.306371+00:00— report_created — created