Adding a new column sounds simple. In production, under load, it is not. Done wrong, it locks tables, drops performance, or even takes your app offline. Done right, it’s invisible to users and safe for critical data.
The first step is to define exactly where the new column belongs. This is not a guess. Use the schema to check indexes and constraints. Decide if the column should be nullable, have a default value, or use a generated value. Choosing incorrectly will slow write throughput or break existing queries.
Next, plan the deployment strategy. For large tables, online schema change tools like gh-ost or pt-online-schema-change reduce lock time. In PostgreSQL, use ADD COLUMN with defaults carefully: a non-null column with a default will rewrite the entire table unless you set the default after creation.
Run your migration in a safe environment first. Check query plans before and after. Watch the effect on indexes and storage. Monitor metrics as you roll out. Schema migrations are not pure code changes; they interact with terabytes of live data.