When adding a new column to a production database, speed and correctness are everything. Schema migrations can slow queries, lock tables, and block writes if not executed with care. The safest path is to plan for atomic changes. For most relational databases—PostgreSQL, MySQL, MariaDB—adding a nullable column without a default is near-instant. Adding a column with a default value can rewrite the entire table and should be handled with a safer, staged approach.
Best practice is to:
- Add the new column without default or constraint.
- Backfill data in small, controlled batches.
- Add default values and constraints only after the data is in place.
This sequence avoids long table locks and keeps the application responsive. Monitor CPU, IO, and query plans during the migration process. Test every step in staging with realistic datasets before running in production.