Cold data stared back from the terminal, millions of rows, each missing the one field you now need. The fix is simple: add a new column. The challenge is doing it without locking production, breaking queries, or waiting hours for migrations to finish.
A new column in a database is more than just schema change. It can alter performance, impact indexing, and shift query plans. In PostgreSQL, adding a nullable column without a default is instant. But add a default to existing rows, and you risk a full table rewrite. MySQL behaves differently: some column types and defaults are metadata-only changes, others are blocking. Know your database engine before you execute.
Start by auditing the table size and traffic patterns. For large datasets, break the migration into stages:
- Add the column as nullable with no default.
- Backfill data with batched updates during off-peak hours.
- Add constraints or set defaults after data is in place.
Avoid schema changes during high write loads. Check replica lag if your system uses read replicas. Schema changes must be applied in sync, and replication delays can cascade into degraded performance.