Adding a new column to a database seems simple. It isn’t. Done wrong, it locks tables, stalls writes, and takes your app down. Done right, it ships fast and stays safe. The goal is zero downtime.
Start with the schema. Identify where the new column fits: its type, default value, nullability, and purpose. Every decision here affects query speed and storage. Avoid guessing. Measure.
In PostgreSQL, ALTER TABLE ADD COLUMN is the baseline command. On large datasets, this can block reads and writes if it includes a default value. Instead, add the column as nullable, then backfill in small batches. This keeps traffic flowing while you expand the schema.
For MySQL, online DDL options like ALGORITHM=INPLACE or LOCK=NONE reduce blocking. In distributed databases, check the docs for online schema change support. Use migrations that run in controlled steps—create, backfill, then enforce constraints.