Adding a new column to a database should be simple. In practice, the wrong move can slow queries, break indexes, or cause downtime. The solution depends on your database engine, schema design, and migration process. For relational databases like PostgreSQL, MySQL, or MariaDB, ALTER TABLE is the standard. It will add a new column to existing rows with a default value or as null.
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP;
The command is fast on small datasets but can lock the table on large ones. To avoid blocking writes in production, you use tools like pg_osc for Postgres or pt-online-schema-change for MySQL. These perform schema changes in a controlled, non-blocking way.
When adding a new column, choose the right data type. Mismatched types cause slow queries and data corruption risk. Set NOT NULL only if you can backfill immediately. For optional fields, keep it nullable until data consistency is guaranteed.
Indexing the new column improves read performance but slows writes. Only index if queries will filter or join on that field. For partial adoption, use a conditional index.