Creating a new column in a database table is one of the most common operations in software development, yet it’s where hidden costs often appear. Downtime, locks, inconsistent data states — these problems scale with data size. Knowing how to add a new column without risking service stability is essential.
First, identify the migration type. In relational databases like PostgreSQL and MySQL, adding a nullable column with no default is fast and usually non-blocking. Adding a column with NOT NULL and a default value often rewrites the entire table, which can lock writes for minutes or hours depending on dataset size.
Plan the change. If you need NOT NULL, add the column as nullable first. Backfill the data in small batches to avoid overwhelming the system. Then enforce constraints in a separate migration. This approach keeps the table available while ensuring data integrity.