The fix was simple: add a new column without breaking production.
Creating a new column in a database should be straightforward, but in live systems, precision matters. A careless schema change can lock tables, slow queries, or cause downtime. The best approach is to plan the new column’s type, default values, indexing, and compatibility before execution.
In relational databases like PostgreSQL or MySQL, adding a new column is usually handled with an ALTER TABLE command. For example:
ALTER TABLE orders ADD COLUMN status VARCHAR(20) DEFAULT 'pending';
This works well on small tables. On large ones, it can cause a table rewrite. That means higher CPU use, increased I/O, and latency spikes for active queries.
To avoid this, use database-specific features for online schema changes. PostgreSQL’s ADD COLUMN without a NOT NULL constraint and without heavy default values is fast. MySQL can leverage ALGORITHM=INPLACE or tools like pt-online-schema-change to avoid locking the entire table. Always test on a parallel environment before touching production.