timshannon / bolthold

BoltHold is an embeddable NoSQL store for Go types built on BoltDB
MIT License
643 stars 45 forks source link

How to recycle space #47

Closed ystyle closed 5 years ago

ystyle commented 5 years ago

I have insufficient free space on my device. And I delete all logs record form store, Probably use about 5G of log records. But space is not recycled

timshannon commented 5 years ago

BoltHold is built on top of BoltDB. If you look at the documentation for BoltDB and look under Caveats and Limitations you'll see mention of the fact that BoltDB does NOT reclaim disk space:

Because of the way pages are laid out on disk, Bolt cannot truncate data files and return free pages back to the disk. Instead, Bolt maintains a free list of unused pages within its data file. These free pages can be reused by later transactions. This works well for many use cases as databases generally tend to grow. However, it's important to note that deleting large chunks of data will not allow you to reclaim that space on disk.

If you deleted all the records, you can reclaim the space by simply deleting the data file.

If you still have records you want to keep, but still want to reclaim space, you could create a new empty data file, and copy the records over.