Adding a new column is one of the most common schema changes in any database. Done well, it’s fast, safe, and invisible to the user. Done poorly, it can lock up tables, block queries, or break production. The difference is in the technique.
Before you add a column, verify the database engine and version. In PostgreSQL and MySQL, ALTER TABLE ADD COLUMN is the direct command. On large datasets, this can be an expensive operation unless the engine supports instant DDL. PostgreSQL versions after 11 can add null columns with no table rewrite. MySQL’s InnoDB storage engine supports instant add for certain types and defaults.
Always define the column with a clear data type and default. For example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
If the default requires a computation or backfill, run it in a separate step. This prevents long locks during the schema migration. For large tables in production, use online schema migration tools like pg_copy, pt-online-schema-change, or native ALTER TABLE ... ALGORITHM=INPLACE where supported.