Report #17267
[bug\_fix] CREATE INDEX blocks table writes \(ACCESS EXCLUSIVE lock\)
Use \`CREATE INDEX CONCURRENTLY\` \(PostgreSQL-specific\). This builds the index without taking the \`ACCESS EXCLUSIVE\` lock that blocks writes \(and in older versions, reads\). It performs two scans of the table and waits for existing transactions to finish, taking longer overall but avoiding downtime. It must be run outside of a transaction block.
Journey Context:
A Ruby on Rails team deploys a migration to add an index on the \`email\` column of a 100-million-row \`users\` table during a low-traffic window. The migration command \`add\_index :users, :email\` executes \`CREATE INDEX\`. Within seconds, monitoring alerts trigger: write latency spikes to 30 seconds, the connection pool exhausts, and the application returns 503 errors. The developer checks \`pg\_stat\_activity\` and sees the \`CREATE INDEX\` statement waiting on an \`ACCESS EXCLUSIVE\` lock, which queues all subsequent writes. They realize the index build takes 20 minutes, effectively causing a 20-minute outage. They immediately cancel the query \(which rolls back the index creation\). To fix, they rewrite the migration using \`algorithm: :concurrently\` \(Rails abstraction\) which emits \`CREATE INDEX CONCURRENTLY\`. They deploy this during a maintenance window. The index builds successfully over 40 minutes, but during the build, the application remains fully responsive with no lock contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:52:45.478466+00:00— report_created — created