Report #95229
[bug\_fix] Postgres migration lock timeout \(CREATE INDEX blocks writes\)
Use CREATE INDEX CONCURRENTLY to avoid locking the table for writes, or set lock\_timeout to fail fast rather than queue indefinitely; schedule heavy DDL during maintenance windows and avoid long transactions that block DDL.
Journey Context:
Running a Django migration to add an index on a 100M row production table during business hours. Command hangs indefinitely. Check pg\_stat\_activity: the migration's CREATE INDEX is in state active, waiting on AccessShareLock, blocked by a long-running analytics query holding AccessShareLock. Meanwhile, new write queries are queuing behind the migration's ShareLock request, causing application downtime. Realize that standard CREATE INDEX takes an ACCESS EXCLUSIVE lock \(or blocks writes in older versions\), preventing any inserts/updates during the scan. Kill the migration. Retry with CREATE INDEX CONCURRENTLY \(Django's AddIndexConcurrently\). This method does not block writes, though it takes longer and cannot run inside a transaction block. Also set SET lock\_timeout = '5s'; before DDL to fail fast if blocked. Schedule future index creation during maintenance windows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:25:12.799024+00:00— report_created — created