Adding a new column is one of the most common tasks in database work, yet it can be the most critical. Schema changes affect data integrity, query performance, and system stability. Done wrong, they trigger downtime or break production. Done right, they extend functionality without risk.
A new column can hold configuration data, track usage events, or store critical metrics. The choice of data type matters. Use INT for counters, VARCHAR for short text, TIMESTAMP for time data. Align it with indexing strategy. A poorly indexed column will slow reads and writes.
Before running ALTER TABLE, measure the consequences.
- Will the table lock under heavy load?
- Can the change be done online?
- Is there a default value that keeps old rows valid?
In Postgres, ALTER TABLE ADD COLUMN is straightforward: