Adding a new column to a production database is simple in theory but carries risk in practice. Schema changes can lock tables, block writes, and trigger cascading failures. The goal is to add the column without downtime, data loss, or degraded performance.
First, verify the exact requirements. Define the column name, data type, nullability, default values, and indexing strategy. Consider the downstream impact on queries, stored procedures, and ORM mappings. Adding a NOT NULL column with a default value can rewrite an entire table in some databases; plan this with care.
Next, select the migration approach. Online schema change tools like pt-online-schema-change or gh-ost allow adding a new column with minimal locking. In PostgreSQL, certain ALTER TABLE operations are fast for metadata-only changes, but others rewrite the table — choose the statement that avoids full rewrites when possible.
Deploy the change in three stages when feasible: