Adding a new column sounds simple. In production, it can be dangerous. Schema changes can lock tables, slow down queries, or take down services if done without planning. Understanding how to add a new column safely is essential.
First, know your database engine. In PostgreSQL, ALTER TABLE ADD COLUMN is straightforward for nullable fields without defaults. Non-null with a default triggers a full table rewrite unless you use Postgres 11+ with a constant default, which avoids a rewrite. MySQL handles ADD COLUMN operations differently depending on the storage engine and version. Some operations are instant, others require a table copy.
Second, plan the migration. Long-running locks will block reads or writes. For high-traffic systems, break the change into smaller steps. Add the new column as nullable. Backfill data in batches. When complete, set constraints in a separate migration.
Third, align code changes with schema changes. Deploy the schema update before writing to the new column. Read paths should handle both old and new states. Rollouts without backward compatibility are brittle.