A table is failing in production. The logs point to missing data. You realize the schema needs a new column, but there’s no room for downtime.
Adding a new column sounds simple. In reality, it can block queries, lock writes, and burn CPU if done wrong. The method you choose depends on database type, table size, and access patterns.
In PostgreSQL, ALTER TABLE ADD COLUMN is fast if you only add a column with a default of NULL. Adding a column with a non-null default rewrites the whole table, which is slow. Use NULL first, then backfill in small batches. When backfill completes, set the NOT NULL constraint.
In MySQL, on large InnoDB tables, adding a column can lock the table depending on the storage engine version. Use ALGORITHM=INPLACE or ALGORITHM=INSTANT where supported. Without instant DDL, consider creating a shadow table with the new column, copying data in chunks, and swapping it in.