Pete Janda
Pete Janda

Reputation: 73

LMDB: How to interpret output from mdb_stat and mdb_dump utilities

I have a functional LMDB that, for test purposes, currently contains only 21 key / value records. I've successfully tested inserting and reading records, and I'm comfortable with the database working as intended.

However, when I use the mdb_stat and mdb_dump utilities, I see the following output, respectively:

Status of Main DB
   Tree depth: 1
   Branch pages: 0
   Leaf pages: 1
   Overflow pages: 0
   Entries: 1

VERSION=3
format=bytevalue
type=btree
mapsize=1073741824
maxreaders=126
db_pagesize=4096
HEADER=END
4d65737361676573

000000000000010000000000000000000100000000000000d81e0000000000001500000000000000ba1d000000000000

DATA=END

In particular, why would mdb_stat indicate only one entry when I have 21? Moreover, each entry comprises 1024 x 300 values of five bytes per value. mdb_dump obviously doesn't show anywhere near the 1,536,000 bytes I'd expect to see, yet the values I mdb_put() and mdb_get() on the fly are correct. Anyone know what's going on?

Upvotes: 2

Views: 1688

Answers (3)

Doug Hoyte
Doug Hoyte

Reputation: 446

Since you are using a sub-database, the number of entries in the main database corresponds to the number of sub-databases you've created (ie just 1).

Try using mdb_stat -a. This will show you a break-down of all the sub-databases (as well as the main DB). In this breakdown it will list the number of entries for each sub-database. Here you should see your 21 entries.

Upvotes: 2

headuck
headuck

Reputation: 2783

4d65737361676573 is the Ascii for "Messages", which is the name of table ("sub-db" in lmdb terminology) storing the actual data in your case.

The mdb_dump command only dumps the main db by default. You can use the -s option to dump that sub-db, i.e.

mdb_dump -s Messages

or you can use the -a option to dump all the sub-dbs.

Upvotes: 2

Pete Janda
Pete Janda

Reputation: 73

The relationship between an operating system's directory and an LMDB environment's data.mdb and lock.mdb files is one-to-one.

If the LMDB environment (in the OS directory) has more than one database, then the environment also contains a separate LMDB database containing all of its named databases.

The mdb_stat and mdb_dump utilities appear to contain minimal logic, so when they are fed a given directory via the command line, they appear to produce results only for the database storing database names and not the database(s) storing the actual data of interest.

Upvotes: 2

Related Questions