Adding a new column is one of the most common adjustments in modern databases. It shapes the data model without rewriting the core. Whether in PostgreSQL, MySQL, or SQLite, the goal is the same: extend the schema with minimal disruption.
In SQL, the operation is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This command modifies the table definition instantly in most systems, but there are nuances. On small datasets, the change is nearly instant. On large, production-scale systems, it can lock writes or trigger table rewrites. Understanding engine-specific behavior is critical.
For PostgreSQL, ADD COLUMN with a default value will rewrite the full table in older versions. Since 11, adding a column with a non-null default avoids the rewrite. MySQL handles ADD COLUMN differently depending on storage engine and version—InnoDB may rebuild the table unless you specify certain options. SQLite rewrites the table almost every time, so schema evolution should be planned carefully.
Indexes and constraints on a new column also impact performance. Adding an index immediately after creating the column can double the operational cost. Consider populating the column first, then creating the index in a controlled window.