When you create a new column in a database, speed and safety matter. The wrong command can lock tables, delay queries, or corrupt data. The right approach keeps systems responsive while schema changes roll out. Whether using PostgreSQL, MySQL, or a cloud-managed database, you need to understand how each engine handles ALTER TABLE operations.
In PostgreSQL, adding a nullable column with no default is fast because it updates metadata only. Setting a default value or adding NOT NULL requires rewriting rows, which can block writes. For high-traffic systems, use a two-step migration: first add the column as nullable, then backfill in small batches, and finally apply constraints.
MySQL behaves differently. Adding a column often rebuilds the table unless you use algorithms like INSTANT or INPLACE, available in newer versions. Always check your engine’s documentation and test in a staging environment before applying the operation in production.
For distributed databases like CockroachDB, a new column change propagates across nodes. Schema changes happen asynchronously, but you must still watch for performance drops during propagation.