Engineering Analysis · Global
What to check before building a PostgreSQL index on a busy table
Adding CONCURRENTLY keeps writes moving, but it changes your migration, monitoring and recovery plan.
By Launchr Space ·
An index that makes a dashboard faster can still make for a bad deploy. Building one on a heavily written orders table is operational work, even if the migration is a single statement. PostgreSQL's concurrent build mode is useful precisely because it avoids blocking ordinary writes for the duration of the build. It is not a promise of a fast or low-impact migration.
Rehearse the operation your runner will actually execute
PostgreSQL does more work for a concurrent build: it scans the table twice and waits for relevant transactions at several points. It also requires the command to run outside a transaction block. Check whether your migration runner wraps every change in a transaction, and choose its documented nontransactional path if needed. Do not quietly drop the concurrent option just to pass a deployment check. On a staging table with representative volume and write activity, measure how the build affects requests that matter and check how long-running transactions affect completion.
Know what failure leaves behind
A failed concurrent build can leave an invalid index. PostgreSQL won't use that index for query planning, but it can still cost work on writes. For a unique index, some failed builds can continue enforcing uniqueness. Before retrying, inspect the index's actual state and understand why the first attempt failed. A script that simply retries with IF NOT EXISTS can mistake a leftover name for success. Plan the cleanup and get the appropriate review before removing an index in production.
Define done from the application's point of view
During the rollout, watch index progress and application latency together. If the build is waiting, check its reported phase and the long-running transactions before deciding whether to stop it. Once it finishes, verify the index is valid, then use a representative query and realistic parameters to check the plan. A valid index that the target query never uses does not solve the original problem. Finally, compare read latency and write cost over normal traffic before calling the rollout a win.