Report #73769
[bug\_fix] CREATE INDEX blocks writes with AccessExclusiveLock
Use CREATE INDEX CONCURRENTLY instead of CREATE INDEX. This builds the index without acquiring the long-lived AccessExclusiveLock that blocks writes \(and reads\) on the table. Root cause: Standard CREATE INDEX locks the table for the entire build duration to ensure consistency, causing outages on production tables.
Journey Context:
A developer needs to add an index to a 500GB "orders" table to speed up queries. They run CREATE INDEX idx\_created\_at ON orders\(created\_at\); during a low-traffic window. Within seconds, application monitoring shows elevated latency and timeouts. Checking pg\_stat\_activity, they see the CREATE INDEX command holding an AccessExclusiveLock on the "orders" table, with 200 other queries queued behind it waiting for the lock. The application threads hang, then timeout. Realizing the standard index creation locks the entire table, the developer cancels the query \(which takes minutes to roll back\), then re-runs CREATE INDEX CONCURRENTLY. The command takes twice as long and uses more CPU, but the site remains responsive throughout because the lock level is only ShareUpdateExclusiveLock, allowing reads and writes to continue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:25:05.305917+00:00— report_created — created