The database table was ready, but the feature needed more room to grow. You need a new column. Fast. Without downtime. Without corrupting data.
Adding a new column sounds simple. It isn’t. Every database engine has its own rules. Some lock the entire table. Some rewrite it on disk. On massive datasets, that means hours of frozen writes. Users see errors. Pipelines fail.
The safest way to add a new column is to plan for scale. First, define the column with defaults that won’t trigger full rewrites. Use nullable columns when possible to avoid immediate value backfill. If defaults are required, use a stepwise migration:
- Add the column as nullable.
- Backfill values in small batches.
- Add constraints or defaults only after data is consistent.
For PostgreSQL, ALTER TABLE ADD COLUMN with a NULL default happens instantly. But adding a column with a non-null default rewrites the table. MySQL and MariaDB behave differently depending on version and storage engine. Check the specific behavior before production changes.