The database was choking. A query that should have been instant dragged for seconds. The fix was simple: add a new column.
Adding a new column is a common database operation, but it carries real consequences for performance, schema design, and application logic. In relational databases like PostgreSQL, MySQL, and MariaDB, an ALTER TABLE statement is the standard method. You define the column name, data type, and constraints. With large production tables, this can lock writes, trigger a full table rewrite, or cause replication lag.
For PostgreSQL, adding a new column with a NULL default is usually fast because no data rewrite occurs. Setting a DEFAULT value can be slower, as the database must populate existing rows. Use ALTER TABLE my_table ADD COLUMN new_column_name data_type; for minimal impact. For MySQL with InnoDB, online DDL can avoid downtime, but not in all versions. Always test on staging with production-scale data before applying changes.
Design decisions matter before you add a new column. Will the column accept NULL values? Will it require indexing? Adding an index immediately after creating the column can compound migration time. If the column will be a foreign key, ensure referenced tables are indexed to keep join performance tight.