推特 阿里云技术文档正文

工具和统计函数_时序函数SQL参考_时空数据库_时序时空数据库TSDB

admin 阿里云技术文档 2020-02-11 187 0
阿里云服务器优惠

工具和统计函数

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 所有磁盘占用空间

示例:

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

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

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

  1. SELECT * FROM timescaledb_information.hypertable
  2. WHERE table_schema='public' AND table_name='metrics';
  3. table_schema | table_name | table_owner | num_dimensions | num_chunks | table_size | index_size | toast_size | total_size
  4. --------------+------------+-------------+----------------+------------+------------+------------+------------+------------
  5. public | metrics | postgres | 1 | 5 | 99 MB | 96 MB | | 195 MB
  6. (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 所有磁盘占用空间

示例:

  1. SELECT * FROM chunk_relation_size('conditions');

或者选取部分列进行输出

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

期望输出:

  1. chunk_table | table_bytes | index_bytes | total_bytes
  2. ---------------------------------------------+-------------+-------------+-------------
  3. "_timescaledb_internal"."_hyper_1_1_chunk" | 29220864 | 37773312 | 67002368
  4. "_timescaledb_internal"."_hyper_1_2_chunk" | 59252736 | 81297408 | 140558336
  5. ...

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 格式

示例:

  1. SELECT * FROM chunk_relation_size_pretty('conditions');

或者选取部分列进行输出

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

期望输出

  1. chunk_table | table_size | index_size | total_size
  2. ---------------------------------------------+------------+------------+------------
  3. "_timescaledb_internal"."_hyper_1_1_chunk" | 28 MB | 36 MB | 64 MB
  4. "_timescaledb_internal"."_hyper_1_2_chunk" | 57 MB | 78 MB | 134 MB
  5. ...

hypertable_approximate_row_count()

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

可选参数

Name Description
main_table 时序元数据表表名

示例:

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

  1. SELECT * FROM hypertable_approximate_row_count('conditions');

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

  1. SELECT * FROM hypertable_approximate_row_count();

期望输出

  1. schema_name | table_name | row_estimate
  2. -------------+------------+--------------
  3. public | conditions | 240000

hypertable_relation_size()

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

必选参数

Name Description
main_table 时序元数据表表名

返回值

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

示例:

  1. SELECT * FROM hypertable_relation_size('conditions');

或者选取部分列进行输出

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

期望输出

  1. table_bytes | index_bytes | toast_bytes | total_bytes
  2. ---------------+----------------+----------------+-------------
  3. 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 格式

示例:

  1. SELECT * FROM hypertable_relation_size_pretty('conditions');

或者选取部分列进行输出

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

期望输出

  1. table_size | index_size | toast_size | total_size
  2. ------------+------------+------------+------------
  3. 1171 MB | 1608 MB | 176 kB | 2779 MB

indexes_relation_size()

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

必选参数

Name Description
main_table 时序元数据表表名

Returns

Column Description
index_name 索引列名
total_bytes 索引磁盘占用空间

示例:

  1. SELECT * FROM indexes_relation_size('conditions');

期望输出

  1. index_name | total_bytes
  2. --------------------------------------+-------------
  3. public.conditions_device_id_time_idx | 1198620672
  4. public.conditions_time_idx | 487358464

indexes_relation_size_pretty()

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

必选参数

Name Description
main_table 时序元数据表表名

返回值

Column Description
index_name 索引列名
total_size 索引磁盘占用空间,pretty格式

示例:

  1. SELECT * FROM indexes_relation_size_pretty('conditions');

期望输出

  1. index_name_ | total_size
  2. --------------------------------------+------------
  3. public.conditions_device_id_time_idx | 1143 MB
  4. public.conditions_time_idx | 465 MB
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论

-----