Adding a new column to a production database is not just a table alteration. It’s a change that can ripple through schemas, migrations, indexes, foreign keys, and application code. Done right, it is seamless. Done wrong, it can lock tables, spike latency, or drop availability.
Start with the database engine’s native command. In PostgreSQL, use ALTER TABLE table_name ADD COLUMN column_name data_type;. In MySQL, it’s ALTER TABLE table_name ADD COLUMN column_name data_type AFTER existing_column; if order matters. Define defaults only when required, to avoid long locks during backfill. Keep new columns nullable until the data is ready. For large datasets, batch updates and avoid full table rewrites.
If the application layer depends on the column, deploy in phases. Add the new column first. Let code reference it without requiring it. Populate it in the background. Once data is complete, enforce constraints. Wrap every change in version control and track migrations with tools like Flyway or Liquibase. Always test migrations against snapshots of production-size data to surface performance issues before they hit the live environment.