86 字
1 分钟
clickhouse空间占用情况

有时候我们需要查看clickhouse中各个表的空间占用情况,可以使用以下sql进行查询

with parts AS (
    select
        database,
        table,
        sum(rows) as rows,
        sum(bytes) as size,
        sum(bytes_on_disk) as bytes_on_disk,
        sum(data_uncompressed_bytes) as data_uncompressed_bytes,
        sum(data_compressed_bytes) as data_compressed_bytes
    from system.parts
    where active and database = 'your database name'
    group by database, table)
select
    database,
    table,
    formatReadableSize(size) as size,
    formatReadableSize(bytes_on_disk) as bytes_on_disk,
    formatReadableSize(data_uncompressed_bytes) as data_uncompressed_bytes,
    formatReadableSize(data_compressed_bytes) as data_compressed_bytes,
    rows
from parts;