Adding a new column should be simple. But in production systems with live traffic, zero downtime matters. Schema changes that lock tables, block writes, or cause replication lag can lead to outages. Doing it right means understanding how your database engine handles structure changes under load.
In SQL, ALTER TABLE is the core tool. On small tables, it runs in seconds. On large tables, it can trigger a full table rewrite, holding locks until complete. For PostgreSQL, adding a nullable column with a default in one step rewrites the table; splitting the operation into two steps (add column, then set default) avoids that rewrite. MySQL’s behavior depends on the storage engine and version—InnoDB supports instant column additions in recent releases, but older setups require online schema change tools.
Before adding a new column, measure table size, active connections, and query patterns. Use EXPLAIN and pg_stat_activity (PostgreSQL) or SHOW PROCESSLIST (MySQL) to identify potential bottlenecks. Schedule schema changes during low-traffic windows, or ensure your change process is fully online. This may mean using tools like gh-ost, pt-online-schema-change, or built-in online DDL.