The query ran. The table stared back. But the data you need isn’t there. You have to add a new column.
Creating a new column isn’t just a schema change. It’s an operation that can lock tables, disrupt queries, and impact performance if done wrong. The right approach depends on your database engine, the size of your data, and how critical uptime is.
In PostgreSQL, adding a new column with a default value can rewrite the entire table. On large datasets, that means long locks. You can avoid this by first adding the column as NULL, then updating rows in batches, and finally setting the default. In MySQL, adding a column may require a full table copy unless you use an online DDL operation. With tools like gh-ost or pt-online-schema-change, you can keep the table responsive during the migration.
When designing for change, think about the column type. Will it store integers, text, or JSON? Pick the minimal type needed to reduce storage costs and increase query speed. Also consider indexing. Adding an index on the new column will speed lookups but can slow writes. Only index after the column is populated and examined for query patterns.