# Is there a way to set an “expiry” time, after which a data entry is automatically deleted in CrateDB?

**URL:** <https://community.cratedb.com/t/is-there-a-way-to-set-an-expiry-time-after-which-a-data-entry-is-automatically-deleted-in-cratedb/418>\
**Category:** CrateDB\
**Created:** [May 31, 2020, 8:37am UTC](https://community.cratedb.com/t/is-there-a-way-to-set-an-expiry-time-after-which-a-data-entry-is-automatically-deleted-in-cratedb/418 "2020-05-31T08:37:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguel.arregui](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/miguel.arregui/32/126_2.png) [@miguel.arregui](https://community.cratedb.com/u/miguel.arregui)\
**Post date:** [May 31, 2020, 8:37am UTC](https://community.cratedb.com/t/is-there-a-way-to-set-an-expiry-time-after-which-a-data-entry-is-automatically-deleted-in-cratedb/418/1 "2020-05-31T08:37:02Z")

</div>

There are DBs where you can set a `DTL` , so that the data will be deleted in that period of time. Let’s say, table with `DTL=2 months` means that the data in that table, which is older than 2 months, will be deleted.

---

<div class="post-metadata">

**Author:** ![miguel.arregui](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/miguel.arregui/32/126_2.png) [@miguel.arregui](https://community.cratedb.com/u/miguel.arregui)\
**Post date:** [May 31, 2020, 8:53am UTC](https://community.cratedb.com/t/is-there-a-way-to-set-an-expiry-time-after-which-a-data-entry-is-automatically-deleted-in-cratedb/418/2 "2020-05-31T08:53:26Z")

</div>

No, at present CrateDB does not have cron-like functionality for data retention policies. Those are meant to be managed by the user externally.

Say you want to forget about data that is older than 7 days:

```auto
delete from table_name where the_timestamp_column < now() - interval '7 days'

```

You can easily concoct a script to be run by cron overnight. These commands will be helpful:

1.- With [crash](https://github.com/crate/crash):

```auto
crash -c 'delete from table_name where the_timestamp_column < now() - interval '7 days''

```

2.- With postgres client `psql`, assuming CrateDB is listening on port 5433:

```auto
psql -h localhost -p 5433 -U crate -c 'delete from table_name where the_timestamp_column < now() - interval '7 days''

```

Alternatively, you could use [partitioned tables](https://crate.io/docs/crate/reference/en/latest/general/ddl/partitioned-tables.html), by time - e.g. by month, and then you could set the cronjob to delete older partitions.
