When working with evolving data models, adding a new column is one of the most common schema changes. It sounds trivial, but the decisions made in this step echo across performance, reliability, and maintainability. A careless alter can block writes, lock tables, or trigger full-table rewrites. A precise alter can go live with zero downtime.
The process starts with defining the purpose of the column. Is it nullable? What is its type? Will it have a default value? In production systems, defaults can be dangerous because they may cause massive updates. For large datasets, consider adding the column without a default, then backfilling in controlled batches. This reduces load and avoids long locks.
In MySQL and PostgreSQL, the syntax is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But under the hood, the database engine may rewrite the table. For a high-traffic service, that can mean blocked transactions. Engineers often use online schema change tools like pt-online-schema-change or gh-ost to migrate columns without locking critical paths. PostgreSQL 11+ can add certain columns with no rewrite if they are nullable and have no default.