Adding a new column to a live database is simple in syntax but carries real risk. Done wrong, it can lock writes, slow queries, or even bring down your service. The process is not just ALTER TABLE; it’s about choosing the right approach for the scale and performance profile of your system.
In PostgreSQL, running ALTER TABLE my_table ADD COLUMN new_column data_type; is instant if the column allows nulls and has no default. But adding a column with a default value rewrites the entire table and can block queries for minutes or hours. MySQL behaves differently. Online schema changes through tools like pt-online-schema-change or native ALGORITHM=INPLACE can help avoid locking.
Plan for indexes. Adding indexes as part of a new column migration should be staged. First, deploy the column. Then backfill data in small batches. Only after that, create the index, ideally using an online index creation option where supported.