Skip to content

Instantly share code, notes, and snippets.

@draev
Last active September 7, 2022 21:58
Show Gist options
  • Save draev/9690325ab28f074f79f4c434724c62e7 to your computer and use it in GitHub Desktop.
Save draev/9690325ab28f074f79f4c434724c62e7 to your computer and use it in GitHub Desktop.
ClickHouse tables size
//https://kb.altinity.com/altinity-kb-useful-queries/altinity-kb-database-size-table-column-size/
WITH
(select free_space from system.disks) as free_space,
(select total_space from system.disks) as total_space
SELECT name as table,database,
max(sizebytes) as sizebytes,
max(size) as size,
concat(toString(round(sizebytes * 100 / (total_space - free_space), 2)), '%') as size_percent,
min(min_date) as min_date,
max(max_date) as max_date,
formatReadableSize(free_space) as free_size,
concat(toString(round(free_space * 100 / total_space, 2)), '%') as free_percent,
formatReadableSize(total_space) as total_size
FROM system.tables
ANY LEFT JOIN
(
SELECT table,database,
formatReadableSize(sum(bytes)) as size,
sum(bytes) as sizebytes,
min(min_date) as min_date,
max(max_date) as max_date
FROM system.parts
WHERE active AND database != 'system'
GROUP BY table,database
)a USING ( table,database )
WHERE 1 AND database != 'system'
GROUP BY table,database
ORDER BY sizebytes DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment