Versions:

You can control how long metric and trace data is retained in Promscale.

A maintenance job periodically removes metric and trace data that is outside the defined retention period. In TimescaleDB 2.0 and above, the maintenance job is automatically scheduled using the job scheduling function. If you are using an earlier version of TimescaleDB, you can use cron or a similar scheduling tool to schedule the maintenance task. See the installation instructions for your platform for more details.

Metric data has an automated retention that drops data after a certain age. The default retention is 90 days which can be customized. It is also possible to configure a specific retention for a metric. This is typically used if you want to keep certain important metrics for longer to do trend analysis or for audit purposes while not incurring the higher storage costs of having to keep all metrics for longer.

Get the currently configured default retention for metrics using the prom_api.get_default_retention_period() function, like this:

SELECT prom_api.get_default_metric_retention_period();

Change the default retention period for metrics by adjusting the retention_period parameter of the function prom_api.set_default_retention_period(retention_period INTERVAL):

SELECT prom_api.set_default_retention_period(30 * INTERVAL '1 day');

If you have specific metrics you need to retain for longer, use the function prom_api.set_metric_retention_period(metric_name TEXT, new_retention_period INTERVAL):

SELECT prom_api.set_metric_retention_period('container_cpu_usage_seconds_total', 180 * INTERVAL '1 day');

You can retrieve which retention is being used for a specific metric, using the prom_api.get_metric_retention_period(metric_name TEXT) function:

SELECT prom_api.get_metric_retention_period('container_cpu_usage_seconds_total');

If no specific retention has been set for the metric, this returns the default retention.

Reset an overridden metric retention period to the default by using the function prom_api.reset_metric_retention_period(metric_name TEXT)

SELECT prom_api.reset_metric_retention_period('container_cpu_usage_seconds_total');

When you change the default retention period, any metrics that have a specific retention configured keep that retention, unless you reset it.

The _ps_trace.span, _ps_trace.event, and _ps_trace.link hypertables have an automated data retention policy which drops chunks beyond a certain age. By default, the retention period is 30 days, or you can use the ps_trace.get_trace_retention_period() function to get the current trace retention period:

SELECT ps_trace.get_trace_retention_period();

You can change the retention period by adjusting the trace_retention_period parameter of the function ps_trace.set_trace_retention_period(trace_retention_period INTERVAL):

SELECT ps_trace.set_trace_retention_period(30 * INTERVAL '1 day');

Found an issue on this page?

Report an issue!

Keywords

Related Content