Adding a new column is one of the most common schema changes in production systems, but it carries weight. Done wrong, it can lock tables, stall queries, and disrupt deployments. Done right, it improves flexibility without downtime.
When you add a new column, the first step is understanding the write path. Most databases will rewrite the entire table when you alter the schema. This can be expensive on large datasets. Choose migration methods that minimize locking:
- In PostgreSQL, adding a nullable column with a default value set afterward avoids a full table rewrite.
- In MySQL,
ALTER TABLE ... ADD COLUMNcan be instant on certain storage engines but slow with defaults applied inline.
Plan for compatibility. Existing queries and services must handle the new column gracefully. Use feature flags to roll out changes in application code. Make sure your ORM or query layer is aware of the schema update.