Adding a new column in production is never just one command. It’s about performance, downtime risk, and schema compatibility. The right approach depends on your database engine, indexing strategy, and migration process. In PostgreSQL, a new column with a default value can lock the table. In MySQL, adding a column to a large table may trigger full table rewrites. Without careful planning, you can block writes, slow reads, or even crash critical services.
The first step is defining the column in a way that reduces risk. For large tables, add the new column as nullable, then backfill in batches. Once the data is populated, set constraints or defaults in a separate step. This approach avoids long locks and keeps your application responsive.
Next, ensure application code is column-aware before deployment. Use feature flags to control when new logic interacts with the column. Deploy in two phases: first schema, then code. This makes rollbacks safe and predictable.