The migration halted. Every eye on the query log caught the same line: ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
Adding a new column seems simple, but at scale it can break deployments, lock tables, and cause downtime that eats into SLAs. The right approach to creating a new column in a live database depends on the engine, the table size, and the traffic patterns. Ignore those details and you risk slowing every request that touches the table.
Modern relational databases like PostgreSQL, MySQL, and MariaDB handle ADD COLUMN differently. PostgreSQL can add a column with a default of NULL instantly, but adding a default value or a NOT NULL constraint may rewrite the table. MySQL before 8.0 used a blocking DDL for most changes, while newer versions support ALGORITHM=INPLACE to reduce locks. Understanding these specifics lets you design migrations that complete in seconds, not hours.
For large tables, online schema change tools are essential. gh-ost and pt-online-schema-change in MySQL clone the table in the background, keep it in sync, then swap it in without blocking writes. In PostgreSQL, strategic use of ADD COLUMN, followed by UPDATE in batches and a final ALTER TABLE to set constraints, avoids long locks.