Adding a new column seems simple. It is not. In production, the wrong approach can lock tables, drop queries, or block deploys. The key is knowing how to add a column without downtime, data loss, or broken APIs.
Start by defining the new column in a way that does not force a full table rewrite. In PostgreSQL, adding a nullable column with a default set to NULL is instant. In MySQL, versions after 8.0 handle most ALTER TABLE operations online, but older versions need extra care. Avoid setting a default and NOT NULL at the same time on large tables — this triggers a table copy.
Backfill data in batches. Write a script that updates small ranges at a time and commits quickly. This keeps locks minimal and avoids blocking reads and writes. Use application-level feature flags to make new code paths read from the new column only after the backfill finishes.
Always add indexes after the data is in place. Index creation can be slow, and concurrent indexing options vary between databases. Monitor performance metrics in real time during the change. Have a rollback plan that drops the new column if needed.