How to drop all partitions of the table?

42 views
Skip to first unread message

Dmitriy Lazarenko

unread,
Aug 19, 2019, 6:01:59 AM8/19/19
to ClickHouse
Hello!

How can I drop all partitions of the table?

I played with system.parts:

ALTER TABLE my_table DROP PARTITION ID IN
(SELECT
    ID
FROM system.parts 
WHERE 
    active AND table = 'my_table')
or somthing like that.

but without success.

Thanks

Denis Zhuravlev

unread,
Aug 19, 2019, 1:57:55 PM8/19/19
to ClickHouse
generate SQL

select concat('alter table `',table, '` drop partition ',partition, ';')
from system.parts
where active = 1 and table like '%my_table%'
group by database,table,partition
order by database,table,partition 

or truncate table my_table

kriticar

unread,
Aug 24, 2019, 1:51:47 PM8/24/19
to ClickHouse
How about dropping paritions of ReplicatedMergeTree table on cluster?
For example if I have 10 nodes, 5 masters and 5 replicas, I should execute result of select you have provided on 5 master nodes.

Is there a better way?

Regards

Denis Zhuravlev

unread,
Aug 24, 2019, 2:40:19 PM8/24/19
to ClickHouse
No better way.
But you can execute drop on cluster: alter table X on cluster segmented drop partition 201908

kriticar

unread,
Sep 3, 2019, 3:46:02 AM9/3/19
to ClickHouse
Hi Denis,

it works only if tables are not replicated.

Regards.

Denis Zhuravlev

unread,
Sep 3, 2019, 9:33:43 AM9/3/19
to ClickHouse

kriticar

unread,
Sep 3, 2019, 10:31:02 AM9/3/19
to ClickHouse
At the moment I am on Altinity version:
ClickHouse client version 19.13.2.19.
Connected to ClickHouse server version 19.13.2 revision 54425.

and it doesn't work.

Regards.
Reply all
Reply to author
Forward
0 new messages