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';

相关推荐

  1. clickhouse删除partition分区数据

    2023-12-09 11:36:01       38 阅读
  2. Clickhouse】如何在ClickHouse删除集群表数据

    2023-12-09 11:36:01       47 阅读
  3. MapReduce-Partition分区

    2023-12-09 11:36:01       24 阅读
  4. mysql 删除分区数据

    2023-12-09 11:36:01       32 阅读
  5. Clickhouse 查看分区情况

    2023-12-09 11:36:01       22 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-09 11:36:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-09 11:36:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-09 11:36:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-09 11:36:01       20 阅读

热门阅读

  1. Thinkphp5+FastAdmin配置workerman消息推送(多线程)

    2023-12-09 11:36:01       35 阅读
  2. 【Linux 软连接命令】

    2023-12-09 11:36:01       30 阅读
  3. GO设计模式——15、责任链模式(行为型)

    2023-12-09 11:36:01       36 阅读
  4. Android 获取进程名称

    2023-12-09 11:36:01       39 阅读
  5. 前端学习--React(5)

    2023-12-09 11:36:01       33 阅读
  6. React查询、搜索类功能的实现

    2023-12-09 11:36:01       42 阅读
  7. ReactJs笔记摘录

    2023-12-09 11:36:01       41 阅读
  8. K8S学习指南(2)-docker的基本使用

    2023-12-09 11:36:01       33 阅读
  9. Solidity学习教程

    2023-12-09 11:36:01       31 阅读
  10. BGP综合

    BGP综合

    2023-12-09 11:36:01      27 阅读
  11. C语言精选——选择题Day40

    2023-12-09 11:36:01       41 阅读
  12. 【力扣100】9.和为k的子数组

    2023-12-09 11:36:01       46 阅读
  13. vue基本运用之常见问题及案例代码

    2023-12-09 11:36:01       34 阅读