Adding a new column is one of the most common database schema changes. Done right, it keeps your application fast, reliable, and easy to evolve. Done wrong, it can lock tables, cause downtime, and break critical code paths. This guide covers how to add a new column to production systems, zero downtime approaches, and the pitfalls to avoid.
Plan the schema change
Start by defining exactly what the new column will store. Choose the smallest data type that works. Keep nullability, defaults, and constraints clear from the start. Adding defaults that require backfilling millions of rows can cause lock contention.
Choose the safest migration path
For PostgreSQL, adding a nullable column without a default is instant. Adding a default with ALTER TABLE in older versions rewrites the whole table. In MySQL, adding columns can trigger a table copy. Use tools like pt-online-schema-change or gh-ost to reduce impact.
Backfill in batches
If you need to populate historical data, do it in small chunks outside peak hours. This keeps replication lag manageable and avoids throttling the database. Track progress and verify each step before moving to the next.