The database groaned as another request hit the API. The query was fast, but the schema was not ready. You needed a new column.
Adding a new column sounds simple until you consider live traffic, large datasets, and zero downtime requirements. Schema changes in production can lock tables, slow queries, or block writes. Without the right approach, a single “ALTER TABLE” can impact core business systems.
The first step is choosing the right migration strategy. For smaller tables, a direct ALTER with minimal locks can work. For high-volume or mission-critical databases, use an online schema change tool like gh-ost or pt-online-schema-change. These tools copy the data into a shadow table, keep it in sync, and swap it in—avoiding long locks.
Always define the exact column type in advance. For example, avoid generic VARCHAR without size limits. Choose defaults carefully to prevent null-related bugs. When adding NOT NULL columns, backfill the data first. In PostgreSQL, you can add a column with a default value without rewriting the entire table when the default is a constant.