The migration hit production at 02:14. Everyone was watching. The change was simple: add a new column. But in databases, small edits can explode.
A new column sounds harmless. In SQL, it can mean structural change, locking tables, breaking queries, or altering indexes. Knowing how to add a new column without downtime is essential. The right method depends on database type, size, and workload.
In PostgreSQL, adding a nullable column without a default is fast. The schema updates instantly. Adding a column with a default value will rewrite the table. That can lock writes and block reads. To avoid this, add the column first, then update rows in batches. Finally, set your default and constraints.
In MySQL, adding a column can trigger a table copy. On large datasets, that means hours of downtime unless you use ALGORITHM=INPLACE where possible. For bigger changes, tools like pt-online-schema-change or gh-ost let you add a column without locking the primary table, swapping it in when ready.