The database was ready. The schema was locked. Then came the request: add a new column.
A new column is simple in code, but never trivial in practice. It changes storage, queries, indexes, migrations. It touches application logic and data integrity. Done wrong, it breaks production. Done right, it scales.
Adding a new column in SQL starts with defining its type, default value, and constraints. In PostgreSQL, you can run:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This is instant if the table is small. On large tables, it can lock writes and cause downtime. Some systems support adding a new column with metadata-only changes for certain types, avoiding full table rewrites. Others require careful migration plans.
When the new column must be populated from existing data, you might need a background job to fill rows in batches. This avoids locking the table for long periods. Schema changes in production should be tested in staging with representative data volume.