KDB knowledge

Keep data page (how long tables keep their rows)

See every table of a database with how long it keeps its rows, and set "keep only the last N months or years": the older days, months or years are dropped, the newest stay.

The Keep data page of the web console (Home menu) lists every table of the chosen database and lets you say how long each keeps its rows. Nothing is dropped from the start of the table: it keeps the newest data and lets the oldest go.

The screen

+------------------------------------------------------------------------------------------+
| Keep data   database nchart006                                                [Refresh]  |
| [x] all   For the 3 ticked: keep the last [6] [months v]  [Keep] [Keep everything] [Drop older now] |
|                                                                                          |
|   | table         | kind              | rows   | on disk | data from / to           | keeps           |                              |
| [x]| Daily_Filter  | time-series, DAY  | 11.5M  | 890 MB  | 2022-01-25 to 2026-09-11 | the last 6 months | [6][months v] [Keep] [Drop older now] [Everything] |
| [ ]| floorsheet_v1 | time-series, DAY  | 69.3M  | 5.3 GB  | 2022-01-25 to 2026-09-11 | everything        | [6][months v] [Keep] [Drop older now]              |
| [ ]| bg_config     | relational        | 2      | 4 KB    | no partitions            | everything (no partitions to drop)                                    |
+------------------------------------------------------------------------------------------+
PartWhat it is
rows, on diskthe table's row count and the bytes its files take
data from / tothe oldest and newest time in the table (read from the block statistics, so it costs nothing)
keepseverything, or the last 6 months: the table's TTL
Keepsets the TTL: ALTER TABLE t SET TTL 6 MONTHS. From then on KDB drops, every minute and by itself, every partition whose last moment is older than that
Everythingtakes the TTL off: ALTER TABLE t SET TTL NONE
Drop older nowone drop, now: ALTER TABLE t DROP PARTITION OLDER THAN 6 MONTHS. It shows the statement and asks first
the top barthe same three for every ticked table at once (Keep everything takes the TTL off them)
Refreshreads the tables and the disk box again

The period is a number and a unit: days, weeks, months or years.

Disk space

The box at the top says what the database takes on disk, part by part. It reads GET /api/disk, which walks the trash folder, so it is asked for on this page only. Hover a part to see how many files it holds.

PartWhat it isField of /api/disk
On diskeverything below togethertotal_bytes
datathe current version of every data file: the rows. Of those, tail files are rows appended after a partition's file, folded back into it later, and delta files the rows of a partition replaced or deleteddata_bytes, data_files; tails tail_bytes, tail_files; deltas delta_bytes, delta_files
older copiesolder versions of the data files, kept so a damaged file can be repaired from one of them (2 per file unless keep_versions says otherwise; a version whose old log is gone can repair nothing and goes by itself)previous_bytes, previous_files
trashreplaced files nothing needs any more; the server removes them by itself once they are older than trash_keep_hours (1 hour unless set), or when the trash is over trash_max_mb (a quarter of the data, at least 256 MB, unless set)trash_bytes, trash_folders
logthe current log, and old log kept for repairs and backups (wal_archive)wal_bytes + wal_archive_bytes

Save disk (admin) runs PURGE VERSIONS KEEP 1, which leaves one older copy per file, then PURGE TRASH, and shows the space that came back. Dropping partitions frees their files the same way: they go to the trash first, and the trash goes on its own.

Example: What the Keep button runs

Setup:

CREATE TABLE trades (time TIMESTAMP, symbol SYMBOL, qty LONG) TIMESERIES(time) PARTITION BY MONTH;
ALTER TABLE trades SET TTL 6 MONTHS;
SHOW CREATE TABLE trades;

Result:

ALTER TABLE trades SET TTL 6 MONTHS

table 'trades' drops partitions older than 6 MONTHS

SHOW CREATE TABLE trades

create_sql (STRING)
CREATE TABLE trades ( time TIMESTAMP, symbol SYMBOL, qty LONG ) TIMESERIES(time) PARTITION BY MONTH SORT BY (symbol, time) TTL 6 MONTHS

(1 row)