Adding a new column is simple in theory, dangerous in production, and essential for evolving a database over time. Whether you are working in PostgreSQL, MySQL, or modern cloud databases, the fundamental process is the same: alter the table definition, set defaults if needed, and ensure the change does not stall queries or lock critical writes.
In SQL, the command is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
On smaller tables, this runs instantly. On large, high-traffic tables, the same statement can cause downtime or slow requests. To minimize impact, use transactional DDL when supported, or apply zero-downtime techniques like adding the column without a default, then backfilling in batches.
Consider constraints and indexes. Adding a NOT NULL constraint with a default can rewrite the entire table, so split it into two operations. First, add the nullable column. Second, backfill data. Finally, apply the NOT NULL constraint once all rows are updated. This staged approach reduces lock contention and avoids blocking queries.