NOTE: Changing the default RP on a database with existing data (and an existing RP) will cause your existing data to disappear from the default query view as the old data is still part of a non-default RP. All new data will have the new, default RP. See below to migrate old data to a new RP.
CREATE RETENTION POLICY "one_year" ON "LibreNMS" DURATION 52w REPLICATION 1 DEFAULT
SHOW RETENTION POLICIES ON LibreNMS
Set default policy after creation
ALTER RETENTION POLICY "one_year" ON "LibreNMS" DEFAULT
From the Influx CLI, you can migrate one measurement at a time. Scripting might be easier is you have lots of measurements (foreach measurement
)
SELECT * INTO "db"."newrp"."newmeasurement" FROM "db"."oldrp"."oldmeasurement" GROUP BY *
Drop the old RP to remove the old data (so you don't have a duplicate of the old data)
DROP RETENTION POLICY "oldrp" ON "db"
Useful comment:
To create a 1 year retention policy on an existing database you can use CREATE RETENTION POLICY "one_year" ON "databasename" DURATION 52w REPLICATION 1 DEFAULT Actually that is 52 weeks. Then when you write to a measurement tell it to use that retention policy. A database can have multiple retention policies. This page is a good reference [Edit] In fact, since I included DEFAULT on the policy that will be the default one to use for that database, so you would not need to specify it explicitly when writing/reading. Note that any existing data will not be affected by this as it will have (presumably) been written with the infinite retention period, so if you want that to expire you will have to manually delete it or move it to the new policy, which you can do using something like SELECT * INTO "the_db"."one_year"."the_measurement" FROM "the_db"."autogen"."the_measurement" GROUP BY * then after you have checked that it is there ok DROP RETENTION POLICY "autogen" ON "home" … Source