Adding a new column sounds simple. It isn’t. Done wrong, it can lock tables, degrade performance, or even take an application offline. Done right, it keeps your schema flexible and your system humming.
A new column changes the shape of your data. In SQL, ALTER TABLE is the command you reach for. In PostgreSQL, ALTER TABLE my_table ADD COLUMN new_column data_type; is common. In MySQL, it’s similar: ALTER TABLE my_table ADD new_column data_type;. The key is to understand what happens under the hood.
On large tables, this operation can be expensive. Some databases rewrite the entire table when adding a column with a default value. To avoid downtime, add the column as nullable without a default. Then backfill the data in small batches before adding constraints. With PostgreSQL, you can use ADD COLUMN ... DEFAULT ... without a full rewrite if you’re on version 11+. Know your version.
In production environments, you must manage locks. PostgreSQL holds an ACCESS EXCLUSIVE lock for schema changes. That means no reads or writes while the command runs. For massive datasets, that’s a problem. Use tools like pg_repack or online schema migration frameworks like gh-ost or pt-online-schema-change for MySQL to avoid blocking.