chunk_compression_stats()

Community

Get chunk-specific statistics related to hypertable compression. All sizes are in bytes.

Required Arguments

NameTypeDescription
hypertableREGCLASSName of the hypertable

Returns

ColumnTypeDescription
chunk_schemaTEXTSchema name of the chunk
chunk_nameTEXTName of the chunk
number_compressed_chunksINTEGERthe number of chunks used by the hypertable that are currently compressed
before_compression_table_bytesBIGINTSize of the heap before compression (NULL if currently uncompressed)
before_compression_index_bytesBIGINTSize of all the indexes before compression (NULL if currently uncompressed)
before_compression_toast_bytesBIGINTSize the TOAST table before compression (NULL if currently uncompressed)
before_compression_total_bytesBIGINTSize of the entire chunk table (table+indexes+toast) before compression (NULL if currently uncompressed)
after_compression_table_bytesBIGINTSize of the heap after compression (NULL if currently uncompressed)
after_compression_index_bytesBIGINTSize of all the indexes after compression (NULL if currently uncompressed)
after_compression_toast_bytesBIGINTSize the TOAST table after compression (NULL if currently uncompressed)
after_compression_total_bytesBIGINTSize of the entire chunk table (table+indexes+toast) after compression (NULL if currently uncompressed)
node_nameTEXTnodes on which the chunk is located, applicable only to distributed hypertables

Sample Usage

  1. SELECT * FROM chunk_compression_stats('conditions')
  2. ORDER BY chunk_name LIMIT 2;
  3. -[ RECORD 1 ]------------------+----------------------
  4. chunk_schema | _timescaledb_internal
  5. chunk_name | _hyper_1_1_chunk
  6. compression_status | Uncompressed
  7. before_compression_table_bytes |
  8. before_compression_index_bytes |
  9. before_compression_toast_bytes |
  10. before_compression_total_bytes |
  11. after_compression_table_bytes |
  12. after_compression_index_bytes |
  13. after_compression_toast_bytes |
  14. after_compression_total_bytes |
  15. node_name |
  16. -[ RECORD 2 ]------------------+----------------------
  17. chunk_schema | _timescaledb_internal
  18. chunk_name | _hyper_1_2_chunk
  19. compression_status | Compressed
  20. before_compression_table_bytes | 8192
  21. before_compression_index_bytes | 32768
  22. before_compression_toast_bytes | 0
  23. before_compression_total_bytes | 40960
  24. after_compression_table_bytes | 8192
  25. after_compression_index_bytes | 32768
  26. after_compression_toast_bytes | 8192
  27. after_compression_total_bytes | 49152
  28. node_name |

Use pg_size_pretty get the output in a more human friendly format.

  1. SELECT pg_size_pretty(after_compression_total_bytes) AS total
  2. FROM chunk_compression_stats('conditions')
  3. WHERE compression_status = 'Compressed';
  4. -[ RECORD 1 ]--+------
  5. total | 48 kB