Question

I'm using Berkeley DB for a lot of my data management needs. I notice, however, that when I delete a large set of values from a database, the actual size of the database file on disk doesn't seem to shrink, ever. I'm guessing that BSD DB simply deallocates the records internally in the file, without actually reclaiming parts of it that shouldn't need to be used anymore.

I've been searching through the API, but I cannot find any way to make BSD DB actually "clean up" in the file and reclaim pages. Is there one that I've simply missed, or is the only way to create a smaller DB file to create a new one from the existing data and replace the old one?

I'm using various versions through 4.8 to 5.3, but I don't imagine that should matter a whole lot.

Était-ce utile?

La solution

You want DB->compact(). From the C API reference:

The DB->compact() method compacts Btree, Hash, and Recno access method databases, and optionally returns unused Btree, Hash or Recno database pages to the underlying filesystem.

http://docs.oracle.com/cd/E17076_02/html/api_reference/C/frame_main.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top