Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:LMDB database file

From ReverseEngineering.wiki
Format
Magic DE C0 EF BE (0xBEEFC0DE) right after the page header of page 0
Extensions data.mdb, lock.mdb
License OpenLDAP Public License
Website https://github.com/LMDB/lmdb
On this wiki Facts · Code · Notes · Topics

LMDB's data.mdb: a memory-mapped copy-on-write B+tree of fixed-size pages, two alternating meta pages (pages 0 and 1) holding magic 0xBEEFC0DE and a data version (1 in the 0.9.x releases, 3 on the mdb.master3 branch), plus a separate lock.mdb.

Overview

An LMDB environment is a directory with data.mdb (the database) and lock.mdb (reader table, not needed to read the data). With MDB_NOSUBDIR the data file itself is the path and the lock file gets a -lock suffix (names in mdb.c). Read from the 0.9 release branch (0.9.36 in lmdb.h) and the default branch mdb.master3 (commit 253ba52).

Pages

The file is an array of pages of the system page size (commonly 4096; recorded in the meta page as mm_psize, stored in the free-DB record's md_pad). Pages 0 and 1 are meta pages; transaction N writes meta page N mod 2, so the live snapshot is the meta page with the higher txnid. Page flags (mdb.c): P_BRANCH 0x01, P_LEAF 0x02, P_OVERFLOW 0x04, P_META 0x08, P_LEAF2 0x20 (fixed-size dup keys), P_SUBP 0x40 (duplicate sub-page). Branch and leaf pages hold a sorted array of node offsets at the front and nodes growing down from the end. Node flags: F_BIGDATA 0x01 (value on overflow pages), F_SUBDATA 0x02 (value is a sub-database record), F_DUPDATA 0x04.

Page header: in the 0.9 release it is 16 bytes (page number 8, pad 2, flags 2, lower 2, upper 2; PAGEHDRSZ = offsetof(MDB_page, mp_ptrs)). On the mdb.master3 branch the header also holds a transaction id, so it is longer (24 bytes when page numbers and transaction ids are 8 bytes, 16 bytes in a 32-bit build without MDB_VL32; mdb.c lines 1039-1075, Fact:LMDB database file/struct/MDB page header).

Meta page

After the page header comes MDB_meta: mm_magic uint32 = 0xBEEFC0DE, mm_version uint32 (MDB_DATA_VERSION: 1 in the 0.9 release, 3 on mdb.master3, 999 in MDB_DEVEL builds), mm_address (pointer-sized), mm_mapsize, two MDB_db records (free-page DB first, main DB second), mm_last_pg, mm_txnid. MDB_db: md_pad uint32, md_flags uint16, md_depth uint16, md_branch_pages, md_leaf_pages, md_overflow_pages, md_entries, md_root. The main DB root and page size are enough to walk the tree; named databases are records in the main DB with F_SUBDATA whose value is an MDB_db.

Layout summed from member types on a 64-bit build of mdb.master3: Fact:LMDB database file/struct/MDB meta is 136 bytes and Fact:LMDB database file/struct/MDB db 48 bytes, so the magic sits at file offset 24, mm_mapsize at 40 and the page size (mm_dbs[0].md_pad) at 48. The checks a reader applies are in Fact:LMDB database file/identification/LMDB env header checks.

Reversing notes

  • Fields are native-endian and pointer-sized (mdb_size_t, pgno_t): files are not portable between 32-bit and 64-bit builds. Exact sizes for the 64-bit mdb.master3 layout are in the Meta page section; Unverified: the 0.9 release layout and 32-bit builds were not summed.
  • Key order depends on db flags in md_flags (reverse key, integer key, dup sort), not visible from raw data alone.
  • Free pages still hold old copies of pages; the other meta page points at the previous snapshot, handy for recovering overwritten data.
  • Version string format in lmdb.h MDB_VERSION_STRING: "LMDB 0.9.x: (date)".

Code & repositories

  • https://github.com/LMDB/lmdb @ 253ba5219172531b719bc14fee6b4aa1a2a5c4a5 · license: OLDAP-2.8 (declared by the contributor; GitHub's detector did not recognize a license file)
    LMDB source mirror; libraries/liblmdb/mdb.c defines page and meta layouts (default branch mdb.master3, release in mdb.RE/0.9).
    Tested on: source read, not run: read mdb.c · checked 2026-10-18

See also

Format:LevelDB database, Format:SQLite database file