On this page
  1. Schema Migrations & Reliability
  2. Contents
  3. Zero-Downtime Expand-and-Contract Migrations
  4. Idempotency Keys & Transactional Outbox
  5. Backups & Point-in-Time Recovery (PITR)

Schema Migrations & Reliability

Prev: Scaling, Partitioning & Sharding | Up: design_patterns | Next: nosql
Rel: DDL & Constraints, Transactions, ACID & Isolation Levels
Ref: PostgreSQL — Backup and Restore
Tags: #public #databases #design-patterns #migrations #reliability


Contents


Zero-Downtime Expand-and-Contract Migrations

Never rename or drop a live column in one step while old app instances are still running:

  1. Expand: Add the new nullable column or table; deploy app code that dual-writes both old and new columns.
  2. Backfill: Populate historical rows in small batches to avoid lock contention and WAL spikes.
  3. Switch reads: Deploy app code reading from the new column, add NOT NULL / constraints (NOT VALID -> VALIDATE CONSTRAINT in PostgreSQL).
  4. Contract: Remove writes to the old column, then drop it in a later release.

Idempotency Keys & Transactional Outbox


Backups & Point-in-Time Recovery (PITR)

A backup is only real once you have tested restoring it. Combine periodic base backups with continuous WAL archiving for Point-in-Time Recovery to any second before an accidental DELETE.

Linked from

Related notes