The schema was locked, but the product team wanted more. A new column had to be added.
Adding a new column in a production database is simple to describe but complex to execute without downtime or broken data. The operation touches schema design, data migration, indexing, and query performance. Poor execution can slow an application or even cause outages.
First, decide if the column is nullable or has a default value. Nullable columns deploy faster because they avoid large rewrites on existing rows. Non-null columns with defaults can trigger a full-table rewrite, which on large datasets can block queries. For mission-critical systems, run the change in phases:
- Add the column as nullable.
- Backfill data in controlled batches.
- Apply constraints and defaults after the backfill completes.
Indexing needs equal care. Creating an index immediately after adding a column can lock the table for long periods. Build indexes concurrently where supported, or split into multiple steps to minimize locking.