The migration finished at 02:14, but the table wasn’t ready. We needed a new column, and we needed it without downtime.
Adding a new column sounds simple. It isn’t. Done wrong, it locks rows, blocks writes, or drags replication to a crawl. In high-throughput systems, that cost is a risk you can’t take. The right approach starts with understanding how your database engine handles schema changes.
For PostgreSQL, ALTER TABLE ADD COLUMN is fast when adding nullable columns without a default. That operation updates metadata only, avoiding a full table rewrite. But the moment you add a default value, PostgreSQL rewrites the entire table. On large datasets, that’s hours of blocking. The safe path: create the column as nullable, backfill in small batches, then set the default and constraints.
MySQL’s behavior depends on its storage engine and version. On recent releases with InnoDB and ALGORITHM=INSTANT, adding a column at the end of the table can be instant. Without it, you may see a full table copy. Always check information_schema and execution plans before running changes in production.