When you add a new column to a production database, you join a live system in motion. Every query, every transaction, every lock matters. A careless ALTER TABLE can stall a queue, block writes, and bring user sessions to a halt. The right approach starts with precision.
First, define the new column in your migration with explicit type and constraints. Avoid implicit defaults unless you control every query path. For large tables, use phased rollouts:
- Add the column as nullable.
- Backfill with batched updates to avoid locking.
- Add
NOT NULLor other constraints after data is in place.
Monitor query plans after deployment. Even unused columns can change index size and I/O patterns. Vacuum, analyze, or rebuild indexes where needed. If your ORM handles migrations, review the generated SQL before shipping. Trust, but verify.