The table is live, the query runs, and now the app needs a new column.
Adding a new column is one of the most common schema changes, yet it can break production if done poorly. The goal is zero downtime and predictable results. Whether in PostgreSQL, MySQL, or a distributed database, the process follows the same principles: plan, apply, verify.
First, decide on the column’s name, data type, and default value. Check for naming collisions. A clear, consistent naming convention reduces errors over time. For numeric or text fields, ensure the type matches the data you expect. For booleans or enums, define constraints upfront to avoid invalid entries.
Next, choose the safest migration method. In PostgreSQL, ALTER TABLE ADD COLUMN is usually non-blocking unless combined with a default value that needs backfilling. To avoid locking large tables, add the column as nullable, then backfill in batches. In MySQL, consider ALGORITHM=INPLACE or online schema change tools like gh-ost or pt-online-schema-change for large datasets. For distributed systems, roll out changes in stages to maintain compatibility.