Adding a new column is one of the most common tasks in database management, but doing it right matters. A careless schema change can block queries, lock rows, or break production. The correct approach depends on your database engine, the size of your dataset, and the level of uptime you demand.
In PostgreSQL, the simplest way to add a new column is with:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This is instantaneous if the column is nullable and has no default value. The moment you add a default or a NOT NULL constraint, the operation may rewrite the entire table. On large tables, that can cause hours of downtime. Version 11+ offers ALTER TABLE ... ADD COLUMN ... DEFAULT ... with metadata-only changes for certain cases, but you need to confirm behavior in staging.
In MySQL, ALTER TABLE always rebuilds the table unless the storage engine supports instant DDL. With InnoDB in MySQL 8.0+, adding a nullable column without a default is instant. Anything more will trigger a table copy. Online schema change tools like gh-ost or pt-online-schema-change can help, but they add complexity.