How to DROP COLUMN in PostgreSQL

Galaxy Glossary

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

ALTER TABLE … DROP COLUMN permanently removes a column and its data from a PostgreSQL table.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

When should I drop a column?

Remove obsolete, duplicated, or deprecated fields to simplify your schema and speed up queries. Always confirm no application logic depends on the column.

What is the basic syntax?

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.

How do I drop a column safely?

Wrap the command in a transaction, back up critical tables, and check for dependencies with pg_depend or by querying information_schema.

Can I drop multiple columns at once?

Yes—list them comma-separated in a single ALTER TABLE statement.This avoids multiple rewrites and speeds deployment.

Example

ALTER TABLE Products
DROP COLUMN IF EXISTS stock,
DROP COLUMN IF EXISTS discontinued;

What happens to indexes and constraints?

PostgreSQL automatically removes indexes or constraints that reference the dropped column.Use CASCADE if additional objects depend on it.

Best practices for production

Create feature flags to stop writing to the column first, run the drop in maintenance windows, and monitor disk space after the operation completes.

How long does DROP COLUMN take?

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.

Is there an alternative to dropping?

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.

Key takeaway

Test, back up, and communicate before using DROP COLUMN. A single ALTER TABLE can permanently delete important data.

.

Why How to DROP COLUMN in PostgreSQL is important

How to DROP COLUMN in PostgreSQL Example Usage


-- Remove obsolete 'stock' column from Products table
BEGIN;
ALTER TABLE Products
    DROP COLUMN IF EXISTS stock RESTRICT;
COMMIT;

How to DROP COLUMN in PostgreSQL Syntax


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

-- Ecommerce example
a) Remove a single column
ALTER TABLE Products 
    DROP COLUMN IF EXISTS stock;

b) Remove multiple columns and cascade
ALTER TABLE Orders 
    DROP COLUMN order_date, 
    DROP COLUMN total_amount CASCADE;

Common Mistakes

Frequently Asked Questions (FAQs)

Does DROP COLUMN free disk space immediately?

The space becomes reusable, but you may need VACUUM FULL or pg_repack to shrink the physical file.

Can I rollback a DROP COLUMN?

Only within the same transaction. Once committed, recovery requires restoring from backup.

Will DROP COLUMN lock the table?

Yes. ALTER TABLE rewrites the table, acquiring an ACCESS EXCLUSIVE lock that blocks reads and writes until completion.

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