Skip to content

Instantly share code, notes, and snippets.

@ayush--s
Created October 15, 2021 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayush--s/2838a27242d345890ee5bde70d0e4555 to your computer and use it in GitHub Desktop.
Save ayush--s/2838a27242d345890ee5bde70d0e4555 to your computer and use it in GitHub Desktop.
get chunk size + start, end for given table in timescaledb
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
@ayush--s
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment