Blocking Pattern (Avoid in Production)

ALTER TABLE billing.orders ALTER COLUMN external_id TYPE BIGINT;

Zero-Downtime Safe Rewrite

-- Expand-Contract zero-downtime migration:
ALTER TABLE billing.orders ADD COLUMN external_id_v2 BIGINT;
-- Dual-write new rows, backfill in batches of 10k, add index concurrently, then swap.

Production Rollout Notes

  • Widening VARCHAR(n) to VARCHAR(m) or TEXT is metadata-only in modern PostgreSQL.
  • Changing numeric/int types almost always triggers a blocking rewrite.