clickhouse清理日志。

参考Clickhouse:日志表占用大量磁盘空间怎么办?_clickhouse store目录很大-CSDN博客t

清理脚本如下,清理动作需要时间比较长,10多分钟:

alter table system.trace_log delete where event_date < '2024-01-01'

alter table system.query_log delete where event_date < '2024-01-01'

alter table system.query_thread_log delete where event_date < '2024-01-01'

alter table system.asynchronous_metric_log delete where event_date < '2024-01-01'

查询语句:

SELECT

    sum(rows) AS `总行数`,

    formatReadableSize(sum(data_uncompressed_bytes)) AS `原始大小`,

    formatReadableSize(sum(data_compressed_bytes)) AS `压缩大小`,

    round((sum(data_compressed_bytes) / sum(data_uncompressed_bytes)) * 100, 0) AS `压缩率`,

    `table` AS `表名`

FROM system.parts where database = 'system' group by `table`

你可能感兴趣的:(数据库,clickhouse)