Adding a new column is one of the most common schema changes in modern databases. Done well, it is simple. Done poorly, it can choke performance, lock writes, or cause production downtime. The decision is never just about adding a field. It’s about the migration path, the query plan, and the storage implications.
In SQL, the basic syntax is clear:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works for small datasets. On a live system with millions of rows, it can be dangerous. Many relational databases rewrite the table on a blocking ALTER TABLE. On PostgreSQL, this can lock the entire table for writes until the operation finishes. MySQL has variations depending on the storage engine, but some operations still require full table copies.
Mitigation strategies matter. For Postgres, you can add a column with a default value only after initial creation to avoid full rewrites. Adding the column as NULL first is fast, then you backfill in batches. MySQL’s ALGORITHM=INPLACE can make certain alterations safer, but you must check each version for exact behavior.
If your system uses an ORM, be aware of how it generates migrations. Many ORMs default to adding constraints immediately, which can trigger heavy locks. Splitting migrations into safe, isolated steps reduces risk: