The table holds millions of rows, but the schema needs to change. You must add a new column—fast, without breaking production.
A new column can mean a simple integer or a complex JSONB field. It can be nullable or enforce strict constraints. The decision determines query speed, storage impact, and how future migrations behave. In high-traffic systems, altering a table is not just a technical change; it’s an operational risk.
The safest path is a migration that avoids locking the table for long periods. Online migrations let you insert a new column without blocking reads and writes. Tools like ALTER TABLE ... ADD COLUMN are fast for small datasets but can cause downtime for large ones. Techniques such as adding the column as nullable, then backfilling in batches, reduce lock time.
Data type choice matters. Use fixed-width types if performance is critical. Avoid overusing text when structured data is available. If the new column will be indexed, create the index after backfilling to avoid index build overhead during population.