Overview
LDB (LevelDB Tool) is RocksDB’s interactive command-line utility for database inspection, debugging, and administrative operations. It provides a rich set of commands for reading, writing, scanning, and analyzing RocksDB databases without writing custom code.Basic Usage
LDB follows this general syntax:Opening a Database
All LDB commands require specifying the database path:Key Commands
Get - Read a Single Key
Retrieve the value for a specific key:Put - Write a Single Key
1
Simple put
2
Put with hex encoding
3
Batch put
Insert multiple keys from a file:Format: one key-value pair per line (key and value separated by space)
Scan - Iterate Through Keys
Scan all keys in the database:Delete - Remove Keys
1
Delete single key
2
Delete range
Delete all keys in a range:
Database Information Commands
Dump - Export Database Contents
Export entire database to a text file:Load - Import Database Contents
Import from a dump file:Manifest Dump - Inspect MANIFEST File
Examine database metadata and LSM tree structure:List Column Families
Show all column families in a database:Column Family Operations
RocksDB supports multiple column families. LDB can operate on specific column families:Working with Column Families
Create and Drop Column Families
Advanced Commands
WAL Dump - Inspect Write-Ahead Log
Examine WAL files for debugging:Compaction
Manually trigger compaction:Reduce DB Levels
Change the number of levels in the LSM tree:Reducing levels requires careful consideration of your data size and can trigger significant compaction work.
Check Consistency
Verify database integrity:Approximate Size
Estimate size of key range:Common Options
Database Opening Options
Data Encoding Options
Environment Options
Working with Hex Encoding
Why Use Hex?
1
Binary data
When keys or values contain non-printable binary data:
2
Precise byte sequences
When you need exact byte control:
3
Debugging binary formats
When inspecting internal key formats:
TTL Databases
LDB supports databases with Time-To-Live (TTL):Transaction Databases
Work with TransactionDB:Blob Index Decoding
For databases using blob files, decode blob references:Practical Examples
Debug Production Issue
1
Open as secondary
Open production DB safely without interfering:
2
Check key existence
3
Inspect nearby keys
Database Migration
Examine LSM Tree Structure
Cleanup Old Keys
Query Tool (Interactive Mode)
Usedb_queryer for interactive database exploration:
Internal Commands
Internal Dump
Dump internal key format with sequence numbers:SST File Dumper
Examine individual SST files:Performance Considerations
Use
--secondary_path when accessing production databases to avoid write locks and ensure safety.Source Reference
LDB is implemented across several files:include/rocksdb/ldb_tool.h:22-47- Public API interfaceinclude/rocksdb/utilities/ldb_cmd.h:31-200- Command definitions and argument constantstools/ldb_cmd.cc:61-400- Command implementationstools/ldb.cc- Main entry point