Adding a new column is one of the most common schema changes in any database. Done right, it’s clean and predictable. Done wrong, it can lock tables, slow queries, or break code in production. The key is planning, testing, and executing with zero downtime.
In SQL, the basic pattern is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works in most engines, from PostgreSQL to MySQL. But production workloads demand more nuance. Large tables may require operations that avoid full table rewrites. PostgreSQL can add nullable columns instantly, but adding defaults can trigger rewrites unless you use versions that support metadata-only changes. MySQL with InnoDB may block writes during schema changes without proper configuration or use of ALGORITHM=INPLACE.
Indexes should be considered early. Adding a new column is often followed by indexing it, but that too can lock or slow the table. Use concurrent index creation where possible. In PostgreSQL, CREATE INDEX CONCURRENTLY avoids table write locks. In MySQL, online DDL can help but may still impact performance.