找出连续聚集体的大小

问题描述 投票:0回答:3

拥有包含几百万行的超表。我可以使用以下命令来选择它的大小:

SELECT pg_size_pretty( pg_total_relation_size('towns') );

我还有该超表的连续聚合:

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;

我刷新了视图,数据按预期显示。然而,我似乎无法弄清楚这个新视图占用了多少空间。

SELECT pg_size_pretty( pg_total_relation_size('towns_income') );
返回 0 个字节,我知道这是不正确的。我认为
towns
的 Total_relation_size 可能会增加,但这似乎也是一样的。我错过了什么吗?我也尝试过
hypertable_size
但没有成功,因为 mv 从技术上来说并不是一个超表。

postgresql materialized-views timescaledb continuous-aggregates
3个回答
9
投票

以下 SQL 可以提供帮助:)

 SELECT view_name, hypertable_size(format('%I.%I', materialization_hypertable_schema , materialization_hypertable_name )::regclass)
  FROM timescaledb_information.continuous_aggregates;

0
投票

另一种方法是以下 SQL 查询

SELECT pg_size_pretty(SUM(total_bytes)), aggs.view_name  
FROM "_timescaledb_internal".hypertable_chunk_local_size hcls, timescaledb_information.continuous_aggregates aggs
WHERE hcls.table_name = aggs.materialization_hypertable_name
GROUP BY aggs.view_name;

0
投票

以下查询以kb、mb格式显示总大小,更直观:

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;
© www.soinside.com 2019 - 2024. All rights reserved.