Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding out the size of a continuous aggregate

Have hypertable table with a couple million rows. I'm able to select the size of this just fine using the following:

SELECT pg_size_pretty( pg_total_relation_size('towns') );

I also have a continuous aggregate for that hypertable:

WITH (timescaledb.continuous, timescaledb.materialized_only=true) AS
SELECT time_bucket(INTERVAL '1 minute', timestamp) AS bucket,
 /* random query */
FROM towns
GROUP BY bucket, town
WITH NO DATA;

I've refreshed the view and the data is showing as expected. However, I cannot seem to figure out how much space this new view is taking up.

SELECT pg_size_pretty( pg_total_relation_size('towns_income') ); returns 0 bytes which I know isn't correct. I thought that maybe the total_relation_size for towns would increase, but that also seems the same. Am I missing something? I've tried hypertable_size as well with no success as mv isn't technically a hypertable.

like image 422
Nicole Staline Avatar asked Oct 18 '25 18:10

Nicole Staline


2 Answers

The following SQL can help :)

 SELECT view_name, hypertable_size(format('%I.%I', materialization_hypertable_schema , materialization_hypertable_name )::regclass)
  FROM timescaledb_information.continuous_aggregates;
like image 193
jonatasdp Avatar answered Oct 21 '25 09:10

jonatasdp


The following query displays the total size in a kb, mb format, which is more insightful:

SELECT 
    view_name, 
    pg_size_pretty(hypertable_size(format('%I.%I', materialization_hypertable_schema, materialization_hypertable_name)::regclass)) AS hypertable_size
FROM 
    timescaledb_information.continuous_aggregates;
like image 45
Konstantinos Gallis Avatar answered Oct 21 '25 07:10

Konstantinos Gallis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!