Adding a new column is one of the most common schema changes in production systems. Yet it’s also one of the most dangerous if done without care. When databases grow beyond millions of rows, a single ALTER TABLE can lock queries, block writes, and cascade failure across dependent services. The right approach depends on the database, workload, and uptime requirements.
First, assess the data type. Choose the smallest type that meets requirements to reduce storage and memory footprint. For example, INT vs. BIGINT can save space and improve cache performance. Define nullability and default values carefully — a non-null column with a default will backfill every row, which can be expensive.
Second, plan the migration path. In PostgreSQL, adding a nullable column without a default is fast. Adding with a default rewrites the whole table. MySQL behaves differently, with online DDL options depending on the storage engine. Check indexes: sometimes the temptation is to add them with the new column, but this doubles the migration cost. Staging indexes separately can reduce lock time.