Adding a new column in a database sounds simple, but the cost of doing it wrong can be high. Schema changes impact performance, locking, and the stability of production systems. Whether you use PostgreSQL, MySQL, or a modern distributed database, the approach matters.
The safest method to add a new column starts with clear requirements. Know its name, data type, default value, and if it allows NULLs. For example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE;
In PostgreSQL, adding a nullable column without a default is fast because it only updates metadata. Adding a NOT NULL column with a default writes to every row, which can block reads and writes. To avoid downtime, add the column as nullable first, backfill data in batches, then enforce constraints later.
In MySQL, ALTER TABLE historically rebuilds the table. Modern versions support instant DDL for some column types, but not all. Check the execution plan before running commands on production.