Adding a new column is one of the most common schema changes in SQL, yet it’s also one of the easiest to get wrong at scale. Whether your database is PostgreSQL, MySQL, or MariaDB, the wrong approach can lock tables, block writes, or take production down during peak load.
The basics are simple. Use ALTER TABLE with ADD COLUMN to introduce the new field. Specify the column name, data type, and constraints. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE;
This works for small tables. For large datasets, it’s not enough. You need to plan for transactional consistency, index creation, and data backfill without blocking queries.
On high-traffic systems, adding a new column with a default value can be dangerous. In many RDBMS, it rewrites the entire table. Instead, add the column as nullable, deploy, then backfill in small batches before applying defaults or constraints.
If the column will be indexed, create the index concurrently where possible: