Roll out a database schema change without downtime

8 steps · about 3 h 12 min · Intermediate

  1. Treat schema evolution as continuous work (guide, Martin Fowler, 28 min)

    Connect database changes to version control, automated deployment and compatibility between application versions.

  2. Map the expand-and-contract sequence (guide, Prisma Data Guide, 24 min)

    Separate additive schema, data movement and later removal so deploy order stays reversible.

  3. Backfill in controlled batches (reference, PostgreSQL documentation, 24 min)

    Update existing rows with an explicit predicate and repeatable ordering rather than one unbounded data rewrite.

  4. Observe migration activity and waits (reference, PostgreSQL documentation, 24 min)

    Inspect active sessions and wait events during rehearsal and rollout instead of discovering blocked traffic from timeouts alone.

  5. Build indexes while writes continue (reference, PostgreSQL documentation, 20 min)

    Use concurrent index construction when its longer multi-phase behavior is preferable to blocking table writes.

  6. Add constraints in controlled phases (reference, PostgreSQL documentation, 24 min)

    Use NOT VALID and later validation where appropriate to separate enforcement planning from an immediate full-table check.

  7. Make the application rollout repeatable (guide, GitLab Docs, 24 min)

    Coordinate compatible binaries, background data movement and later cleanup through an auditable migration process.

  8. Canary the read and write switch (guide, Google SRE Workbook, 24 min)

    Observe correctness and load on a small slice before committing all traffic or contracting the old schema.