Adding a new column to a production database should be simple. In reality, it can cause downtime, lock tables, or corrupt data if done carelessly. Schema changes run at the heart of an application’s data layer, so precision is the only safe approach.
First, define the new column with explicit data types and constraints. Avoid defaults unless required. Implicit defaults can trigger full-table writes on creation, impacting performance.
When possible, use ALTER TABLE in a transaction. For large tables, consider an online schema change tool like gh-ost or pt-online-schema-change. These create a shadow table, sync changes, and swap it in without blocking reads or writes.
For nullable columns, add them first without indexes. Populate them in controlled batches to avoid locking long-running queries. Once data is consistent, add indexes or constraints. Each structural change should be isolated to make rollback faster.