The table was breaking. Queries slowed to a crawl. You scanned the schema and knew the fix: a new column.
Adding a new column sounds simple. In production, it can be risky. A poorly planned schema change can lock tables, block writes, or trigger downtime. The right approach depends on your database engine, data volume, and uptime requirements.
In relational databases like PostgreSQL or MySQL, ALTER TABLE ADD COLUMN is the common command. For small tables, it’s fast. For large datasets, it can be destructive if executed without care. Locks may block concurrent operations. This is why adding a column in production demands a plan.
Use an online schema migration tool when zero downtime matters. Tools such as pt-online-schema-change or gh-ost create a shadow table, copy the data, add the column, then swap tables. This lets you add a new column while the database stays online.
When defining the new column, choose default values wisely. In some engines, setting a non-null default can rewrite the entire table, causing performance hits. Often it’s safer to add the column as nullable, then update rows in batches before enforcing constraints.