Adding a new column is one of the most common schema changes. Done wrong, it’s slow, risky, and sometimes dangerous. Done right, it’s clean and predictable. Whether in PostgreSQL, MySQL, or any SQL-compliant database, the process follows the same core principles—plan the change, execute it safely, and confirm integrity.
The simplest case:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works instantly for small datasets. For production-scale datasets, you need to think about locks, defaults, and backfilling. Large tables can lock writes or even block reads while the new column is created. Always test the migration in a staging environment with similar data volume before touching production.
If the new column needs a default value, set it carefully. In PostgreSQL 11 and later, adding a column with a constant default is a fast metadata-only change. In older versions, it rewrites the table—potentially causing long downtime. MySQL has similar behavior, but with version-dependent optimizations.