Adding a new column is one of the most common database changes. Done right, it preserves performance and integrity. Done wrong, it can lock tables, stall deployments, and create silent data corruption. The mechanics are simple. The consequences are not.
When you add a new column in SQL, you start with ALTER TABLE. This operation must be scoped to avoid blocking writes. On production systems, large tables make this tricky. Some engines support ADD COLUMN with an implicit default; others rewrite the whole table. In PostgreSQL, adding a nullable column is fast. Adding a column with a default can cause a full table rewrite unless you use DEFAULT with NOT NULL and backfill later. MySQL’s behavior varies depending on the storage engine and version.
Plan the change in stages:
- Create the column as nullable, no default.
- Backfill data in controlled batches.
- Apply constraints or defaults after the backfill finishes.
This approach avoids downtime and minimizes replication lag. In systems with strict SLAs, test the migration in a staging environment with realistic data volumes. Monitor lock times and IO impact.