The database paused, waiting. You run the migration. A new column appears.
Adding a new column is one of the most frequent schema changes in modern software. It looks simple, but poor execution can lock rows, block writes, slow queries, and take down services. The right approach keeps systems online and data consistent while applying structural changes at scale.
Before adding a new column, decide on the correct data type, constraints, and default values. Incorrect settings here can force costly rewrites later. In PostgreSQL, for example, adding a column with a non-null default rewrites the entire table, holding locks. In MySQL, some operations are instant while others require a full table copy. Understanding the specific database behavior is essential to avoid downtime.
For production workloads, add the new column with nullable defaults first. Migrate data in controlled batches. Backfill values using background jobs or scripts. Once the column is populated, add constraints and indexes in separate steps. This phased pattern reduces locking impact and isolates failure conditions.