Time travel queries
This guide describes how to leverage the time travel feature. This feature helps access historical data at a specific time.
PREMIUM EDITION FEATURE
This is a Premium Edition feature. All Premium Edition features are available out of the box without additional cost on RisingWave Cloud. For self-hosted deployments, users need to purchase a license key to access this feature. To purchase a license key, please contact sales team at sales@risingwave-labs.com.
For a full list of Premium Edition features, see RisingWave Premium Edition.
PUBLIC PREVIEW
This feature is currently in public preview, meaning it is nearing the final product but may not yet be fully stable. If you encounter any issues or have feedback, please reach out to us via our Slack channel. Your input is valuable in helping us improve this feature. For more details, see our Public Preview Feature List.
Prerequisites
Time travel requires the meta store type to be SQL-compatible. We recommend reserving at least 50 GB of disk space for the meta store.
The system parameter time_travel_retention_ms
controls time travel functionality. By default, it’s set to 0
, which means time travel is turned off. To enable time travel, you need to alter this system parameter to a non-zero value.
For example, you can set time_travel_retention_ms
to 86400000
(1 day). Then historical data older than this period will be deleted and no longer accessible.
Enabling time travel will introduce additional overhead to both the meta store and the object store.
Syntax
Specify FOR SYSTEM_TIME AS OF
separately for each table accessing historical data. The following subclauses can be used:
- Unix timestamp in seconds. For example,
SELECT * FROM t_foo FOR SYSTEM_TIME AS OF 1721024455;
. - Datetime. For example,
SELECT * FROM t_foo FOR SYSTEM_TIME AS OF '2000-02-29T12:13:14-08:30';
. - NOW() [ - Interval ]. For example,
SELECT * FROM t_foo FOR SYSTEM_TIME AS OF NOW() - '10' SECOND;
.
If you specify a point in time that is outside the time travel period, the query will return an error, like time travel: version not found for epoch
.
Storage space reclamation
Stale time travel data in both the meta and object stores is automatically removed in the background, freeing up storage space. The default cleanup schedule is as below, which is usually sufficient for most situations.
- The interval to reclaim the meta store is 30 seconds by default. You can change this interval by adjusting the
vacuum_interval_sec
setting. After changing this setting, restart the meta node for it to take effect. - The interval to reclaim the object store is 1 day by default. You can customize this schedule by adjusting two settings:
full_gc_interval_sec
andmin_sst_retention_time_sec
. After modifying these values, restart the meta node to apply the changes.