Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
mdbx-rs
A pure Rust reimplementation of libmdbx - an extremely fast embedded key-value database.
Acknowledgments
This project is a Rust reimplementation based on libmdbx by Leonid Yuriev (Леонид Юрьев). We extend our sincere thanks for creating such an excellent database engine that served as the foundation for this work.
The original libmdbx is a remarkably well-engineered embedded database with exceptional performance characteristics. This Rust implementation aims to provide the same capabilities with memory safety guarantees.
How This Crate Works
This crate provides low-level C-style FFI bindings. At build time, it downloads prebuilt static libraries from GitHub Releases:
- Repository: igor53627/mdbx-rs-releases
- Artifacts:
mdbx-rs-{platform}.tar.gz - License: Apache-2.0
Source Code Availability
The Rust source code is currently in a private repository while we work toward production quality. Once the implementation is stable and well-tested, we plan to open-source the full codebase to enable community contributions.
In the meantime, this crate provides prebuilt binaries that are binary-compatible with C libmdbx databases.
Performance
Pure Rust mdbx-rs now outperforms C libmdbx on all operations.
Benchmarks on x86_64 Linux (AMD EPYC) with 1M entries (20-byte keys, 32-byte values):
| Operation | Rust mdbx-rs | C libmdbx | Rust Advantage |
|---|---|---|---|
| PUT | 2.1M/sec | 2.1M/sec | Parity |
| GET | 4.5M/sec | 4.0M/sec | 15% faster |
| CURSOR | 55.7M/sec | 40.8M/sec | 37% faster |
These results are achieved with Profile-Guided Optimization (PGO), which is enabled by default in release builds.
Key Optimizations
- Zero-copy reads - Returns borrowed slices directly into mmap
- Unchecked page access - Removes bounds checking in release mode
- Optimized binary search - SIMD key comparison for fixed-size keys
- Byte-balanced page splits - Optimal page fill reduces DB size
Installation
[]
= "0.2"
Quick Start
use *;
use CString;
Configuring Database Size
By default, the database will grow automatically but may hit size limits. Use mdbx_env_set_geometry before mdbx_env_open to configure:
use *;
unsafe
If you encounter MDBX_MAP_FULL (-30797), increase size_upper before opening.
Troubleshooting
SIGBUS on Large Databases (1TB+)
Fixed in v0.2.21. Earlier versions could crash with SIGBUS when writing to large databases because tree splits can allocate 1000+ pages at once. If the file wasn't pre-extended, writes to mmap'd regions beyond EOF caused SIGBUS.
Solution: Upgrade to v0.2.21 or later.
What changed:
- Pager now uses
geometry.size_upperfor the mmap virtual address range - File is extended at
env_openifmetadata.size_now > file_size - Before allocating pages, file is pre-extended by
growth_step(default 16MB)
MDBX_CORRUPTED (-30796)
If your database was corrupted by previous SIGBUS crashes, you'll need to restore from backup or resync from scratch.
Supported Platforms
| Platform | Artifact |
|---|---|
| Linux x86_64 | mdbx-rs-linux-x86_64.tar.gz |
| macOS Apple Silicon | mdbx-rs-macos-aarch64.tar.gz |
Offline Builds
By default, mdbx-rs downloads prebuilt binaries during cargo build.
To use a locally built library (for offline/air-gapped builds):
Compatibility
- Binary compatible with C libmdbx databases (format version 0.13.x)
- No migration required for existing databases
API Level
This crate exposes the low-level C-style FFI API. All database operations require unsafe blocks. A higher-level safe Rust wrapper may be provided in a future release.
License
Apache 2.0
Prebuilt Artifacts
Release archives contain only C-compatible libraries:
libmdbx_rs.a- Static library (staticlib)libmdbx_rs.so/libmdbx_rs.dylib- Dynamic library (cdylib)
Note: .rlib files are not included. The .rlib format is Rust-internal and not stable across compiler versions. If you need to use mdbx-rs from Rust code with full optimization (inlining, LTO), depend on the source crate and let Cargo build from source.
Supported Platforms
| Platform | Artifact |
|---|---|
| Linux x86_64 | mdbx-rs-linux-x86_64.tar.gz |
| macOS ARM64 | mdbx-rs-macos-aarch64.tar.gz |
Usage from C/C++
// Link with: -lmdbx_rs -lpthread -ldl -lm
extern int ;
extern int ;
// ... see mdbx.h for full API
Usage from Rust (via this crate)
[]
= "0.2"
The build script automatically downloads and links the appropriate prebuilt library.