Adding a new column is one of the most common database operations, yet it can still cause downtime, break queries, or trigger massive re-indexing if done wrong. Whether you're working with PostgreSQL, MySQL, or a managed cloud database, the rules are simple: know your data types, set defaults carefully, and control execution so your change doesn't block production traffic.
In PostgreSQL, use ALTER TABLE with minimal locking:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE DEFAULT NULL;
Avoid DEFAULT values that force a full table rewrite unless they’re critical. For large datasets, add the column as nullable first, then backfill in small batches. Monitor query plans after the change, because indexes and constraints may shift execution costs.
MySQL’s behavior depends on storage engine and version. Modern InnoDB can add columns instantly in many cases, but older versions require a full table copy. Test in staging with production-like data to verify migration duration.