HomeMogDBMogDB StackUqbar

Documentation:v1.1

Supported Versions:

CREATE TIMESERIES POLICY

Function

Used to create a new data retention policy under the current database.

Precautions

  • The name of the newly created data retention policy cannot be renamed with an existing retention policy.

  • The value of duration should be greater than or equal to that of chunkGroupDuration.

  • duration and chunkGroupDuration are formatted as number + time unit. If the number entered is not an integer, it will be rounded upwards, e.g. 1.2 weeks will be rounded to 2 weeks.

  • duration and chunkGroupDuration do not support negative numbers, duration and chunkGroupDuration support the minimum time unit is 1 hour, if the value set is less than 1 hour will be automatically set to 1 hour.

  • The value unit of duration and chunkGroupDuration can be hour, day, week, month, and year.

  • The value range of each unit needs to meet the following condition.

    Unit Upper Limit Lower Limit
    Year 0 296533
    Month 0 3558399
    Week 0 15250284
    Day 0 106751991
    Hour 0 2147483647

Syntax Format

CREATE TIMESERIES POLICY [ IF NOT EXISTS ] policy_name WITH (option = value, [...] )

option includes:

  • duration: indicates the time-series data retention duration. If the retention duration is exceeded, data will be automatically deleted by chunk group. The value should be greater than or equal to 1 hour. The value can also be 0, indicating that data is permanently reserved meanwhile the time unit can be second, minute, hour, day, week, month, and year.

  • chunkGroupDuration: indicates the temporal granularity. The value cannot be set to 0.

    If this parameter is not specified, the system automatically sets it in terms of the duration parameter. The following are rules to be followed:

    • If the duration value is lower than 2 days, set chunkGroupDuration to 1 hour. It means that the start time of chunkGroupDuration should be an integer, such as 2020-07-10 00:00:00 and 2020-07-10 01:00:00 rather than 2020-07-10 00:10:00 and 2020-07-10 00:10:10.
    • If the duration value is lower than or equal to 6 months, set chunkGroupDuration to 1 day. It means that the chunkGroupDuration value can be a value like 2020-07-10 00:00:00 and 2020-07-11 00:00:00.
    • If the duration value is greater than 6 months, set chunkGroupDuration to 7 days. It means that the start day of the chunkGroupDuration value should be Monday of a week.
    • If the duration value is greater than 3 years, set chunkGroupDuration to 1 month. It means that the start date of the chunkGroupDuration value should be the first day of a month.

The upper limits of duration and chunkGroupDuration are 231.

There is a default data retention policy named 'infinity' under each database. The default policy has duration='0s', which means the data will never be deleted. chunkGroupDuration='1month'.

Examples

Uqbar=# CREATE TIMESERIES POLICY policy_test WITH (duration = '2 years', chunkGroupDuration='7 days');
CREATE POLICY

ALTER TIMESERIES POLICY, DROP TIMESERIES POLICY

Copyright © 2011-2024 www.enmotech.com All rights reserved.