Generic retention
Create a generic data retention policy that applies to ALL hypertables, as opposed to just a single one as required by add_retention_policy
. The policy could be further refined with additional filters, by adding a WHERE clause to the PERFORM query in the procedure definition.
CREATE OR REPLACE PROCEDURE generic_retention (job_id int, config jsonb)
LANGUAGE PLPGSQL
AS $$
DECLARE
drop_after interval;
BEGIN
SELECT jsonb_object_field_text (config, 'drop_after')::interval INTO STRICT drop_after;
IF drop_after IS NULL THEN
RAISE EXCEPTION 'Config must have drop_after';
END IF;
PERFORM drop_chunks(format('%I.%I', table_schema, table_name), older_than => drop_after)
FROM timescaledb_information.hypertables;
END
$$;
Register job to run daily dropping chunks on all hypertables that are older than 12 months.
SELECT add_job('generic_retention','1d', config => '{"drop_after":"12 month"}');
当前内容版权归 TimescaleDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 TimescaleDB .