Adding a new column sounds simple. It can break production if you get it wrong. Whether you’re changing PostgreSQL, MySQL, or any other SQL database, the approach matters. You need to decide if the column is nullable, if it has a default, and whether you can add it without locking the table. For high-traffic applications, a blocking schema change can stall writes, drop connections, or trigger a full outage.
In PostgreSQL, ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE; will add the column instantly if it’s nullable and without a default. If you add a default, the database rewrites every row, which can be slow on large tables. To avoid downtime, add the column as nullable, backfill in batches, then set the default in a follow-up migration.
MySQL requires similar caution. ALTER TABLE users ADD COLUMN last_login DATETIME NULL; works fast on small datasets but can lock the table on large ones unless you use online DDL (e.g., with ALGORITHM=INPLACE or pt-online-schema-change).