Adding a new column is common, but doing it wrong can take a service down. It’s not just ALTER TABLE. On large datasets, schema changes can lock tables, block writes, or trigger unexpected replication lag. The right approach depends on the database engine, the size of the table, and the uptime requirements.
In PostgreSQL, ALTER TABLE ADD COLUMN is fast for empty columns without defaults, because it updates only the schema metadata. But adding a NOT NULL column with a default can rewrite the entire table. This can take minutes—or hours. Use ADD COLUMN ... DEFAULT after setting the column as nullable, then UPDATE in batches, and finally ALTER TABLE ... SET NOT NULL once the data is in place.
MySQL and MariaDB behave differently. For tables using InnoDB, some column additions require a table copy, which can lock writes. For high-traffic systems, use pt-online-schema-change or gh-ost to add new columns without downtime. These tools create a shadow table, sync data online, and swap schema changes in a controlled cutover.
In distributed SQL databases, schema changes propagate across nodes. Latency in schema gossip can cause query errors if code is deployed before all nodes recognize the new column. Always stage schema updates ahead of code changes and monitor cluster health during the rollout.