Adding a new column is one of the most common, and most dangerous, database operations. Done right, it enables features, fixes critical defects, and keeps development velocity high. Done wrong, it locks migrations, blocks deploys, and corrupts production data.
When creating a new column, begin by defining the exact purpose—type, constraints, default values, and indexing strategy. Avoid null where possible; define defaults explicitly. Write your migration script idempotently so it can run safely across environments. In PostgreSQL, use ALTER TABLE … ADD COLUMN with DEFAULT and NOT NULL only if the table size allows it without locking writes for too long. For large datasets, add the column as nullable first, backfill in batches, then enforce the constraint.
Consider the performance implications. A new column can change query plans, trigger unexpected index rebuilds, and increase row size beyond page limits. Run EXPLAIN on key queries before and after the change. Monitor replication lag during deployment to avoid cascade failures.