Adding a new column to a database is simple in syntax, but dangerous in practice. It affects storage, performance, and application logic. Done wrong, it locks tables, blocks writes, or corrupts data. Done right, it extends your system with zero downtime.
Start by defining what the new column should store and why. Avoid vague datatypes. Pick the smallest type that fits the exact need. This improves read speed, index size, and memory use.
Plan for nullability. If the column cannot be null, decide how to populate existing rows during the migration. Large tables with default values require careful batching, or you risk long locks.
When altering live systems, use online schema changes where supported. In PostgreSQL, adding a column without a default is fast. MySQL with InnoDB handles it differently. Always check your version-specific behavior before running production changes.