Timescaledb: How to delete old records correctly?

Created on 14 May 2018  路  3Comments  路  Source: timescale/timescaledb

Records count:

db=# select count(*) from data_logs ;
   count   
-----------
 141184654
(1 row)

Trying to del old records:

db=# SELECT drop_chunks(interval '36 hours', 'data_logs');
 drop_chunks 
------------- 
(1 row)

Records still in table :

db=# select count(*) from data_logs;
   count   
-----------
 141295446
(1 row)
question

Most helpful comment

The function drop_chunks will only delete a chunk if all of its records are older than the specified time threshold.

http://docs.timescale.com/v0.9/api#drop_chunks

Do you have chunks for which that is true? You can get the time ranges of your chunks via this function:

http://docs.timescale.com/v0.9/api#chunk_relation_size_pretty

Otherwise, if you need specific rows deleted, you can always use DELETE, it's just much less efficient for bulk deletion.

All 3 comments

The function drop_chunks will only delete a chunk if all of its records are older than the specified time threshold.

http://docs.timescale.com/v0.9/api#drop_chunks

Do you have chunks for which that is true? You can get the time ranges of your chunks via this function:

http://docs.timescale.com/v0.9/api#chunk_relation_size_pretty

Otherwise, if you need specific rows deleted, you can always use DELETE, it's just much less efficient for bulk deletion.

@ya-jeks , did @mfreed 's response answer your question (I see your thumbs up reaction :) ). If so, can I close this?

@RobAtticus, yes. Thank you )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sezaru picture sezaru  路  5Comments

shane-axiom picture shane-axiom  路  4Comments

ziXet picture ziXet  路  5Comments

vanwalj picture vanwalj  路  5Comments

100milliongold picture 100milliongold  路  5Comments