☆ 15 r/databases ·by Oskar ·2026-11-03 Adding a column with a default to a big table 1534 views ALTER TABLE events ADD COLUMN flagged boolean NOT NULL DEFAULT false on a 30M row table. Will this lock the table? ⧉ Copy link⚑ Report
☆ 0 J Jordan ·2026-11-03#1 On Postgres 11+ a constant default is mostly metadata only, but older versions rewrite the table. A volatile default always rewrites. ⧉ Copy link⚑ Report
☆ 0 O Oskar ·2026-11-03#2 We are on Postgres 12 but the migration still seemed slow. ⧉ Copy link⚑ Report
☆ 0 J Jules R. ·2026-11-04#3 Check for a long-running transaction holding a lock on the table. Add the column as nullable first, backfill in batches, then set NOT NULL. ⧉ Copy link⚑ Report
3 replies