Format:Berkeley DB database file
| Developer | Sleepycat Software, Oracle |
|---|---|
| Versions | btree/hash version 9 (oldest supported 8/7), queue 4, heap 1 |
| Magic | 0x00053162 btree, 0x00061561 hash, 0x00042253 queue at offset 12 |
| Extensions | .db, .bdb |
| Endianness | host order of the creating machine |
| On this wiki | Facts · Code · Notes · Topics |
Berkeley DB's single-file databases (btree, hash, queue, heap): page 0 is a metadata page whose bytes 12-15 hold a magic number (btree 0x053162, hash 0x061561, queue 0x042253, heap 0x074582) in the byte order of the machine that created the file, followed by a version and the page size.
Overview
Berkeley DB (BDB, from Sleepycat, now Oracle) is an embedded key-value store used by many older programs (Unverified list: RPM databases, Subversion's BDB back end, Bitcoin Core wallets before 0.21, mail and LDAP servers). A database is one file of fixed-size pages, or a file holding several sub-databases; an environment adds a directory with __db.* region files and log.* transaction logs. There are four access methods: btree (recno shares its pages), hash, queue and heap.
Metadata page
Page 0 is the metadata page (DBMETA, 72 bytes common header) (Fact:Berkeley DB database file/struct/DBMETA): 0 LSN (8 bytes), 8 page number, 12 magic, 16 version, 20 page size, 24 encryption algorithm, 25 page type, 26 meta flags, 28 free list head, 32 last page number, 36 partition count, 40 cached key count, 44 cached record count, 48 flags, 52 unique file id (20 bytes). The method-specific fields (btree minkey, recno record length, root page; hash fill factor and masks) follow at offset 72.
Magic numbers (Fact:Berkeley DB database file/enum/Metadata magic numbers): btree 0x053162, hash 0x061561, queue 0x042253, heap 0x074582, renamed file 0x030800, log file 0x040988. Current versions: btree 9, hash 9, queue 4, heap 1. Because the file is written in the byte order of the machine that created it, the magic reads as 62 31 05 00 on little-endian files and 00 05 31 62 on big-endian ones; readers detect and swap (Fact:Berkeley DB database file/identification/Magic at offset 12).
Page types
The type byte of a page header: 1 duplicate (deprecated), 2 unsorted hash (pre 4.6), 3 btree internal, 4 recno internal, 5 btree leaf, 6 recno leaf, 7 overflow, 8 hash metadata, 9 btree metadata, 10 queue metadata, 11 queue data, 12 off-page duplicate leaf, 13 sorted hash, 14 heap metadata, 15 heap, 16 heap internal (Fact:Berkeley DB database file/enum/Page types).
Reversing notes
- The
fileutility recognises these magics at offset 12 (file/file magic/Magdir/database: 12 long 0x00061561 hash, 12 long 0x00053162 btree, with big- and little-endian variants; it notes that Hash and Btree 2.x and later store metadata in host byte order);db_dumpanddb_verifyfrom the same release read a copy of the file. Python's bsddb/bsddb3 and Java bindings were the common readers. - The metadata page has encrypt_alg at offset 24 and metaflags at offset 26 with DBMETA_CHKSUM 0x01 (src/dbinc/db_page.h, dbmeta33, in berkeleydb/libdb 5e00a8b5e1). Unverified: that a set checksum flag means every page carries a checksum; an encryption algorithm byte other than 0 means the pages are encrypted and cannot be read without the password.
- The unofficial mirror github.com/berkeleydb/libdb carries the Oracle 6.x tree; Oracle changed the license of 6.0 and later to AGPL-3.0 (Unverified: the LICENSE file at libdb 5e00a8b5e1 is the older Oracle redistribution licence, not the AGPL text, so confirm in the LICENSE of the version you use).
Code & repositories
- https://github.com/berkeleydb/libdb @
5e00a8b5e17afac346816a60dbe876b1881c6990· license: LicenseRef-Oracle-Berkeley-DB (declared by the contributor for the files used; GitHub reports BSD-3-Clause (read from LICENSE; GitHub's detector did not classify it) for the repository)
Mirror of the Berkeley DB source; src/dbinc/db_page.h and db.in define page types, metadata structs and magics.
Tested on: source read, not run · checked 2026-10-18; last activity 2026-10-18
See also
Format:LMDB database file, Format:SQLite database file, Format:ESE database (EDB)