Adding a new column to a database table is simple in theory but dangerous in practice. Done wrong, it locks tables, stalls writes, or loses data. Done right, it’s invisible to users and seamless for your team.
The first step is choosing the correct data type. Match the column’s purpose to the tightest possible type. Smaller types save memory, speed queries, and reduce index size. For example, use INT over BIGINT unless higher precision is required.
Run schema changes in non-blocking mode when your database supports it. For MySQL, use ALGORITHM=INPLACE or ALGORITHM=INSTANT. For PostgreSQL, adding a nullable column without a default is almost instant. Avoid adding a default on creation for large tables—backfill later with batched updates.
Index only when needed. Adding an index with the column at creation time locks more resources. If queries don’t filter or join on the field, skip the index.