Adding a new column is simple to describe, but it’s easy to get wrong in production. Schema changes can block queries, break indexes, and lock entire tables if done carelessly. The right approach respects both performance and uptime.
In SQL, a new column begins with an ALTER TABLE statement:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But that syntax is only the start. The impact depends on database engine, size, and concurrency. On PostgreSQL, adding a nullable column without a default is fast—it just updates the metadata. Add a default and the engine might rewrite every row. In MySQL, even adding a nullable column can trigger a full table copy in certain storage engines.
For critical systems, always test the migration on a replica or staging database with production-like data. Measure the schema change time. Watch for locks. Use pt-online-schema-change for MySQL or pgOnlineSchemaChange scripts to avoid downtime. In large Postgres tables, consider adding the column as nullable, then backfilling in batches, then setting the default and constraints.