I am using the official InfluxDB docker image. I want to set the retention policy to be 14 days
by default.
There are various ENV
variables that I can set to change the config for InfluxDB, such as INFLUXDB_RETENTION_POLICY
. This expects the name of a retention policy such as "default" to be used as the default retention policy.
The problem is that this default policy has a duration of 7 days. I need to set it to 14 days.
The documentation is rather poor. I cannot find any ENV
variable to adjust the default duration. I could also set the INFLUXDB_RETENTION_POLICY
variable to a different name of a different retention policy, but I don't see how I can create that retention policy through configuration.
Is anyone aware of: 1) a way to change the default duration for retention via configuration or 2) a way to create a retention policy through configuration
Unfortunately there is no way to set the default retention policy via the configuration. The reason for this is that typically retention policy duration is defined during database creation.
CREATE DATABASE <database_name>
[WITH [DURATION <duration>] [REPLICATION <n>]
[SHARD DURATION <duration>] [NAME <retention-policy-name>]]
If users were allowed to set a default retention duration via the configuration, the results of the command
CREATE DATABASE mydb
would vary from instance to instance. While this isn't necessarily problematic, it isn't ideal either.
The problem is that this default policy has a duration of 7 days. I need to set it to 14 days.
The default retention policy in InfluxDB should be infinite.
> CREATE DATABASE mydb
> SHOW RETENTION POLICIES ON mydb
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
Here we see that the duration of the retention policy is 0s
which is an alias for infinite and the shard group duration is 168h0m0s
which is 7 days.
I think the main point of confusion here is relatively common--and mostly due to retention policies being poorly named. In InfluxDB an Database is a container for Retention Policies and a Retention Policy is a container for the actual time series data. That is to say a Retention Policy isn't so much of a policy as it as a container that has a policy for all data it contains.
My recommendation would be to always be fully explicit when creating a database in InfluxDB. Doing so will always guarantee that your database will have the correct retention policy duration. So for creating a database with a 14 day retention policy you'd issue the command
CREATE DATABASE mydb WITH DURATION 14d