The query ran, the cursor blinked, and nothing happened. You needed a new column, but every choice had consequences.
Adding a new column in a production database is never just a schema change. It is a migration that can lock tables, cascade into downtime, and trigger failed deployments. The right approach depends on scale, load, and the patterns in your read and write traffic.
Start by defining the new column in a way that avoids blocking operations. In PostgreSQL, adding a nullable column with no default is instant. In MySQL, the process can be more costly depending on storage engine and version. Always measure the impact on your largest table in a staging or shadow environment.
Backfill strategies matter. For small datasets, a single transaction works. For large datasets, backfill in batches, commit often, and monitor replication lag. Avoid locking patterns by using UPDATE ... WHERE id BETWEEN ... with limits that keep query time short. This prevents timeouts and keeps downstream services responsive.