Typorithm · easy

TTL Lifecycle

ttl-lifecycleclickhousettlretentiontiered-storage
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn TTL Lifecycle

0%

Scale & Ops

A TTL clause expires or moves old data — e.g. TTL event_date + INTERVAL 90 DAY DELETE, or TO VOLUME 'cold'.

A TTL (time to live) rule tells ClickHouse when each row's data should be expired based on a date or time column.

With DELETE, rows older than the expression are dropped automatically during background merges — handy for retention windows.

Instead of deleting, TTL ... TO VOLUME 'cold' moves aging parts to cheaper disks, giving tiered storage for warm and cold data.

01

TTL expires or moves rows by age.

02

... DELETE enforces retention windows.

03

... TO VOLUME 'cold' tiers storage.

ALTER TABLE events
MODIFY TTL event_date + INTERVAL 90 DAY DELETE;

Read the implementation

Connect each part of the code to the concept before you type.

1. Modify the table

MODIFY TTL changes the lifecycle rule on an existing table without recreating it.

ALTER TABLE events

2. TTL expression

The TTL expression computes when each row expires, relative to a date column.

MODIFY TTL event_date + INTERVAL 90 DAY

3. Expiry action

DELETE drops expired rows; alternatively TO VOLUME moves them to cheaper storage.

DELETE

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

TTL Lifecycle: Lesson & Practice · Typorithm | ApplyDjinn