Adding a new column should be simple, but production databases demand precision. Schema changes risk downtime, data loss, or broken queries. When you add a new column, you must consider the effect on indexes, default values, nullability, and query performance.
Start with the ALTER TABLE statement. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This runs instantly on small tables, but large tables can lock writes. Use tools like pg_repack, pt-online-schema-change, or zero-downtime migrations. Test in staging with the same data scale to understand lock times and replication lag.
If the new column requires a default, decide between setting it in the migration or applying it in batches. A large defaulted column can trigger a full table rewrite. For frequent inserts or updates, consider adding the column as nullable first, then updating in chunks.