Adding a new column to a database table is one of the most common schema changes, yet it is where downtime, performance hits, and production incidents often creep in. Done right, it is invisible. Done wrong, it blocks queries, locks rows, and tangles migrations.
Plan the change before you write the migration script. Identify the column type, nullability, default values, and indexing needs. For large tables, avoid adding a NOT NULL column with a default in a single step. This can lock the table and rewrite the entire dataset. Instead, add the column as nullable, backfill in controlled batches, then enforce constraints in a second migration.
If you are working in PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for nullable columns without defaults. Defaults on new columns are stored in metadata in newer PostgreSQL versions, making the addition immediate. But adding indexes or constraints after will still require a full table scan. MySQL and MariaDB behave differently; adding a column can be an online or offline operation depending on the storage engine and server settings.