Skip to main content

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.
LDB is particularly useful for debugging production issues, examining database contents, and performing one-off administrative tasks.

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:
With hex encoding:

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:
Scan with range limits:
Limit number of keys:
Scan without printing values (keys only):

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:
Dump with hex encoding:

Load - Import Database Contents

Import from a dump file:

Manifest Dump - Inspect MANIFEST File

Examine database metadata and LSM tree structure:
Verbose output with detailed file information:

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:
Filter by sequence numbers:

Compaction

Manually trigger compaction:
Compact specific key range:

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)

Use db_queryer for interactive database exploration:
Once in interactive mode:

Internal Commands

Internal Dump

Dump internal key format with sequence numbers:

SST File Dumper

Examine individual SST files:

Performance Considerations

When working with large databases, use --max_keys to limit output:
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 interface
  • include/rocksdb/utilities/ldb_cmd.h:31-200 - Command definitions and argument constants
  • tools/ldb_cmd.cc:61-400 - Command implementations
  • tools/ldb.cc - Main entry point
Build LDB:

Getting Help

Display available commands and options:
Get help for specific command: