Timescaledb: `TRUNCATE TABLE` deletes data but does not remove underlying chunks

Created on 7 Jul 2017  Â·  7Comments  Â·  Source: timescale/timescaledb

I experienced some odd behavior after running TRUNCATE TABLE on a table that has a hyper table. I didn't have time to investigate at the time and re-created the table.

enhancement limitation

Most helpful comment

Just a head's up: PR currently being reviewed: https://github.com/timescale/timescaledb/pull/131

All 7 comments

Hi, thanks for reporting this. When I truncate an hypertable, the existing chunks are not removed although they are empty. Is this the behavior that you saw and found odd ? I think removing the empty chunks on truncate would be a better behavior and will look into fixing it.

Hi @abrkn thanks for this feedback.

We'll look into more expected behavior for TRUNCATE in the future (i.e., delete the existing chunks), but for now, you can turn to our drop_chunks interface for the expected behavior:

 SELECT drop_chunks(NOW() + interval ‘1 year’, tablename)

drop_chunks deletes all chunks if all of their data are beyond the cut-off point (based on chunk constraints). Here I'm just pushing out the leading edge by 1 year to just mean something "way in the future". Not the prettiest interface, but can give you the functionality you want for now.

Also, my testing confirms the same as @olofr : after TRUNCATE, all the data is deleted, just that the existing chunks remain (but now are empty).

Just a head's up: PR currently being reviewed: https://github.com/timescale/timescaledb/pull/131

Fixed as part of 0.3.0 release (by @olofr).

https://github.com/timescale/timescaledb/releases/tag/0.3.0

Hi @abrkn thanks for this feedback.

We'll look into more expected behavior for TRUNCATE in the future (i.e., delete the existing chunks), but for now, you can turn to our drop_chunks interface for the expected behavior:

 SELECT drop_chunks(NOW() + interval ‘1 year’, tablename)

drop_chunks deletes all chunks if all of their data are beyond the cut-off point (based on chunk constraints). Here I'm just pushing out the leading edge by 1 year to just mean something "way in the future". Not the prettiest interface, but can give you the functionality you want for now.

This deletes all chunks ... I guess the drop_chunks() function has evolved since you wrote this, and the behaviour has changed

Just an update truncate table cascade fails with default config it is asking to increase the shared memory limit..

Was this page helpful?
0 / 5 - 0 ratings