Adding a new column is one of the most common schema changes in software. It looks simple, but the wrong approach can stall deployments, lock tables, and cause service downtime. The right approach keeps performance stable and data safe, whether you work with PostgreSQL, MySQL, or any modern relational database.
When adding a new column, the first choice is whether it will be nullable. Setting a default value on a large table can cause a full rewrite, creating long locks and blocking reads or writes. Nullable columns avoid this, allowing you to backfill data in smaller, controlled batches. If you need a default, consider creating the column as nullable first, then updating rows in chunks, and finally adding constraints in a separate migration.
Use ALTER TABLE with care. Some database engines permit adding nullable columns instantly, while adding non-null or default values can be expensive. Test the migration in a staging environment with production-like data size. Measure query performance before and after. This is essential for zero-downtime deployments.