Adding a new column to a database table should be simple. In production, it is not. The wrong approach locks tables. It triggers downtime. It delays deploys and stalls releases. The right approach is precise, online, and safe.
First, define the purpose of the new column. Keep its type and nullability clear. Choose defaults that won’t rewrite millions of rows at once. This prevents full-table scans that crush performance.
Second, use an online schema change process. In MySQL, tools like pt-online-schema-change or gh-ost copy data into a shadow table while replaying changes. In PostgreSQL, adding a nullable column with no default is instant, but adding a default to existing rows rewrites data—add it in a separate, controlled step.