Adding a new column is one of the most common schema changes in any production database. Done right, it’s fast, safe, and invisible to users. Done wrong, it can lock tables, block writes, and trigger downtime.
Before adding a new column, examine your database engine’s behavior. In MySQL prior to 8.0, ALTER TABLE with a new column could rebuild the entire table. In PostgreSQL, adding a nullable column with a default can still cause a full table rewrite if not handled carefully. For large datasets, plan the change to avoid long locks.
The simplest path for most systems is:
- Add the column as
NULLwithout a default. - Backfill data in small batches.
- Add constraints or defaults after the backfill is complete.
This approach keeps migrations non-blocking and maintains service uptime. If the column must be NOT NULL, enforce that only after you are certain every row is populated correctly.