Creating a new column is one of the most common operations in any production database, but doing it right means balancing speed, safety, and maintainability. Whether you're working in PostgreSQL, MySQL, or a modern cloud-native database, the fundamentals stay the same: define the column, set its type, handle defaults, and migrate without downtime.
The simplest approach starts with ALTER TABLE. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works in development. In production, you need to think about locks and migration strategy. Adding a new column with a default value can rewrite the whole table. That means possible slow queries, blocked writes, and angry users. Use NULL where possible, backfill in smaller batches, and update defaults after data is in place.
For heavily-loaded systems, online schema changes are essential. Tools like gh-ost (for MySQL) or PostgreSQL’s ADD COLUMN with careful batching can reduce risk. Always measure impact in a staging environment before running in prod, and use monitoring to detect regressions fast.