Adding a new column sounds simple. In practice, the details decide whether you ship cleanly or cause downtime. The process begins with defining the column name, type, and constraints. In SQL, this uses the ALTER TABLE statement. For example:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This command changes the schema in place. On small tables, it finishes fast. On large tables, it can block reads and writes. To avoid this, use migrations that roll out in steps. First, add the column as nullable. Then backfill data in batches. Finally, add NOT NULL or an index if needed.
In PostgreSQL, ADD COLUMN with a default value before version 11 rewrote the entire table, creating long locks. Newer versions optimize this path by storing the default in the metadata. MySQL and MariaDB differ. On InnoDB, adding a column may require a full table rebuild depending on version and storage format.
When altering high-traffic systems, schedule schema changes during maintenance windows or use tools like pt-online-schema-change for MySQL or pg_online_schema_change for PostgreSQL. Test migrations in a staging environment with production-like data and load.