The query finished running. The data looked clean. But the table needed a new column.
Adding a new column is one of the most common schema changes in any database. It can be trivial or destructive, depending on scale, constraints, and uptime requirements. The right approach ensures zero downtime and avoids corrupting data.
First, decide on the column type and default value. A poorly chosen type will cause migrations to lock tables or bloat storage. For large datasets, adding a column with a non-null default can rewrite the entire table. Use NULL defaults and backfill in controlled batches if you need to preserve performance.
Next, plan the migration path. Tools like ALTER TABLE may be straightforward for small tables, but in production with billions of rows, you need online migrations. PostgreSQL supports adding a nullable column instantly. MySQL can use ALGORITHM=INPLACE for certain changes. Always verify your database engine's capabilities before running the migration.