In relational databases, adding a new column is a common migration step. It changes the table definition and allows you to store new attributes without breaking existing queries. But doing it wrong can block deployments, cause downtime, or corrupt data.
A new column in SQL is declared with an ALTER TABLE statement. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE;
This executes instantly for metadata-only changes, but can take longer if a default value is set without NULL. Large tables with a non-null default will rewrite the entire table. In production, that can lock writes for minutes or hours. The safe pattern is to:
- Add the column allowing
NULLand no default. - Backfill data in small batches.
- Add constraints or defaults after the data is populated.
If the new column must be unique, use a concurrent index build to avoid locking. In PostgreSQL: