clickhouse删除partition分区数据

clickhouse分布式表tencent_table_20231208_DIST,本地表tencent_table_20231208_local;
30台clickhouse存储服务器;

本地表:tencent_table_20231208_local

 CREATE TABLE tencent_sz.tencent_table_20231208_local
(
    `id` Int64 DEFAULT CAST(0, 'Int64'),
    `pid` Int64,
    `user` String,
    `host` String,
    `db` Nullable(String),
    `COMMAND` String,
    `TIME` Int64,
    `STATE` Nullable(String),
    `source_sql` Nullable(String),
    `INFO` Nullable(String),
    `create_time` DateTime DEFAULT now(),
    `collect_create_time` DateTime,
    `instance_name` String,
    `source_ip` String,
    `source_port` UInt32,
    `_date` Date DEFAULT toDate(create_time),
    `scan_row` Int64 DEFAULT CAST(0, 'Int64'),
    `use_key` Nullable(String),
    `crc32` Int64 DEFAULT CAST(0, 'Int64')
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/tencent_table_20231208_local', '{replica}')
PARTITION BY _date
ORDER BY (source_ip, create_time)
TTL _date + toIntervalDay(14)
SETTINGS index_granularity = 8192

分布式表:

CREATE TABLE tencent_sz.tencent_table_20231208_DIST
(
    `id` Int64 DEFAULT CAST(0, 'Int64'),
    `pid` Int64,
    `user` String,
    `host` String,
    `db` Nullable(String),
    `COMMAND` String,
    `TIME` Int64,
    `STATE` Nullable(String),
    `source_sql` Nullable(String),
    `INFO` Nullable(String),
    `create_time` DateTime DEFAULT now(),
    `collect_create_time` DateTime,
    `instance_name` String,
    `source_ip` String,
    `source_port` UInt32,
    `_date` Date DEFAULT toDate(create_time),
    `scan_row` Int64 DEFAULT CAST(0, 'Int64'),
    `use_key` Nullable(String),
    `crc32` Int64 DEFAULT CAST(0, 'Int64')
)
ENGINE = Distributed('clk_dba', 'tencent_sz', 'tencent_table_20231208_local', rand())

一段时间后,数据过大,手动删除;
先查询该表的所有分区:

SELECT  database,  table,  partition,  name,  active FROM system.parts WHERE table = 'tencent_table_20231208_local'

输出:

┌─database─────┬─table──────────────────────────┬─partition──┬─name─────────────────┬─active─┐
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_4740_5083_4 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_5084_5330_4 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_5331_5441_3 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_5442_5467_2 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_5468_5468_0 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_5469_5469_0 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-07 │ 20231207_5470_5470_0 │      1 │
│ tencent_sz │ tencent_table_20231208_local │ 2023-12-08 │ 20231208_0_611_4     │      1 │

删除分区名:

alter table tencent_sz.tencent_table_20231208_local DROP PARTITION '2023-12-07';
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值