Adding a new column is one of the most common schema changes in modern development. It’s also one of the easiest changes to get wrong at scale. A single ALTER TABLE can lock a table for minutes or even hours, depending on the size of the data. In high-traffic systems, that’s unacceptable.
The best approach starts with assessing the table’s size and traffic patterns. For large datasets, online schema change tools like gh-ost or pt-online-schema-change avoid long locks. These tools create a shadow table with the new column, sync data, and then swap it in with minimal downtime. Always test these migrations in a staging environment with production-like data volumes before hitting production.
When adding the new column, decide on NULL vs. NOT NULL early. Setting a default value on a large table can trigger a full table rewrite. Sometimes it’s safer to add the column as nullable, backfill data in batches, and then enforce NOT NULL in a separate, zero-downtime step.
Mind storage engines, too. In MySQL, InnoDB handles online DDL differently than MyISAM. In PostgreSQL, adding a NULLable column without a default is instant, but adding one with a default will rewrite the whole table unless you’re on a version that supports the optimized metadata-only change.