Adding a new column to a database table sounds simple, but the wrong approach can lock writes, trigger downtime, or corrupt data. In production systems with live traffic, speed and safety matter more than elegance.
A new column alters the structure of a table. The database must update its metadata, and in some engines, rewrite entire data files. On small tables, this finishes fast. On billions of rows, a naïve ALTER TABLE ADD COLUMN can block for hours. The fix is not just about syntax. It’s about strategy.
In PostgreSQL, adding a nullable column with a default constant writes that default to every row. Avoid defaults in initial migrations. Add the column without the default, backfill in batches, then apply the default and constraints later. MySQL and MariaDB can avoid table copies in some cases, but it depends on the storage engine and column type. Always check the execution plan before running in production.