Created
February 5, 2023 11:05
-
-
Save kovetskiy/9d805cea5d24438b8e7d5e5b21ab39c9 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -euo pipefail | |
table="${1:-}" | |
view="${2:-}" | |
if [[ -z "$table" || -z "$view" ]]; then | |
echo "Usage: $0 <table> <view>" | |
exit 1 | |
fi | |
range_start="2023-02-04" | |
range_end="2023-02-05" | |
intervals=(1s 1m 5m 15m 1h 4h 1d) | |
:psql() { | |
psql "${PG_URL}" -c "$1" -t -A | |
} | |
:raw_size() { | |
:psql " | |
SELECT sum(c.total_bytes) | |
FROM chunks_detailed_size('$table') as c | |
JOIN timescaledb_information.chunks as ch | |
ON ch.chunk_schema = c.chunk_schema AND ch.chunk_name = c.chunk_name | |
WHERE range_start >= '$range_start' and range_end <= '$range_end'; | |
" | |
} | |
:interval_size() { | |
local interval="$1" | |
:psql " | |
SELECT sum(c.total_bytes) | |
FROM chunks_detailed_size(( | |
(select format('%I.%I', materialization_hypertable_schema, materialization_hypertable_name) | |
from timescaledb_information.continuous_aggregates | |
where view_name = '${view}_agg_${interval}'))) as c | |
JOIN timescaledb_information.chunks as ch | |
ON ch.chunk_schema = c.chunk_schema AND ch.chunk_name = c.chunk_name | |
WHERE range_start >= '$range_start' and range_end <= '$range_end'; | |
" | |
} | |
:main() { | |
local raw_size="$(:raw_size)" | |
echo "${table} $raw_size" | |
for interval in "${intervals[@]}"; do | |
local interval_size="$(:interval_size "$interval")" | |
echo "${view}_agg_${interval} $interval_size" | |
done | |
} | |
:main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment