Adding a new column to a database sounds simple, but it can break production if done without planning. Whether you are working with PostgreSQL, MySQL, or a distributed system like CockroachDB, the principles are the same: change the schema without blocking writes, preserve existing data, keep downtime at zero.
Start with clarity. Define the column name, type, and constraints. Decide if it should allow NULLs or have a default value. Every choice affects locks and migrations. On large datasets, adding a NOT NULL column with no default can lock the table for minutes or hours. Use defaults carefully and backfill in smaller batches where possible.
In PostgreSQL, ALTER TABLE ... ADD COLUMN with a default will rewrite the whole table pre-11, while later versions optimize this to avoid a full rewrite. In MySQL, adding a column might still rewrite pages depending on storage engine and version. For high-traffic systems, skip schema changes in peak load. Use rolling deploys and feature flags to sequence code changes and database migrations.