Adding a new column sounds simple. In production, it can trigger locks, block writes, and slow reads. On large datasets, it can cascade into downtime. This is common on relational databases like PostgreSQL, MySQL, and MariaDB. Without care, ALTER TABLE ADD COLUMN can become a silent outage.
To avoid this, start with a safe migration strategy. In PostgreSQL, adding a nullable column without a default is usually fast. Adding a column with a default value, however, rewrites the table. This rewrite can lock the table for minutes or hours. Split the migration into steps:
- Add the new column as nullable without a default.
- Backfill data in small batches.
- Add the default value and constraints after the backfill completes.
In MySQL, even adding a nullable column can be slow on large tables unless you run it online. Use pt-online-schema-change or the native ALGORITHM=INPLACE when possible. Always verify the execution plan before running migrations in production.