文档

工具和统计函数

更新时间:
一键部署

获得时序元数据表的详细信息。

timescaledb_information.hypertable

获得时序元数据表的详细信息。

字段及其含义

Name

Description

schema_name

时序元数据表schema名

table_name

时序元数据表表名

table_owner

时序元数据表拥有用户

number_partitions

分区数

num_chunks

数据块数

table_bytes

时序元数据表的磁盘使用空间

index_bytes

索引的磁盘使用空间

toast_bytes

TOAST表磁盘使用空间

total_bytes

所有磁盘占用空间

示例:

查询所有时序元数据表信息:

SELECT * FROM timescaledb_information.hypertable;
 table_schema | table_name | table_owner | num_dimensions | num_chunks | table_size | index_size | toast_size | total_size
--------------+------------+-------------+----------------+------------+------------+------------+------------+------------
 public       | metrics    | postgres    |              1 |          5 | 99 MB      | 96 MB      |            | 195 MB
 public       | devices    | postgres    |              1 |          1 | 8192 bytes | 16 kB      |            | 24 kB
(2 rows)

检查表是否是时序元数据表

SELECT * FROM timescaledb_information.hypertable
WHERE table_schema='public' AND table_name='metrics';
 table_schema | table_name | table_owner | num_dimensions | num_chunks | table_size | index_size | toast_size | total_size
--------------+------------+-------------+----------------+------------+------------+------------+------------+------------
 public       | metrics    | postgres    |              1 |          5 | 99 MB      | 96 MB      |            | 195 MB
(1 row)

chunk_relation_size()

获得时序元数据表的数据块关系。返回值是一张表。

必选参数

Name

Description

main_table

时序元数据表表名

返回值

Column

Description

chunk_id

数据块ID

chunk_table

数据块表名

partitioning_columns

分区列名

partitioning_column_types

分区列类型

partitioning_hash_functions

分区列哈希函数

dimensions

分区列列名

ranges

分区区间

table_bytes

时序元数据表的磁盘使用空间

index_bytes

索引的磁盘使用空间

toast_bytes

TOAST表磁盘使用空间

total_bytes

所有磁盘占用空间

示例:

SELECT * FROM chunk_relation_size('conditions');

或者选取部分列进行输出

SELECT chunk_table, table_bytes, index_bytes, total_bytes
FROM chunk_relation_size('conditions');

期望输出:

chunk_table                 | table_bytes | index_bytes | total_bytes
---------------------------------------------+-------------+-------------+-------------
 "_timescaledb_internal"."_hyper_1_1_chunk"  |    29220864 |    37773312 |    67002368
 "_timescaledb_internal"."_hyper_1_2_chunk"  |    59252736 |    81297408 |   140558336
 ...

chunk_relation_size_pretty()

与chunk_relation_size()功能相同,显示格式不同。

必选参数

Name

Description

main_table

时序元数据表表名

Returns

Column

Description

chunk_id

数据块ID

chunk_table

数据块表名

partitioning_columns

分区列名

partitioning_column_types

分区列类型

partitioning_hash_functions

分区列哈希函数

dimensions

分区列列名

ranges

分区区间

table_bytes

主表(main_table)的磁盘使用空间, Pretty 格式

index_bytes

索引的磁盘使用空间, Pretty 格式

toast_bytes

TOAST表磁盘使用空间, Pretty 格式

total_bytes

所有磁盘占用空间, Pretty 格式

示例:

SELECT * FROM chunk_relation_size_pretty('conditions');

或者选取部分列进行输出

SELECT chunk_table, table_size, index_size, total_size
FROM chunk_relation_size_pretty('conditions');

期望输出

chunk_table                  | table_size | index_size | total_size
---------------------------------------------+------------+------------+------------
 "_timescaledb_internal"."_hyper_1_1_chunk"  | 28 MB      | 36 MB      | 64 MB
 "_timescaledb_internal"."_hyper_1_2_chunk"  | 57 MB      | 78 MB      | 134 MB
 ...

hypertable_approximate_row_count()

计算时序元数据表行数近似值

可选参数

Name

Description

main_table

时序元数据表表名

示例:

计算conditions时序元数据表行数近似值

SELECT * FROM hypertable_approximate_row_count('conditions');

计算所有时序元数据表行数近似值

SELECT * FROM hypertable_approximate_row_count();

期望输出

schema_name | table_name | row_estimate
-------------+------------+--------------
  public     | conditions |      240000

hypertable_relation_size()

获得时序元数据表的关系表。

必选参数

Name

Description

main_table

时序元数据表表名

返回值

Column

Description

table_bytes

时序元数据表磁盘占用空间

index_bytes

索引磁盘占用空间

toast_bytes

TOAST表磁盘占用空间

total_bytes

时序元数据表关联的索引,TOAST表和它本身的磁盘占用空间之和

示例:

SELECT * FROM hypertable_relation_size('conditions');

或者选取部分列进行输出

SELECT table_bytes, index_bytes, toast_bytes, total_bytes
FROM hypertable_relation_size('conditions');

期望输出

table_bytes | index_bytes | toast_bytes | total_bytes
---------------+----------------+----------------+-------------
  1227661312 |  1685979136 |      180224 |  2913820672

hypertable_relation_size_pretty()

与hypertable_relation_size()相同,显示格式有区别。

必选参数

Name

Description

main_table

时序元数据表表名

返回值

Column

Description

table_size

时序元数据表的磁盘使用空间, Pretty 格式

index_size

索引的磁盘使用空间, Pretty 格式

toast_size

TOAST表磁盘使用空间, Pretty 格式

total_size

所有磁盘占用空间, Pretty 格式

示例:

SELECT * FROM hypertable_relation_size_pretty('conditions');

或者选取部分列进行输出

SELECT table_size, index_size, toast_size, total_size
FROM hypertable_relation_size_pretty('conditions');

期望输出

table_size | index_size | toast_size | total_size
------------+------------+------------+------------
 1171 MB    | 1608 MB    | 176 kB     | 2779 MB

indexes_relation_size()

获得时序元数据表索引大小。

必选参数

Name

Description

main_table

时序元数据表表名

Returns

Column

Description

index_name

索引列名

total_bytes

索引磁盘占用空间

示例:

SELECT * FROM indexes_relation_size('conditions');

期望输出

index_name              | total_bytes
--------------------------------------+-------------
 public.conditions_device_id_time_idx |  1198620672
 public.conditions_time_idx           |   487358464

indexes_relation_size_pretty()

与indexes_relation_size()相同,显示格式有区别。

必选参数

Name

Description

main_table

时序元数据表表名

返回值

Column

Description

index_name

索引列名

total_size

索引磁盘占用空间,pretty格式

示例:

SELECT * FROM indexes_relation_size_pretty('conditions');

期望输出

index_name_              | total_size
--------------------------------------+------------
 public.conditions_device_id_time_idx | 1143 MB
 public.conditions_time_idx           | 465 MB
  • 本页导读 (1)
文档反馈