Adding a new column in a production table can be fast or fatal. Speed without safety means downtime, data loss, or broken queries. The right approach depends on schema size, workload, and uptime requirements.
In relational databases like PostgreSQL, MySQL, or SQL Server, a new column definition sounds simple:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This command works for small tables. On large datasets, it may lock rows and block writes. That’s why online schema changes exist. Tools like pg_online_schema_change for Postgres or gh-ost for MySQL add a column without long locks, streaming changes while the service stays available.
A new column should have the correct default and nullability. Adding a non-null column with a default in PostgreSQL rewrites the table in older versions, but in Postgres 11+ it’s metadata-only if no rows are touched. MySQL still copies the table in most cases. For SQL Server, ALTER TABLE with default constraints is often metadata-only, but large indexes still need monitoring.