Adding a new column to a database table sounds simple. It is not. Without care, it can lock tables, slow requests, and trigger outages. Production migrations magnify the risk. Each data store behaves differently, and the wrong approach can cause minutes or hours of downtime.
When adding a new column in PostgreSQL, the fastest operation is adding it with a default value of NULL. Setting a non-null default writes to every row, which can be expensive. MySQL follows similar rules but has different locking behavior depending on the storage engine and server version. In both systems, schema changes should be paired with versioned migrations and rolled out in steps:
- Add the new column nullable.
- Backfill data in controlled batches.
- Enforce constraints after the backfill is complete.
For distributed systems, schema changes must be backward-compatible. Deploy application updates that work with both old and new schemas before altering the table. This avoids breakage during the migration window.