Adding a new column is one of the most common operations in database migrations, yet it’s where performance, downtime, and data integrity collide. The challenge comes when the table is large, live, and under heavy traffic. An ALTER TABLE that locks rows for minutes—or hours—can cripple your system.
The safe approach starts with understanding your database engine. In PostgreSQL, adding a nullable column without a default is fast—the metadata changes instantly. But adding a column with a default value forces a rewrite. MySQL struggles with similar operations on large tables unless you use ALGORITHM=INPLACE when possible.
To avoid downtime, use staged migrations. First, add the new column as nullable. Deploy. Then backfill in small batches, controlled by an application job or migration script that limits row updates per transaction. Finally, set the NOT NULL constraint or the default value once the data is ready.