The data folder size increases after deleting records

I am creating a disk space watchdog for my app which uses couchbase server 6.0 community on a single node. I’d like to delete older documents if the occupied disk space for couchbase data exceeds a threshold.
Is there a recommended way to do so?

Currently, I am planning to measure the size of the data folder (/opt/couchbase/var/lib/couchbase/data in Linux) and delete records from Scala SDK using remove (eq to N1QL DELETE). However, I noticed after I delete a bunch of records using the web console with N1QL DELETE, the size of the data folder increases. Specifically, the size of every related index item in data/@2i goes up.

Why is this happening? How can I actually release disk space occupied by older data?


Check out the docs on compaction. Effectively, with Couchbase an initial delete is really a write of a tombstone, then the file reduction happens later. You can probably tune the thresholds to get what you want though.

Thanks! I’ll check it out.