Adding a new column is not just a schema change. It can break queries, slow writes, or lock tables if done poorly. The right approach depends on your database and workload. A careless migration can stall production for hours. A precise migration can ship in seconds.
Plan before you alter.
- Define the column’s role and data type.
- Set default values only when necessary—defaults can trigger full table rewrites.
- Avoid nullable columns unless they reflect a real absence of data.
- Index with caution. Adding an index during the same migration can double the cost.
Control the change.
- In Postgres,
ALTER TABLE ADD COLUMNis fast if no defaults are set. Defaults force a rewrite. - In MySQL, adding a column may lock the table unless using
ALGORITHM=INPLACE. - For large datasets, add the column first, then backfill in batches.
- Monitor replication and lag before and after the change.
Test in a staging environment.