Adding a new column is one of the most common operations in database management. It sounds simple, but the wrong approach can cause downtime, lock tables, or corrupt data. Whether you work with PostgreSQL, MySQL, or a modern cloud-native database, understanding how to add a new column safely and efficiently is critical.
A new column changes the shape of your data model. Push it in without planning, and you risk breaking queries, APIs, or ETL pipelines. The operation should be atomic when possible. Always define the data type explicitly. Choose sensible defaults. In large tables, avoid setting a default value that forces a full table rewrite—this can stall production systems.
For PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE;
This runs fast if no default is specified. If a default is needed, set it after creation: