Adding a new column to a database table should be fast, reversible, and safe. In production, it must also happen without downtime or data loss. Whether you’re working with PostgreSQL, MySQL, or SQLite, the goal is the same: introduce a schema change that your application can handle instantly.
A new column can store additional data, enable new features, or replace legacy fields. The process starts with defining the column name, data type, and default value. Avoid null defaults unless your code can handle them. In relational databases, adding a column with a default value on a large table can lock writes for seconds or minutes. To prevent blocking, add the column without a default, then backfill in smaller batches.
In PostgreSQL, for example:
ALTER TABLE orders ADD COLUMN processed_at TIMESTAMPTZ;
Run this outside of peak traffic, verify the column exists, and then update your application code to read and write to it. Once deployed, run a backfill job: