Adding a new column to a database table sounds simple, but the wrong move can lock tables, block writes, or cause downtime. Whether you’re working with PostgreSQL, MySQL, or a distributed datastore, understanding how to add a new column safely is critical.
In PostgreSQL, adding a nullable column without a default is almost instant because it only updates metadata. But setting a default value can rewrite the entire table, which can be expensive. The best practice is to add the column nullable, backfill in batches, then add the default constraint once complete.
For MySQL, the cost of adding a new column depends on the storage engine and version. Modern versions with ALGORITHM=INSTANT can add certain types of columns without a table copy. On older versions, adding a column may require a full table rebuild, so schedule during low-traffic windows or use online schema change tools like gh-ost or pt-online-schema-change.