Adding a new column to a database table is simple in syntax but dangerous in practice. The wrong approach can lock tables, slow queries, or break code in production. The right approach ensures data integrity, zero downtime, and compatibility with existing logic.
When adding a new column, start by defining its exact purpose and constraints. Decide whether it allows NULLs. If you need a default value, know that large default writes can cause table rewrites in some engines. In PostgreSQL, adding a nullable column without a default is instant. Adding one with a default is not—unless you use the DEFAULT with a constant and NOT NULL after backfilling.
Always audit the ORM models, queries, and APIs that touch the table. If the application layer reads SELECT *, a schema change can break assumptions about column ordering. If you need immediate reads from the new column, deploy code that can handle both its absence and presence to support rolling migrations.
On high-traffic systems, use a phased rollout.