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

# Data retention overview

> TimescaleDB API reference for data retention. Includes SQL functions for adding and removing data retention policies that run on a schedule that you define

export const TIMESCALE_DB = 'TimescaleDB';

export const HYPERTABLE = 'hypertable';

export const CHUNK = 'chunk';

<Icon icon="circle-play" iconType="duotone" /> Community

An intrinsic part of time-series data is that new data is accumulated and old data is rarely, if ever, updated. This
means that the relevance of the data diminishes over time. It is therefore often desirable to delete old data to save
disk space.

With {TIMESCALE_DB}, you can manually remove old {CHUNK}s of data or implement policies using these APIs.

For more information about creating a data retention policy, see the [data retention section][data-retention-howto].

## Samples

### Create a data retention policy to discard chunks greater than 6 months old

```sql theme={"dark"}
SELECT add_retention_policy('conditions', drop_after => INTERVAL '6 months');
```

When you call `drop_after`, the time data range present in the partitioning time column is used to select the target
{CHUNK}s.

### Create a data retention policy with an integer-based time column

```sql theme={"dark"}
SELECT add_retention_policy('conditions', drop_after => BIGINT '600000');
```

### Create a data retention policy to discard chunks created before 6 months

```sql theme={"dark"}
SELECT add_retention_policy('conditions', drop_created_before => INTERVAL '6 months');
```

When you call `drop_created_before`, {CHUNK}s created 3 months ago are selected.

### Remove a retention policy

```sql theme={"dark"}
SELECT remove_retention_policy('conditions');
```

Removes the existing data retention policy for the `conditions` table.

## Available functions

* [`add_retention_policy()`][add_retention_policy]: create a policy to drop {CHUNK}s older than a given interval
* [`remove_retention_policy()`][remove_retention_policy]: remove a policy to drop {CHUNK}s of a particular {HYPERTABLE}

[add_retention_policy]: /api-reference/timescaledb/data-retention/add_retention_policy

[data-retention-howto]: /use-timescale/data-retention/create-a-retention-policy

[remove_retention_policy]: /api-reference/timescaledb/data-retention/remove_retention_policy
