Format:LevelDB database
| Magic | footer ends with 57 FB 80 8B 24 75 47 DB (0xdb4775248b80fb57 little-endian) |
|---|---|
| Extensions | .log, .ldb, .sst, MANIFEST-*, CURRENT, LOCK, LOG |
| Endianness | little (fixed ints), varints |
| License | BSD-3-Clause |
| Website | https://github.com/google/leveldb |
| On this wiki | Facts · Code · Notes · Topics |
Google LevelDB's on-disk directory: 32 KB-block write-ahead logs (.log), sorted tables (.ldb/.sst) ending in a footer with magic 0xdb4775248b80fb57, a MANIFEST-NNNNNN log of version edits and a CURRENT pointer. Used by Chromium/Electron Local Storage and IndexedDB and many desktop apps.
Overview
A LevelDB database is a directory, not a single file. Keys and values are arbitrary byte strings kept sorted by a comparator (default bytewise; applications such as Chromium IndexedDB use a custom comparator named in the MANIFEST). See Library:LevelDB for the library and Format:RocksDB database for the Facebook fork, which keeps the same log framing but a different table footer.
Directory layout
File names are built in db/filename.cc: NNNNNN.log (write-ahead log, newest writes), NNNNNN.ldb (sorted table; older versions used .sst, readers accept both), MANIFEST-NNNNNN (six-digit number), CURRENT (text file naming the live MANIFEST), LOCK, LOG / LOG.old (text info log) and NNNNNN.dbtmp (temporary). The same number space is shared by logs, tables and manifests.
Log file format (.log and MANIFEST)
The file is a sequence of 32768-byte blocks (the last may be partial). Each record has a 7-byte header: checksum uint32 (little-endian, masked crc32c of the type byte plus data), length uint16 (little-endian), type uint8, then length bytes. Types: FULL=1, FIRST=2, MIDDLE=3, LAST=4. A record never starts in the last six bytes of a block; leftover bytes are zero and skipped. A user record bigger than the room left is split into FIRST/MIDDLE/LAST fragments. To resync after corruption a reader just skips to the next 32 KB boundary.
The stored CRC is masked: rotate right by 15 then add 0xa282ead8 (kMaskDelta in util/crc32c.h). Computing a plain crc32c and comparing will fail.
A user record in a .log file is a WriteBatch (db/write_batch.cc: header size 12). The header is an 8-byte sequence number followed by a 4-byte entry count (kHeader = 12, comment in write_batch.cc), both fixed little-endian. Entries are a tag byte (1 = kTypeValue put, 0 = kTypeDeletion) then a varint-length-prefixed key and, for puts only, a varint-length-prefixed value; entry i gets sequence number base + i (Fact:LevelDB database/struct/WriteBatch record).
Table file format (.ldb / .sst)
Layout: data blocks, meta blocks (e.g. a filter block named filter.<policy name> in the metaindex), metaindex block, index block, 48-byte footer. Each block on disk is followed by a 5-byte trailer (table/format.h kBlockTrailerSize): compression type byte (0 none, 1 Snappy, 2 Zstd per include/leveldb/options.h) and a masked crc32c covering the block plus the type byte (table_builder.cc). Snappy blocks are raw Snappy, see Format:Snappy.
The footer is fixed at 48 bytes at the end of the file: metaindex BlockHandle and index BlockHandle (each offset varint64 + size varint64), zero padding to 40 bytes, then the 8-byte magic 0xdb4775248b80fb57 stored little-endian (bytes 57 FB 80 8B 24 75 47 DB). The magic is the leading 64 bits of the SHA-1 of the old project URL (comment in table/format.h). Look at a file's last 8 bytes to identify a table.
Inside a block (table/block_builder.cc) entries are prefix compressed: shared_bytes varint32, unshared_bytes varint32, value_length varint32, key delta, value. Every N-th key (a restart point) has shared_bytes 0. After the entries come uint32 restart offsets and a uint32 restart count. Keys in tables are internal keys: the user key followed by 8 fixed little-endian bytes holding (sequence << 8) | type, type 1 value, 0 deletion; the sequence is at most 2^56 - 1 (PackSequenceAndType in db/dbformat.cc, kMaxSequenceNumber in db/dbformat.h). A deleted key can therefore still be found in older tables and logs (Fact:LevelDB database/struct/Internal key). The comparator orders user key ascending, then sequence descending (InternalKeyComparator::Compare in db/dbformat.cc: user key by the user comparator, then the 8-byte trailer number descending; see Fact:LevelDB database/behavior/InternalKeyComparator ordering).
MANIFEST
The MANIFEST is a log-format file whose records are VersionEdits: varint tags with payload (db/version_edit.cc). Tags: 1 comparator name, 2 log number, 3 next file number, 4 last sequence, 5 compact pointer, 6 deleted file, 7 new file, 9 previous log number (8 retired). It lists which tables belong to which level; files not listed are obsolete. CURRENT contains the name of the active MANIFEST without the directory, plus a newline; it is replaced atomically by writing a temporary file and renaming it (SetCurrentFile in db/filename.cc). Tag 8 was once used for large value refs and is never written now.
Reversing notes
- Compressed values (Snappy) need decompression before the structure is readable; Chromium stores V8-serialized values for IndexedDB, see Format:Chromium IndexedDB on LevelDB and Format:Chromium Local Storage on LevelDB.
- Copy the directory (including the newest .log and MANIFEST) before opening it with a library; opening replays the log and may compact, modifying files.
- Unverified: Chromium carries its own fork of leveldb; the layout above is from google/leveldb.
Code & repositories
- https://github.com/google/leveldb @
bb74ef739973a70ca9f0d90788a1da89b788c0ad· license: BSD-3-Clause (read from LICENSE; GitHub's API was busy)
Reference LevelDB implementation; doc/log_format.md and doc/table_format.md define the file formats.
Tested on: source read, not run: read source and docs · checked 2026-10-18
See also
Library:LevelDB, Format:Snappy, Format:RocksDB database, Format:SQLite database file, Format:LMDB database file