Adding a new column sounds simple. In production, it’s not. Schema changes can lock tables, block queries, or cause downtime if handled wrong. The right approach depends on the database engine, the size of your data, and the uptime requirements.
In SQL, a new column is created with ALTER TABLE. The basic syntax in PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMPTZ;
For small tables, this runs instantly. For large ones, adding a column with a default value can rewrite the entire table, taking minutes or hours. Always check your database’s documentation for how it handles storage and defaults.
In MySQL, ALTER TABLE can rebuild the table depending on the column type and position. Use ALGORITHM=INPLACE if possible to avoid a full rebuild. In PostgreSQL 11+, adding a column with a constant default is optimized, avoiding a full table rewrite. In distributed systems, adding a new column must be coordinated with application code deployments to allow for backward compatibility.