The query finished running, but the table was still wrong. You needed a new column, and you needed it without breaking production.
A new column in a database is simple to describe, but the wrong implementation can stall releases, corrupt data, or lock tables at scale. Whether you use PostgreSQL, MySQL, or a distributed store, adding a column is about control of downtime, default values, migration scripts, and schema management tools.
Start by defining the exact purpose and type. Avoid generic names. Use consistent naming conventions so the schema remains self-documenting. For large tables, perform the change in steps:
- Add the new column without defaults or constraints.
- Backfill values in small batches to avoid long locks.
- Add indexes and constraints only after data is fully populated.
In PostgreSQL, ALTER TABLE ADD COLUMN is straightforward but may rewrite the table if a default is included. In MySQL, adding a column can be blocking unless you use tools like pt-online-schema-change or native ALGORITHM=INPLACE. In distributed SQL, ensure schema changes are serializable and coordinated across nodes.