Expiring data with time-to-live

Use time-to-live (TTL) to expire data in a column or table.

Columns and tables support an optional expiration period called TTL (time-to-live); TTL is not supported on counter columns. Define the TTL value in seconds. Data expires once it exceeds the TTL period and is then marked with a tombstone. Expired data continues to be available for read requests during the grace period, see gc_grace_seconds. Normal compaction and repair processes automatically remove the tombstone data.

Note:
  • TTL precision is one second, which is calculated by the coordinator node. When using TTL, ensure that all nodes in the cluster have synchronized clocks.
  • A very short TTL is not very useful.

  • Expiring data uses additional 8 bytes of memory and disk space to record the TTL and grace period.

Setting a TTL for a specific column

Use CQL to set the TTL.

To change the TTL of a specific column, you must re-insert the data with a new TTL. The database upserts the column with the new TTL.

To remove TTL from a column, set TTL to zero. For details, see the UPDATE documentation.

Setting a TTL for a table

Use CREATE TABLE or ALTER TABLE to define the default_time_to_live property for all columns in a table. If any column exceeds TTL, the entire table is tombstoned.

For details and examples, see Expiring data with TTL example.