The query ran fast and broke on the first step. The schema didn’t match. A new column was missing.
Adding a new column is simple at first glance, but it is one of the most common points where systems slow, fail, or cause downtime. Whether you are using PostgreSQL, MySQL, SQLite, or a distributed SQL engine, the wrong migration strategy can lock tables, block writes, or corrupt data under load.
The safest way to add a new column depends on three factors: size of the table, traffic patterns, and the database’s DDL behavior. For small tables, an ALTER TABLE ... ADD COLUMN is almost instant. For large or high-traffic tables, that statement can trigger a full table rewrite. On production systems, always measure the impact in staging with the same data size and indexes.
Use defaults carefully. In PostgreSQL, adding a new column with a default and NOT NULL creates a table rewrite. To avoid this, add the column as nullable, backfill values in small batches, then set the default and NOT NULL in separate steps. MySQL’s behavior depends on the storage engine, but the same principle applies: break changes into minimal-impact steps.