日常工作中需要观察Clickhouse的磁盘使用情况,查看文档后发现基于system.parts
表可以查询相关信息。
需要注意的是,systems.parts
只可以查询MergeTree
系列的表的情况。
systems.parts
字段说明见文末。
相关查询
查看数据库的磁盘使用情况及数据行数
查询本机整个数据库所有表总共的情况
select \
sum(rows) as row, \
formatReadableSize(sum(bytes_on_disk)) as used_disk, \
formatReadableSize(sum(data_uncompressed_bytes)) as brfore_compress, \
formatReadableSize(sum(data_compressed_bytes)) as after_compress, \
round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes) * 100, 0) compress_rate \
from system.parts
查询所有表某一天的磁盘使用情况
查询本机所有表在指定日期的磁盘使用、数据量情况。
select \
table, \
sum(rows) as row, \
formatReadableSize(sum(bytes_on_disk)) as used_disk, \
formatReadableSize(sum(data_uncompressed_bytes)) as before_compress, \
formatReadableSize(sum(data_compressed_bytes)) as after_compress, \
round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes) * 100, 0) compress_rate \
from system.parts \
where partition = '20210719000000' \
group by table \
order by row desc \
;