Adding a new column sounds simple. It isn’t. In production, schema changes carry risk. A poorly planned ALTER TABLE can lock rows, block writes, and stall your entire system. The key is to design and execute a schema migration that avoids downtime and data loss.
Start with the migration plan. Decide whether the new column will be nullable, have a default, or require backfilled data. For large tables, avoid backfilling in a single transaction. Instead, add the column first, then backfill in batches. This reduces lock times and minimizes replication lag.
Choosing the right data type for your new column matters. Use the smallest type that fits current and future requirements. Over-allocating wastes space and can slow queries. Under-allocating forces another migration later — always harder once the table grows.
If you run on PostgreSQL, adding a nullable new column without a default is fast. With MySQL, adding even a nullable column may trigger a full table rewrite depending on the engine and version. Understand your database’s behavior before you run the command.