Created
October 15, 2021 10:27
-
-
Save ayush--s/2838a27242d345890ee5bde70d0e4555 to your computer and use it in GitHub Desktop.
get chunk size + start, end for given table in timescaledb
This file contains 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
WITH size AS ( | |
SELECT | |
concat(chunk_schema, '.', chunk_name) AS name, | |
round(table_bytes / (1024 * 1024.0), 2) AS table_megs, | |
round(index_bytes / (1024 * 1024.0), 2) AS index_megs, | |
round(total_bytes / (1024 * 1024.0), 2) AS total_megs | |
FROM | |
chunks_detailed_size ('%%table%%') | |
ORDER BY | |
chunk_name, | |
node_name | |
), | |
timerange AS ( | |
SELECT | |
* | |
FROM | |
chunks_tstz | |
WHERE | |
hypertable::text = '%%table%%' | |
) | |
SELECT | |
chunk, | |
table_megs, | |
index_megs, | |
total_megs, | |
time_range | |
FROM | |
size s | |
INNER JOIN timerange t ON s.name = t.chunk::text | |
ORDER BY | |
time_range DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source of chunks_tstz view: https://github.com/timescale/timescaledb-extras/blob/master/views/chunks.sql