Adding a new column sounds simple, but in production systems it can be dangerous. Table size, index bloat, lock contention, and deployment windows all matter. A careless ALTER TABLE can freeze writes, block reads, or trigger cascading failures. Treat it as a migration, not a quick fix.
First, decide the column type and constraints. Choose data types that minimize storage and parsing cost. Avoid defaults that require a full table rewrite if the dataset is large. In PostgreSQL, adding a nullable column without default is fast; adding one with a constant default rewrites the entire table. Understand your database's execution path before committing to syntax.
Second, plan the migration path. Large tables may require phased rollouts:
- Add the new column as nullable with no default.
- Backfill data in small batches to avoid long transactions.
- Add constraints, indexes, or defaults after the backfill completes.
Third, address indexing strategy. Create indexes only after the column is populated, or risk expensive index churn. Consider partial indexes if the column will be sparse.