Adding a new column in a production database is never just one step. Schema changes touch every layer of the stack. You need to choose the right data type, define constraints, and decide on defaults. If the database is large, adding the column can lock tables and disrupt queries. Even a small change can cascade into downtime, broken migrations, or missed indexes.
In PostgreSQL, you can add a new column with:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE;
For big datasets, run the change in off-peak hours or use tools like pg_repack or gh-ost for minimal locking. Always back up before making the change. If the column requires computed or derived values, consider adding it nullable first, then backfilling in batches to avoid long locks.
In MySQL or MariaDB, syntax is similar:
ALTER TABLE users ADD COLUMN last_login DATETIME;
On large tables, use ALGORITHM=INPLACE when possible to reduce lock time.