cleanup_stale_data_streams()
cleanup_stale_data_streams( ttl_minutes FLOAT, dry_run BOOLEAN DEFAULT TRUE)Deletes data streams that have not been accessed for longer than the time-to-live (TTL) you specify, in minutes. A data stream counts as accessed whenever a transaction reads from or writes to it, so a stream is stale only when it has gone the full TTL without any access. Streams that have never been accessed are never treated as stale.
By default, the procedure runs in dry-run mode and reports the data streams it would delete without removing anything.
Pass dry_run => FALSE to delete them.
Requires the rai_user application role.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
ttl_minutes | FLOAT | The time-to-live, in minutes. A data stream is deleted only when it has not been accessed for longer than this value. |
dry_run | BOOLEAN | Whether to run without deleting anything. Defaults to TRUE, which reports the data streams that would be deleted. Pass FALSE to delete them. |
Returns
Section titled “Returns”OBJECT
In dry-run mode, the object reports the candidate data streams:
{ "dry_run": true, "would_delete": <number>, "objects": [ <fq_object_name>, ... ] }When dry_run => FALSE, the object reports the result of the deletion:
{ "dry_run": false, "deleted": <number>, "errors": [ ... ] }Example
Section titled “Example”Use api.cleanup_stale_data_streams() to preview the data streams that have not been accessed for longer than a TTL.
The following call reports the data streams not accessed in more than 7 days (10,080 minutes) without deleting them:
CALL relationalai.api.cleanup_stale_data_streams(10080);/*+-------------------------------------------------------------------------------------+ | CLEANUP_STALE_DATA_STREAMS | |-------------------------------------------------------------------------------------| | { | | "dry_run": true, | | "would_delete": 2, | | "objects": [ "example_db.sales.view1", "example_db.hr.employees" ] | | } | +-------------------------------------------------------------------------------------+ */Once you have confirmed the candidates, pass dry_run => FALSE to delete them:
CALL relationalai.api.cleanup_stale_data_streams(10080, dry_run => FALSE);/*+---------------------------------------------------------+ | CLEANUP_STALE_DATA_STREAMS | |---------------------------------------------------------| | { | | "dry_run": false, | | "deleted": 2, | | "errors": [] | | } | +---------------------------------------------------------+ */Use the api.data_streams view’s last_accessed column to inspect when each data stream was last accessed before running a cleanup.