Adding a new column to a production database sounds simple. In practice, it is an operation that can block writes, take locks, or trigger cascading updates. The risks grow with table size and traffic. You need a repeatable, low‑risk process that works in staging and production.
Define the column in your schema with the correct type, constraints, and default values. Avoid defaults that cause the database to rewrite all existing rows in one transaction. Use nullable columns first, then backfill data in controlled batches before enforcing NOT NULL. This reduces lock contention and downtime.
In SQL, use:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL;
Run the statement during a low‑traffic window or on a hot standby. For large datasets, coordinate with your migration tool to make the ALTER TABLE non‑blocking if possible. Many managed databases now support instant column adds for certain data types; know your platform’s limits.