Adding a new column sounds simple. In practice, it can be the step that breaks your deployment or corrupts production data. The wrong approach locks tables, stalls queries, and creates downtime. The right approach is fast, safe, and repeatable.
A new column changes the schema. Before adding it, confirm constraints, indexes, and nullability. Decide if the column will have a default value. Defaults on large tables can rewrite the entire dataset, so avoid them unless necessary. Add the column first, then backfill data in controlled batches. This reduces locking and keeps the system responsive.
For production systems, run the change behind feature flags. Deploy the code that writes to the new column only after the schema is live. This two-stage rollout avoids race conditions between old code and the altered schema.
When using ALTER TABLE, know your database engine’s behavior. PostgreSQL can add a new nullable column instantly. MySQL may require more care depending on the storage engine. For large datasets, consider online schema change tools like pt-online-schema-change or gh-ost.