Adding a new column to a database sounds simple, but it can disrupt production if done without planning. Schema changes can lock tables, block writes, and slow reads. Downtime is costly. Even a fast ALTER TABLE ADD COLUMN can cascade into performance issues on busy systems.
The first decision is where and how to add it. In relational databases like PostgreSQL or MySQL, the syntax is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But the impact depends on factors like data size, indexes, and default values. Adding a column with a default that’s not NULL can rewrite every row, locking the table for the duration. On billions of rows, that’s a disaster.
Online schema change tools like gh-ost or pt-online-schema-change can make this safer by copying the table in the background and swapping it in. In cloud databases, managed migrations can reduce lock time. In NoSQL systems, adding a new field is often schema-less, but the application code must handle both old and new document shapes during the transition.