Adding a new column is one of the simplest schema changes, but it can cause outages, lock tables, or break application code if done without care. The process depends on the database engine, the data type, and whether the operation must run online.
In PostgreSQL, ALTER TABLE table_name ADD COLUMN column_name data_type; works for small tables without issue. For large production datasets, it’s safer to add the column as nullable, then backfill data in batches to avoid locking. MySQL and MariaDB also support ALTER TABLE ADD COLUMN, but old versions may rebuild the table, which can be slow. Using tools like pt-online-schema-change or gh-ost reduces downtime.
When creating a new column, define constraints and defaults only if they do not trigger full table rewrites. In high-traffic systems, adding a default value directly to the schema change can block queries. Instead, add the column without a default, update existing rows asynchronously, then alter it to set a default for future inserts.
Indexes on the new column should be applied after data is backfilled. Building an index during peak traffic can lock critical paths, so schedule it in maintenance windows or use concurrent index creation if supported.