A schema change is simple in theory, but the reality is databases in high-traffic environments leave little room for mistakes. A poorly planned ALTER TABLE can lock rows, slow queries, or block writes. The right approach to adding a new column keeps your application online, your data safe, and your deployment pipeline moving.
Before you run a migration, define the column precisely. Choose the correct data type, default values, and constraints. Adding a nullable column is often safer than adding one with a default that rewrites millions of rows. If the new column is large, consider whether it belongs in this table or if you should decouple it into another table.
In PostgreSQL, ALTER TABLE … ADD COLUMN is fast for nullable columns without defaults. If a default is needed, add the column as nullable, backfill the data in batches, then set the default and constraint later. This pattern avoids long locks and keeps queries responsive.
For MySQL, be aware that older versions copy the entire table during an ALTER TABLE. Use tools like gh-ost or pt-online-schema-change to perform online migrations. Always test on a staging database with production-scale data to measure migration time and impact.