The database sat heavy with data, but the request demanded more. You needed a new column.
Adding a new column should be straightforward, but only if you plan for scale, accuracy, and minimal downtime. Whether the table is small or serves millions of rows, the wrong approach can lock writes, slow reads, or risk data integrity.
First, define the purpose of the new column. Decide on the correct data type, constraints, and default values. Avoid NULL unless it’s intentional. Every choice here will affect performance and future migrations.
Next, check the database engine’s capabilities. In MySQL, ALTER TABLE can lock the table for the whole operation. PostgreSQL can add a column instantly if no default is specified. For large datasets, use techniques like online schema changes or progressive backfills. Tools such as pt-online-schema-change, gh-ost, or native partitioning can help reduce blocking and downtime.