Adding a new column is one of the most common schema changes in databases, yet it’s also one of the most disruptive if done poorly. Whether you’re working with PostgreSQL, MySQL, or a distributed store, the wrong approach can lock tables, slow queries, and cause downtime. The right approach keeps your system online and your data consistent.
A new column can be used to store calculated values, track new business requirements, or prepare for a feature launch. In relational databases, the first step is to alter the schema. For example, in PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
While this looks simple, execution strategy matters. For large tables in production:
- Use
ADD COLUMNwith a default value carefully; it may rewrite the table. - For PostgreSQL, using
NULLby default avoids immediate rewrites. - Apply backfills in small batches to protect performance.
- In MySQL, use
ALGORITHM=INPLACEorONLINEwhen supported.
Schema migrations for a new column should be part of a deployment plan: