The database schema is ready, but the product needs more. You need a new column, and you need it fast.
Adding a new column is one of the most common schema changes in software development. It looks simple, but the wrong approach can lock tables, slow queries, or even block deploys. Whether you use PostgreSQL, MySQL, or another SQL database, the fundamentals are the same: plan the migration, execute it safely, and verify the change without downtime.
Plan the schema change
Before adding a new column, check the table size. For large tables, adding a column with a default value can rewrite the entire table. Instead, add the column as nullable, then update values in smaller batches. This prevents long locking operations and keeps service latency stable.
Choose the right migration method
For PostgreSQL, ALTER TABLE ADD COLUMN is generally fast if the column is nullable and without a default. Adding defaults to existing rows should be done in separate update statements. In MySQL, remember that some storage engines handle ALTER TABLE operations by copying the table. Use ALGORITHM=INPLACE when possible to reduce locking.