CREATE INDEX CONCURRENTLY: When It Helps, What It Costs, and What Can Go Wrong
PostgreSQL offers two ways to build indexes in production: the standard CREATE INDEX, which blocks all writes for the entire build duration, and CREATE INDEX CONCURRENTLY, which avoids write locks but takes significantly longer to complete. Benchmarks on a 20-million-row table show the plain form blocked inserts for over 4 seconds, while the concurrent form kept the worst wait under 125 milliseconds. The concurrent build scans the table twice and waits for open transactions to close, making it slower but far safer on live, write-heavy tables. However, if a concurrent build fails midway due to a deadlock or cancellation, it leaves behind an invalid index that consumes write overhead without ever being used by the query planner. Developers should routinely query pg_index for invalid indexes after migrations and drop them using DROP INDEX CONCURRENTLY to avoid silent performance degradation.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in