> ## 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.

# chunk_columnstore_stats()

> Get statistics about chunks in 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>
  `chunk_columnstore_stats()` replaces `chunk_compression_stats()`, deprecated in 2.18.0. The parameters are the same.
</Info>

Retrieve statistics about the {CHUNK}s in the {COLUMNSTORE}

`chunk_columnstore_stats` returns the size of {CHUNK}s in the {COLUMNSTORE}, these values are computed when you call
either:

* [CREATE TABLE][hypertable-create-table]: create a {HYPERTABLE} with a default [job][job] that automatically
  moves {CHUNK}s in a {HYPERTABLE} to the {COLUMNSTORE} at a specific time interval.
* [add\_columnstore\_policy][add_columnstore_policy]: create a [job][job] on an existing {HYPERTABLE} that automatically
  moves {CHUNK}s in a {HYPERTABLE} to the {COLUMNSTORE} at a specific time interval.
* [convert\_to\_columnstore][convert_to_columnstore]: manually add a specific {CHUNK} in a {HYPERTABLE} to the
  {COLUMNSTORE}.

Inserting into a {CHUNK} in the {COLUMNSTORE} does not change the {CHUNK} size. For more information about how to
compute
{CHUNK} sizes, see [chunks\_detailed\_size][chunks_detailed_size].

## Samples

To retrieve statistics about {CHUNK}s:

* **Show the status of the first two {CHUNK}s in the `conditions` {HYPERTABLE}**:
  ```sql theme={"dark"}
  SELECT * FROM chunk_columnstore_stats('conditions')
    ORDER BY chunk_name LIMIT 2;
  ```
  Returns:
  ```sql theme={"dark"}
  -[ RECORD 1 ]------------------+----------------------
  chunk_schema                   | _timescaledb_internal
  chunk_name                     | _hyper_1_1_chunk
  compression_status             | Uncompressed
  before_compression_table_bytes |
  before_compression_index_bytes |
  before_compression_toast_bytes |
  before_compression_total_bytes |
  after_compression_table_bytes  |
  after_compression_index_bytes  |
  after_compression_toast_bytes  |
  after_compression_total_bytes  |
  node_name                      |
  -[ RECORD 2 ]------------------+----------------------
  chunk_schema                   | _timescaledb_internal
  chunk_name                     | _hyper_1_2_chunk
  compression_status             | Compressed
  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` to return a more human friendly format**:

  ```sql theme={"dark"}
  SELECT pg_size_pretty(after_compression_total_bytes) AS total
    FROM chunk_columnstore_stats('conditions')
    WHERE compression_status = 'Compressed';
  ```

  Returns:

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

## Arguments

The syntax is:

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

| Name         | Type       | Default | Required | Description                |
| ------------ | ---------- | ------- | -------- | -------------------------- |
| `hypertable` | `REGCLASS` | -       | ✔        | The name of a {HYPERTABLE} |

## Returns

| Column                           | Type   | Description                                                                                                                                                                                                           |
| -------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `chunk_schema`                   | NAME   | Schema name of the {CHUNK}.                                                                                                                                                                                           |
| `chunk_name`                     | NAME   | Name of the {CHUNK}.                                                                                                                                                                                                  |
| `compression_status`             | TEXT   | Current compression status of the {CHUNK}.                                                                                                                                                                            |
| `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 chunk 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 {CHUNK} table (`after_compression_table_bytes` + `after_compression_index_bytes `+ `after_compression_toast_bytes`) after compression. Returns `NULL` if `compression_status` == `Uncompressed`.   |
| `node_name`                      | NAME   | **DEPRECATED**: nodes the {CHUNK} is located on, applicable only to distributed {HYPERTABLE}s.                                                                                                                        |

[add_columnstore_policy]: /api-reference/timescaledb/hypercore/add_columnstore_policy

[chunks_detailed_size]: /api-reference/timescaledb/hypertables/chunks_detailed_size

[convert_to_columnstore]: /api-reference/timescaledb/hypercore/convert_to_columnstore

[hypertable-create-table]: /api-reference/timescaledb/hypertables/create_table

[job]: /api-reference/timescaledb/jobs-automation/add_job

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