> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# hypertable_columnstore_stats()

> Get columnstore statistics related to the columnstore

export const CHUNK = 'chunk';

export const HYPERTABLE = 'hypertable';

export const COLUMNSTORE = 'columnstore';

<Icon icon="tag" iconType="duotone" /> Since [2.18.0][tsdb-2.18.0]

<Tag>Community</Tag>

<Info>
  `hypertable_columnstore_stats()` replaces `hypertable_compression_stats()`, deprecated in 2.18.0. The parameters are the same.
</Info>

Retrieve compression statistics for the {COLUMNSTORE}.

For more information about using {HYPERTABLE}s, including {CHUNK} size partitioning,
see [{HYPERTABLE}s][hypertable-docs].

## Samples

To retrieve compression statistics:

* **Show the compression status of the `conditions` {HYPERTABLE}**:

  ```sql theme={"dark"}
  SELECT * FROM hypertable_columnstore_stats('conditions');
  ```

  Returns:

  ```sql theme={"dark"}
  -[ RECORD 1 ]------------------+------
  total_chunks                   | 4
  number_compressed_chunks       | 1
  before_compression_table_bytes | 8192
  before_compression_index_bytes | 32768
  before_compression_toast_bytes | 0
  before_compression_total_bytes | 40960
  after_compression_table_bytes  | 8192
  after_compression_index_bytes  | 32768
  after_compression_toast_bytes  | 8192
  after_compression_total_bytes  | 49152
  node_name                      |
  ```

* **Use `pg_size_pretty` get the output in a more human friendly format**:

  ```sql theme={"dark"}
  SELECT pg_size_pretty(after_compression_total_bytes) as total
    FROM hypertable_columnstore_stats('conditions');
  ```

  Returns:

  ```sql theme={"dark"}
  -[ RECORD 1 ]--+------
  total | 48 kB
  ```

## Arguments

The syntax is:

```sql theme={"dark"}
SELECT * FROM hypertable_columnstore_stats('<hypertable_name>');
```

| Name         | Type     | Description                         |
| ------------ | -------- | ----------------------------------- |
| `hypertable` | REGCLASS | {HYPERTABLE} to show statistics for |

## Returns

| Column                           | Type   | Description                                                                                                                                                                                                     |
| -------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `total_chunks`                   | BIGINT | The number of {CHUNK}s used by the {HYPERTABLE}. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                      |
| `number_compressed_chunks`       | BIGINT | The number of {CHUNK}s used by the {HYPERTABLE} that are currently compressed. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                        |
| `before_compression_table_bytes` | BIGINT | Size of the heap before compression. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                                  |
| `before_compression_index_bytes` | BIGINT | Size of all the indexes before compression. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                           |
| `before_compression_toast_bytes` | BIGINT | Size the TOAST table before compression. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                              |
| `before_compression_total_bytes` | BIGINT | Size of the entire table (`before_compression_table_bytes` + `before_compression_index_bytes` + `before_compression_toast_bytes`) before compression. Returns `NULL` if `compression_status` == `Uncompressed`. |
| `after_compression_table_bytes`  | BIGINT | Size of the heap after compression. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                                   |
| `after_compression_index_bytes`  | BIGINT | Size of all the indexes after compression. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                            |
| `after_compression_toast_bytes`  | BIGINT | Size the TOAST table after compression. Returns `NULL` if `compression_status` == `Uncompressed`.                                                                                                               |
| `after_compression_total_bytes`  | BIGINT | Size of the entire table (`after_compression_table_bytes` + `after_compression_index_bytes `+ `after_compression_toast_bytes`) after compression. Returns `NULL` if `compression_status` == `Uncompressed`.     |
| `node_name`                      | NAME   | nodes on which the {HYPERTABLE} is located, applicable only to distributed {HYPERTABLE}s. Returns `NULL` if `compression_status` == `Uncompressed`.                                                             |

[hypertable-docs]: /manage-data/capabilities/hypertables

[tsdb-2.18.0]: https://github.com/timescale/timescaledb/releases/tag/2.18.0
