Skip to content

CICD-318 · Zero-downtime schema migration ​

Encyclopedia · Database delivery and migration · All snippets

Previous · CICD-317 · Next · CICD-319

1. Where it fits ​

  • Placement migrations/add_email_index.sql.
  • Prerequisites disposable database, migration tools and a scoped database role.
  • Platforms local-lab.

2. Copy the snippet ​

sql
SET lock_timeout = '3s';
CREATE INDEX CONCURRENTLY IF NOT EXISTS accounts_email_idx ON accounts (email);

3. How it works ​

PostgreSQL builds the index in concurrent phases so ordinary writes can continue. Run outside a transaction block and check for an invalid index after an interrupted attempt.

4. Verify the result ​

Run outside a transaction block. Inspect pg_index.indisvalid and recovery from failed concurrent builds.

Validation untested. Status definitions.