ALTER TABLE … DROP COLUMN permanently removes one or more columns and their data from a ClickHouse table.
Free storage, simplify schema, or remove sensitive data. ClickHouse reads column-oriented files; unused columns still consume disk until dropped.
Use ALTER TABLE … DROP COLUMN
in a maintenance window and verify no materialized views or queries depend on the column.
ClickHouse rewrites table metadata instantly.Old parts become obsolete and are purged by the background merge process, so the operation is usually fast.
ALTER TABLE [db.]table
DROP COLUMN column_name [, column_name2 …]
[ON CLUSTER cluster_name];
Add ON CLUSTER
for distributed DDL across a cluster.
ALTER TABLE Orders
DROP COLUMN legacy_status;
The legacy_status
column vanishes from Orders
; queries referencing it will now fail.
ALTER TABLE Customers
DROP COLUMN temp_flag,
DROP COLUMN deprecated_phone;
Multiple DROP statements can be chained in one command.
No built-in UNDO exists.Restore from backup or recreate the column and reload data.
1️⃣ Search your codebase for references. 2️⃣ Check materialized views. 3️⃣ Take a backup or snapshot. 4️⃣ Use staging first.
The metadata update is O(1). Disk cleanup happens asynchronously, so production impact is minimal.
• Retire A/B test flags
• Remove PII after retention period
• Trim legacy ETL columns
Include ON CLUSTER
to propagate the command.Without it you must run the statement on each shard/replica.
-- Orders table holds purchase data
CREATE TABLE Orders (
id UInt64,
customer_id UInt64,
order_date DateTime,
total_amount Decimal(10,2),
promo_code String
) ENGINE = MergeTree()
ORDER BY id;.
-- Decide promo_code is obsolete
ALTER TABLE Orders DROP COLUMN promo_code;
The column and its data disappear from new parts immediately.
UNKNOWN_IDENTIFIER
if the column does not exist; CANNOT_DROP_COLUMN
if a materialized view still depends on it.
After dropping columns, consider running OPTIMIZE TABLE … FINAL
to expedite disk space reclamation.
Only a lightweight metadata lock; read/write queries continue.
Space is released once old parts are merged or TTL moves them out—usually minutes to hours depending on load.
No.The key definition must remain valid; recreate the table if you need a different primary key.
.
No. Restore from backup or recreate the column and reload data.
Running queries keep using the old metadata snapshot, so they finish normally. New queries use the new schema.
Only if the partitioning key uses the column. ClickHouse prevents the drop in that case.