ALTER TABLE … DROP COLUMN permanently removes a column and its data from a PostgreSQL table.
Remove obsolete, duplicated, or deprecated fields to simplify your schema and speed up queries. Always confirm no application logic depends on the column.
Use ALTER TABLE followed by DROP COLUMN.Add IF EXISTS to skip errors when the column may not exist, and CASCADE to automatically remove dependent objects.
Wrap the command in a transaction, back up critical tables, and check for dependencies with pg_depend
or by querying information_schema.
Yes—list them comma-separated in a single ALTER TABLE statement.This avoids multiple rewrites and speeds deployment.
ALTER TABLE Products
DROP COLUMN IF EXISTS stock,
DROP COLUMN IF EXISTS discontinued;
PostgreSQL automatically removes indexes or constraints that reference the dropped column.Use CASCADE if additional objects depend on it.
Create feature flags to stop writing to the column first, run the drop in maintenance windows, and monitor disk space after the operation completes.
PostgreSQL rewrites the entire table unless the column is the only one stored in a TOAST table.Plan downtime for very large tables or use ALTER TABLE … SET NOT NULL
followed by pg_repack to minimize impact.
Mark the column as deprecated in code, stop referencing it, and leave it for future cleanup to avoid immediate downtime. You can also set the column as invisible in client code.
Test, back up, and communicate before using DROP COLUMN. A single ALTER TABLE can permanently delete important data.
.
The space becomes reusable, but you may need VACUUM FULL or pg_repack to shrink the physical file.
Only within the same transaction. Once committed, recovery requires restoring from backup.
Yes. ALTER TABLE rewrites the table, acquiring an ACCESS EXCLUSIVE lock that blocks reads and writes until completion.