The query had been running fine for months. Then the business team asked for a new column.
Adding a new column to a database table sounds simple. In reality, it can break queries, slow down writes, and disrupt downstream jobs. The risk comes from how schema changes interact with production traffic. Even a single ALTER TABLE can lock rows, rewrite data, or cause replication lag.
The right approach starts with understanding the database engine. In PostgreSQL, adding a new column with a default value rewrites the whole table. That can stall large datasets. Using ADD COLUMN ... DEFAULT without NOT NULL avoids that rewrite. MySQL has similar pitfalls—some engines can add columns instantly, others require a full table copy.
Plan migrations in steps. First, add the column as nullable without a default. Then backfill values in small batches. After that, set the default and constraints. This method reduces lock times and avoids downtime. Always verify with EXPLAIN and measure query plans before and after.