How to DROP a Column in PostgreSQL

Galaxy Glossary

How do I drop a column in PostgreSQL without breaking dependencies?

ALTER TABLE … DROP COLUMN permanently removes one or more columns from an existing table.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

DROP COLUMN in PostgreSQL

ALTER TABLE … DROP COLUMN deletes a column and its data forever. Use it to clean schemas, reduce storage, and simplify queries.

Why would I drop a column?

Remove obsolete, redundant, or migrated data. Cleaning unused columns keeps tables small, improves cache efficiency, and lowers maintenance overhead.

What is the exact DROP COLUMN syntax?

Use ALTER TABLE table_name DROP [IF EXISTS] column_name [CASCADE | RESTRICT]. Add ,-separated clauses to drop multiple columns in one statement.

How do I drop a single column?

ALTER TABLE employees DROP COLUMN middle_name;

The column and all its data disappear immediately. No table rewrite occurs if the column is not part of any index or constraint.

How do I drop several columns at once?

ALTER TABLE orders
DROP COLUMN IF EXISTS promo_code,
DROP COLUMN IF EXISTS ship_notes;

Multiple DROP COLUMN clauses run in one transaction, avoiding extra locks and reducing replication lag.

When do I need CASCADE or RESTRICT?

CASCADE automatically removes dependent objects—views, triggers, foreign keys—that reference the column. RESTRICT (default) blocks the command if dependents exist.

Will DROP COLUMN reclaim disk space?

Yes. PostgreSQL marks the space as free immediately. Autovacuum later returns it to the file system after freezing dead tuples.

Best practices for DROP COLUMN

Backup the table or schema, confirm no application code uses the column, drop during low-traffic windows, and test on staging first.

What happens in replicas?

The statement is WAL-logged. Standby servers apply it automatically, keeping schema in sync across clusters.

Why How to DROP a Column in PostgreSQL is important

How to DROP a Column in PostgreSQL Example Usage


-- Remove an unused column with dependent view
ALTER TABLE public.sales DROP COLUMN IF EXISTS discount_pct CASCADE;

How to DROP a Column in PostgreSQL Syntax


ALTER TABLE table_name
  DROP [ IF EXISTS ] column_name [, ...]
  [ CASCADE | RESTRICT ];

Common Mistakes

Frequently Asked Questions (FAQs)

Does DROP COLUMN lock the entire table?

It acquires an ACCESS EXCLUSIVE lock but usually completes quickly. For large tables, schedule during maintenance windows.

Can I undo a DROP COLUMN?

Not directly. You must restore from backup or recreate the column and repopulate data manually.

Is DROP COLUMN replicated to standbys?

Yes. The WAL record is streamed, so standbys execute the same ALTER TABLE statement automatically.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.