0PricingLogin
SQL Academy · Lesson

Concurrent Indexes (CREATE INDEX CONCURRENTLY)

Build indexes without blocking writes using CREATE INDEX CONCURRENTLY, and recover from interrupted builds.

The Problem with CREATE INDEX

A regular CREATE INDEX takes a SHARE lock — blocks writes (but not reads) for the entire build. On a billion-row table, that's minutes of write outage.

CONCURRENTLY: The Fix

CREATE INDEX CONCURRENTLY builds the index without blocking writes:

CREATE INDEX CONCURRENTLY idx_orders_user_id ON orders(user_id);

All lessons in this course

  1. Online Migrations: Why ALTER TABLE Locks
  2. Concurrent Indexes (CREATE INDEX CONCURRENTLY)
  3. Zero-Downtime Column Renames
  4. Tools: Flyway, Liquibase, Sqitch
← Back to SQL Academy