Adding a new column in a live database is never just a schema change. It’s a shift in the system’s contract. The wrong approach can lock tables, stall queries, and trigger downtime. The right approach keeps services online and data consistent while the schema evolves.
First, define the column with defaults in mind. Avoid non-nullable columns with no default on large tables. This forces a full table rewrite. Instead, create the column as nullable or with a lightweight default. This minimizes immediate load.
Second, backfill in controlled batches. Direct mass updates block writes and risk timeouts. Use incremental updates, scheduled jobs, or background workers to migrate existing records without impacting live traffic.
Third, deploy in multiple steps. Step one: add the new column with safe defaults. Step two: roll out application code that starts writing to it. Step three: verify data correctness before enforcing constraints.