Adding a new column should be fast, predictable, and safe. Whether in PostgreSQL, MySQL, or a cloud-native data warehouse, schema changes can block queries, slow deployments, and risk downtime if handled without care. A well-planned migration keeps systems responsive while evolving to meet new requirements.
In PostgreSQL, use ALTER TABLE with ADD COLUMN for a straightforward change:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
Avoid adding columns with heavy defaults in one step. Large datasets can lock for seconds or minutes. Instead, add the column NULL, backfill in batches, then set constraints or defaults.
MySQL’s ALTER TABLE behaves differently in certain storage engines. For InnoDB, most new columns with no default can be added online. But for columns with calculated defaults or large indexes, online DDL options (ALGORITHM=INPLACE) prevent full table rebuilds.