Adding a new column in a production database can break uptime, lock writes, or slow queries to a crawl. The right approach depends on your database system, table size, and traffic pattern. For small datasets, a simple ALTER TABLE command with ADD COLUMN works. For high-traffic or massive tables, the process must be staged to avoid downtime.
First, design the schema change. Define the column name, data type, nullability, and default value. Avoid unnecessary defaults on large tables—they trigger a full table rewrite in some systems like MySQL. If you must have a default, consider adding the column as nullable, backfilling data in batches, then altering it to set the default value later.
Second, sequence the schema change. In PostgreSQL, certain ALTER TABLE ADD COLUMN operations are fast because they update metadata without rewriting the table. In MySQL, tools like gh-ost or pt-online-schema-change can create a ghost table, sync changes, and swap it with no downtime. In cloud-managed databases, use built-in online DDL options if available.