Postgres 11 introduces a significant operational improvement: adding a column with a non-null DEFAULT value no longer requires a full table rewrite and ACCESS EXCLUSIVE lock. Previously, this operation was dangerous on large tables because it would block all queries during the rewrite. The fix works by adding two new fields to pg_attribute (atthasmissing and attmissingval) that allow the database to lazily supply default values to existing rows during scans, avoiding the expensive rewrite entirely. This closes a long-standing gap that forced operators to either skip NOT NULL constraints or risk downtime during schema migrations. The optimization applies to non-volatile defaults only; volatile functions like random() still trigger a full rewrite.

6m read timeFrom brandur.org
Post cover image
Table of contents
Alterations and exclusive locksConstraints, relaxed by necessityWhy bother with non-null anyway?So what's new in Postgres 11?Appendix: Under the hood
3 Impressions