Adding a new column is one of the most common schema changes in modern software projects. It sounds simple, yet in production systems it can trigger downtime, lock tables, slow queries, or break dependencies. A misstep here can cost real money.
A new column can be used to store derived values, capture new business requirements, track timestamps, or mark feature flags. In relational databases like PostgreSQL, MySQL, and MariaDB, the syntax is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But the execution is rarely trivial. Consider the table size, indexes, default values, and access patterns. For large datasets, adding a new column with a default non-null value can rewrite the entire table and block writes during the operation. In PostgreSQL, using ADD COLUMN ... DEFAULT can be costly unless you use DEFAULT NULL and backfill separately.
If your service cannot afford downtime, online schema migration tools like pt-online-schema-change or gh-ost can help. They create a shadow table with the new column, copy data in chunks, then swap in the new version with minimal lock time. For cloud-managed databases, check if your provider supports instant DDL for column additions.