Adding a new column to a table is one of the most common schema changes in any production system. Done right, it’s a simple migration. Done wrong, it can lock tables, block writes, break queries, or bring down critical services. The difference is in execution.
In SQL, the syntax is clear:
ALTER TABLE orders ADD COLUMN shipped_at TIMESTAMP;
This runs instantly in small tables. On large tables with millions or billions of rows, the approach changes. PostgreSQL will take an ACCESS EXCLUSIVE lock during the operation. MySQL before version 8 often requires a table copy. For production systems, these locks can be deadly. Plan for them.
Mitigation strategies include adding the column with a nullable default, running schema changes during low-traffic windows, or using an online schema migration tool such as pt-online-schema-change or gh-ost. In PostgreSQL 11+, adding a column with a constant default can be done without rewriting the entire table. In cloud databases, read docs carefully—behavior varies and some managed services offer non-blocking operations for adding new columns.