Adding a new column is one of the most common schema changes. It sounds simple, but in production, the wrong approach can lock tables, block writes, or trigger downtime. The right approach depends on your database engine, table size, and concurrency requirements.
In PostgreSQL, ALTER TABLE ADD COLUMN is fast when adding a nullable column without a default. The command updates only the system catalog and doesn’t rewrite the full table. But adding a column with a default value forces a table rewrite, which can lock the table for the entire duration. For high-traffic systems, this can be unacceptable. Instead, add the column without a default, backfill in small batches, and then set the default at the end.
In MySQL, behavior differs by engine. InnoDB can perform many ADD COLUMN operations online, but not all. Check if your version supports ALGORITHM=INPLACE and LOCK=NONE to avoid major disruptions. If unsupported, consider creating a shadow table with the new column, backfilling data, and switching over via rename—minimizing downtime to seconds.