Adding Retention Policies to already existing database

Is it possible to create a RP to an already existing database with > 2 years data?

I believe all the data will be deleted immediately after creating the RP. Why does this happen?

Is it possible to create a RP to an already existing database with > 2
years data?

What is the retention policy you wish to apply?

I believe all the data will be deleted immediately after creating the RP.

All the data which is not included in the retention policy will be deleted,
yes, and the rest will be retained.

Why does this happen?

Er, because the retention policy says not to keep the data which got deleted?

Give us a specific example of the policy you’re applying, with a summary of the
date range your data covers (how recent as well as how old), and tell us what
gets deleted (or what gets retained) after applying the policy.

Antony.

Thank you for offering help! Let me explain:

Give us a specific example of the policy you’re applying, with a summary of the
date range your data covers (how recent as well as how old), and tell us what
gets deleted (or what gets retained) after applying the policy.

So to understand how RP’s work on already existing databases (without any previous RP’s), I made a small test on an empty DB.

> INSERT treasures,captain_id=pirate_king value=5
> INSERT treasures,captain_id=pirate_king value=10
> INSERT treasures,captain_id=pirate_king value=20

After inserting, data seems to be there:

> select * from treasures
name: treasures
time                captain_id  value
----                ----------  -----
1601467009258052600 pirate_king 5
1601467009513793900 pirate_king 10
1601467009517316300 pirate_king 20

But then, if I create the retention policy to delete data after two hours, and I select data again, this data is gone. Even though it hasn’t been two hours yet.

> create retention policy "two hours" on "mydb" duration 2h replication 1 default
> select * from treasures
>

Result is empty, but this data was inserted just 1 min before creating a Retention Policy that should remove data older than 2h.

How can I make sure that creating the Retention Policy on a database (which is filled with data) doesn’t remove recent data?

Hi Karimchito,

It seems the most likely explanation is that the old data is still in the original Retention Policy (“autogen”, I assume). If data is written prior to the creation of a new retention policy, the data will be in the old retention policy.

You can see your current Retention Policies by using a SHOW RETENTION POLICIES command…

Try selecting the data from “database_name”.“retention_policy_name”.“measurement_name”:

select * from “mydb”.“autogen”.“treasures”
or
select * from “autogen”.“treasures”

Once you create a new retention policy and set it as default, future writes will go “in the new retention policy”, but the past data won’t move between retention policies. You would need to use an INTO statement (or something) to move the data from the old retention policy to the new retention policy.

I hope that helps.