---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ydb.tech/docs/en/recipes/ydb-cli/ttl.md?version=main
  - https://ydb.tech/docs/ru/recipes/ydb-cli/ttl.md?version=main
sourcePath: en/core/recipes/ydb-cli/ttl.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Configuring Time to Live (TTL)

This section contains recipes for configuration of table's TTL with YDB CLI.

## Enabling TTL for an existing table {#enable-on-existent-table}

In the example below, the items of the `mytable` table will be deleted an hour after the time set in the `created_at` column:

```bash
$ ydb -e <endpoint> -d <database> table ttl set --column created_at --expire-after 3600 mytable
```

The example below shows how to use the `modified_at` column with a numeric type (`Uint32`) as a TTL column. The column value is interpreted as the number of seconds since the Unix epoch:

```bash
$ ydb -e <endpoint> -d <database> table ttl set --column modified_at --expire-after 3600 --unit seconds mytable
```

## Enabling data eviction to S3-compatible external storage

<!-- source: en/_includes/not_allow_for_oltp_note.md -->
{% note warning %}

<!-- source: en/_includes/not_allow_for_oltp_text.md -->
Supported only for [column-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=main#column-oriented-tables) tables. Support for [row-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=main#row-oriented-tables) tables is currently under development.
<!-- endsource: en/_includes/not_allow_for_oltp_text.md -->

{% endnote %}
<!-- endsource: en/_includes/not_allow_for_oltp_note.md -->

To enable data eviction, an [external data source](https://ydb.tech/docs/en/concepts/datamodel/external_data_source.md?version=main) object that describes a connection to the external storage is needed. Refer to [YQL recipe](https://ydb.tech/docs/en/yql/reference/recipes/ttl.md?version=main#enable-tiering-on-existing-tables) for examples of creating an external data source.

The example below shows how to enable data eviction by executing a YQL-query from YDB CLI. Rows of the table `mytable` will be moved to the bucket described in the external data source `/Root/s3_cold_data` one hour after the time recorded in the column `created_at` and will be deleted after 24 hours.

```bash
$ ydb -e <endpoint> -d <database> sql -s '
    ALTER TABLE `mytable` SET (
        TTL =
            Interval("PT1H") TO EXTERNAL DATA SOURCE `/Root/s3_cold_data`,
            Interval("PT24H") DELETE
        ON modified_at AS SECONDS
    );
'
```

## Disabling TTL {#disable}

```bash
$ ydb -e <endpoint> -d <database> table ttl reset mytable
```

## Getting TTL settings {#describe}

The current TTL settings can be obtained from the table description:

```bash
$ ydb -e <endpoint> -d <database> scheme describe mytable
```

