Created
August 7, 2025 08:48
-
-
Save iamsudip/3796013bbc7e19913f1c32caa4b27a38 to your computer and use it in GitHub Desktop.
Clickhouse Get Table Size and other related information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| parts.*, | |
| columns.compressed_size, | |
| columns.uncompressed_size, | |
| columns.compression_ratio, | |
| columns.compression_percentage | |
| FROM | |
| ( | |
| SELECT | |
| `table`, | |
| formatReadableSize(sum(data_uncompressed_bytes)) AS uncompressed_size, | |
| formatReadableSize(sum(data_compressed_bytes)) AS compressed_size, | |
| round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes), 3) AS compression_ratio, | |
| round(100 - ((sum(data_compressed_bytes) * 100) / sum(data_uncompressed_bytes)), 3) AS compression_percentage | |
| FROM system.columns | |
| GROUP BY `table` | |
| ) AS columns | |
| RIGHT JOIN | |
| ( | |
| SELECT | |
| `table`, | |
| sum(rows) AS rows, | |
| max(modification_time) AS latest_modification, | |
| formatReadableSize(sum(bytes)) AS disk_size, | |
| formatReadableSize(sum(primary_key_bytes_in_memory)) AS primary_keys_size, | |
| any(engine) AS engine, | |
| sum(bytes) AS bytes_size | |
| FROM system.parts | |
| WHERE active | |
| GROUP BY | |
| database, | |
| `table` | |
| ) AS parts ON columns.`table` = parts.`table` | |
| ORDER BY parts.bytes_size DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment