Blocking Pattern (Avoid in Production)

ALTER TABLE billing.orders ADD COLUMN trace_token UUID DEFAULT gen_random_uuid();

Zero-Downtime Safe Rewrite

SET lock_timeout = '2s';
ALTER TABLE billing.orders ADD COLUMN trace_token UUID;
ALTER TABLE billing.orders ALTER COLUMN trace_token SET DEFAULT gen_random_uuid();

Production Rollout Notes

  • Always set lock_timeout because even a 1ms ACCESS EXCLUSIVE lock queues behind long-running reads.
  • Backfill existing rows in small batches after setting the default for future inserts.