Adding a new column to a production database schema is simple in syntax but hard in impact. It changes queries, migrations, application code, and often the assumptions of surrounding systems. Done without care, it can lock tables, spike CPU, or block writes. Done right, it’s seamless.
First, decide the column type and default value. Every decision here affects future query performance and storage. Avoid broad types like TEXT when you can use VARCHAR(n) or a precise numeric type. Choose NOT NULL or NULL deliberately.
Next, plan the migration for minimal impact. In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for nullable columns without defaults. Defaults on large tables can lock the table, so consider adding the column as nullable first, then backfilling data in batches, and finally adding constraints.
In MySQL, older versions can lock tables on ALTER TABLE, but ALGORITHM=INPLACE or ALGORITHM=INSTANT in recent versions make adding a new column faster. Always confirm the availability of these options before running migrations.