The dataset stared back, incomplete but bursting with potential. One thing was missing—a new column.
Adding a new column is one of the most common schema changes in relational databases. It looks simple. It is not. A poorly executed ALTER TABLE can lock writes, spike latency, and slow production to a crawl. The right method depends on your database engine, your table size, and your uptime requirements.
In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for metadata-only changes, especially when you set a default to NULL. But adding a column with a non-null default forces a table rewrite. For massive datasets, that’s downtime. To avoid it, add the column as nullable, backfill data in controlled batches, then set constraints after the fact.
In MySQL, adding a new column can still lock the table unless you use ALGORITHM=INPLACE for supported cases. With large tables, tools like pt-online-schema-change can copy data into a shadow table and swap atomically, avoiding locks on production traffic.