Urgent.News

What's breaking now, across thousands of outlets.

More in Tech

Adding a NOT NULL Column to a Large PostgreSQL Table: Constant Default, Backfill or NOT VALID

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples. TL;DR: On PostgreSQL 11 and later, ADD COLUMN ...

  • Adding a NOT NULL column with constant default (e.g., NOW()) is fast in PostgreSQL 11+.
  • For per-row computed values, add column as nullable, backfill in batches, then set NOT NULL.
  • PostgreSQL 12+ allows NOT VALID constraint to skip full table scan during backfill.

More from Thursday 1 October →