Can we change retention period in timescaledb on fly please

Hi guys

Can we change retention period in timescaledb on fly please? Let’s say initially we deployed database with 30 days retention. After 25 days we decided that we need to reduce it to 20 days.

  1. Is it possible please?
  2. What will happen with 5 days that are out of 20 days (new retention limit)? Thanks
1 Like

Very good question @Yi_Sun !

It’s possible. You can create and remove retention policies.

Retention policies are purely background jobs validating conditions to delete old data. If you remove and recreate the retention policy, next time the background job run, it will just adapt to the new limit.

The important thing here is understand that the retention policy is chunk based, which means it will truncate the entire chunk.

  1. What will happen with 5 days that are out of 20 days (new retention limit)? Thanks

So, if your chunk is like a month, and only after 20 days you’re going to clean the data, the earliest row of the chunk will be 50 days because it will wait until the latest data of the chunk is also at least 20 days old.

If your chunk time interval is like 1 day, then it will work very well because every day it will run the policy and clean the old chunks.

Give a try in a sandbox environment to guarantee you don’t end up removing data too early.