Lesson 2 of 7

Adding Columns and Constraints Without Downtime

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source

The one thing to understand first

The previous article showed why strong locks held for a long time are dangerous. The art of online schema change is converting an operation that scans or rewrites the table into one that only touches the catalog — or splitting it into a fast lock plus a slow, lock-light scan.

Every safe schema change follows the same shape: make the metadata change instantly under a brief lock, then do the heavy data work (backfill or validation) separately without blocking reads and writes. Constant defaults, NOT VALID constraints, and validated-CHECK-then-SET NOT NULL are all instances of that one idea.

Adding a column with a default

Modern PostgreSQL stores a constant default as catalog metadata (a “missing value”) rather than rewriting every row. So this is fast even on huge tables:

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • NOT VALID: the key to online constraints
  • Adding NOT NULL safely
  • Changing a column type
  • Layer 3 — Watch it happen on your own database
  • Layer 4 — The levers this hands you
  • Layer 5 — What an Oracle DBA should expect vs what they get
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Was this helpful?

← Back to 03 — Operations: Zero-Downtime Deployments