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

# move_chunk()

> Move a chunk and its indexes to a different tablespace

export const PG = 'Postgres';

export const CHUNK_CAP = 'Chunk';

export const CHUNK = 'chunk';

export const HYPERTABLE_CAP = 'Hypertable';

export const HYPERTABLE = 'hypertable';

<Tag>Community</Tag>

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

TimescaleDB allows you to move data and indexes to different tablespaces. This
allows you to move data to more cost-effective storage as it ages.

The `move_chunk` function acts like a combination of the
[{PG} CLUSTER command][postgres-cluster] and
[{PG} ALTER TABLE...SET TABLESPACE][postgres-altertable] commands. Unlike
these {PG} commands, however, the `move_chunk` function uses lower lock
levels so that the {CHUNK} and {HYPERTABLE} are able to be read for most of the
process. This comes at a cost of slightly higher disk usage during the
operation. For a more detailed discussion of this capability, see the
documentation on [managing storage with tablespaces][manage-storage].

<Note>
  You must be logged in as a super user, such as the `postgres` user,
  to use the `move_chunk()` call.
</Note>

## Samples

```sql theme={"dark"}
SELECT move_chunk(
  chunk => '_timescaledb_internal._hyper_1_4_chunk',
  destination_tablespace => 'tablespace_2',
  index_destination_tablespace => 'tablespace_3',
  reorder_index => 'conditions_device_id_time_idx',
  verbose => TRUE
);
```

## Arguments

The syntax is:

```sql theme={"dark"}
SELECT move_chunk(
    chunk = '<chunk_name>',
    destination_tablespace = '<tablespace_name>',
    index_destination_tablespace = '<tablespace_name>',
    reorder_index = '<index_name>',
    verbose = true | false
);
```

| Name                           | Type     | Default | Required | Description                                                                      |
| ------------------------------ | -------- | ------- | -------- | -------------------------------------------------------------------------------- |
| `chunk`                        | REGCLASS | -       | ✔        | Name of {CHUNK} to be moved                                                      |
| `destination_tablespace`       | NAME     | -       | ✔        | Target tablespace for {CHUNK} being moved                                        |
| `index_destination_tablespace` | NAME     | `NULL`  | ✖        | Target tablespace for index associated with the {CHUNK} you are moving           |
| `reorder_index`                | REGCLASS | -       | ✖        | The name of the index (on either the {HYPERTABLE} or {CHUNK}) to order by        |
| `verbose`                      | BOOLEAN  | `FALSE` | ✖        | Setting to true displays messages about the progress of the move\_chunk command. |

## Returns

This function returns void.

[manage-storage]: /use-timescale/schema-management/about-tablespaces/

[postgres-altertable]: https://www.postgresql.org/docs/13/sql-altertable.html

[postgres-cluster]: https://www.postgresql.org/docs/current/sql-cluster.html

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