Adding a new column to a production database is never just one step. It touches schema, code, migrations, indexing, and performance. The wrong approach can lock tables, block writes, or burn CPU. The right approach keeps services live, queries consistent, and downtime at zero.
First, define the new column with precision. Decide on type, constraints, and defaults before writing the migration. Avoid NULL unless necessary. Choose data types that match the data you will store. Overly wide types waste memory and slow reads.
Second, plan the migration strategy. For small tables, a direct ALTER TABLE works. For large or high-traffic tables, use an online schema change tool like gh-ost or pt-online-schema-change. These tools avoid full table locks by creating a shadow table, applying changes, and syncing rows in the background.
Third, backfill safely. Add the new column as nullable, deploy, then backfill in controlled batches to avoid load spikes. Only after the backfill completes should you enforce NOT NULL or add indexes.