Repository navigation
Description
LMDB 1.0 was released in June 2026. This release uses a file format that is incompatible with the LMDB 0.9.x version that this repository has been supporting. The [official upgrade documentation](https://github.com/LMDB/lmdb/blob/mdb.master3/libraries/liblmdb/upgrading.doc) recommends using mdb_dump and mdb_load to perform a data migration.
It is not possible to link to both the 0.9.x and 1.0 versions of liblmdb in one program, because they use the same symbol names. This makes it hard to support both versions at the same time in lmdb-go and similar wrappers like [py-lmdb (link to related issue)](jnwatson/py-lmdb#472). Both lmdb-go and py-lmdb statically link to liblmdb to not require additional dependencies.
Options for lmdb-go
There are several directions we could take to support LMDB v1.0.
For clarity the text below will use old LMDB to refer to v0.9.x LMDB databases and liblmdb, and new LMDB to refer to LMDB v1.0.
Option A: Release lmdb-go/v2 with new LMDB
Do the Go module version bump thing and release a v2 that ships new LMDB, while continuing to support old LMDB in the current v1 series. The vendored C code remains unmodified, we just switch to a different branch in v2.
On the surface this seems like the 'right' solution, as this is an incompatible change to the library, and it allows users to decide when they want to upgrade to lmdb-go/v2 at their own pace.
Gotcha: no simultaneous import
Unfortunately there is one major catch: because the symbol names remain the same, only one version of liblmdb can be linked at a time. This means it is not possible to import v1 and v2 at the same time, as is possible with normal Go modules.
This also means that it is impossible to support both old and new LMDB in the same process, or to select one at runtime. This also prevents doing an application level migration.
We would prefer to be able to load both versions for applications like our [LightningStream](https://github.com/PowerDNS/lightningstream).
Option B: Dynamic linking for new LMDB support
Support the new LMDB by dynamic linking instead of static linking, keeping the API surface the same. This would require a Go application to:
- use build tags to opt-in to dynamic linking instead of static linking
- have liblmdb installed on the build system
- ensure that the library is installed in the desired version on the target platform
There are some additional technical hurdles:
- Old and new LMDB have a different
SONAME, which means that additional hacks and symlinks would be required to allow seamless switching between versions on deployment. - Without hacking only the version linked at build time would be supported, basically requiring separate builds for old and new LMDB support.
Downsides:
- Build tags are fragile and complicate the build process.
- It still does not allow us to support two versions at the same time.
- Dynamic linking complicates deployment of applications.
This option would not expose new LMDB features, that would still require a v2.
Option C: v2 for new LMDB + v1 symbol renaming
Like in Option A, create a new v2 for new LMDB support.
Additionally, rename the symbols in the vendored old LMDB to allow both v1 and v2 to be imported at the same time.
Downsides:
- Client code that wants to support both would need to import both v1 and v2 and create its own abstraction over this library to support this.
- A low-level abstraction over
Txn.Putand similar functions with interfaces would likely add a significant overhead for libraries. - Support for new LMDB would require client code to change all imports to point to v2, making it very hard to support both old and new LMDB with the same codebase, even via separate builds.
Technical annoyances:
- Need to modify upstream code to rename symbols, although most can probably be done with header
#definerename tricks. - CGo glue code still needs to be modified to call the new renamed symbol names in v1.
- Code between v1 and v2 would diverge because of the renames.
Option D: anylmdb route
One step further is to rename symbols of both the old and the new LMDB, and provide a compatibility layer that exposes the normal LMDB API for access to either version, routing calls to the appropriate backend.
This is the approach that the experimental [wojas/anylmdb](https://github.com/wojas/anylmdb) takes. Disclaimer: I created this repository, but this is truly an experiment at this point with no decision that this is the path forward.
Advantages:
- Both versions can be supported at the same time, including simultaneously opening old and new LMDBs.
- The C code abstracts away the differences between old and new for most parts.
- Caller can decide the default version for newly created LMDBs.
- C level indirection is more efficient than performing this on the Go level.
Disadvantages:
- Patching of upstream code is kept minimal, but is still present.
- Updates of LMDB require running the anylmdb update scripts, which is similar to the current lmdb-go update process.
- C level indirection still may have some performance impact, although this is likely far smaller than CGo call overhead.
- Added complexity.
- Slightly added overhead of shipping two versions in the build. The added overhead is not that significant in the Go ecosystem of large static binaries.
Experimental branch that uses anylmdb in lmdb-go: https://github.com/wojas/lmdb-go/tree/anylmdb
Additional complications
LMDB v1.0 bugs
At the time of writing, the new LMDB has a few bugs that have been found using AI. These have not yet been reported upstream, since [upstream's (OpenLDAP) contribution policy](https://www.openldap.org/devel/contributing.html#aipolicy) disallows AI-assisted contributions.
Windows support is currently broken in LMDB v1.0. We have not tested earlier versions of lmdb-go on Windows, so perhaps not a blocker for lmdb-go. See WIP: experimental Windows support (MSVC + MinGW) wojas/anylmdb#1(FIXED IN 1.0.1)mdb_cursor_closeaftermdb_txn_commitcrash: this was explicitly allowed in 0.9 and comments suggest the intended behavior did not change, but this now causes a use-after-free.- Building with
MDB_RPAGE_CACHE=0could have avoided the crashing code path, but this option no longer compiles.
- Building with
mdb_env_open on wrong version implications
First, opening a database with the wrong version yields a misleading "corrupt database" error. @Habbie suggested a patch, but this was rejected.
Second, the lock file is written before the data file is read. Probing with the wrong version can create a lock file and race with the correct version, leading to the correct version subsequently giving "corrupt database" errors. This makes just trying to open the database with one version to detect the database version unsafe, requiring custom code (anylmdb contains code for this).
Security patches
py-lmdb carries a set of security patches against LMDB that have been rejected by upstream but appear to be really valuable for general use of LMDB:
jnwatson/py-lmdb#472 (comment)
Even if the world switches to the new LMDB rapidly, it is worthwhile to maintain these patches without duplicating them between py-lmdb and lmdb-go. They are also useful to C/C++ users of liblmdb.
At a certain point in the future where users have migrated to the new LMDB, we could release a v2 (or v3) that returns to just supporting the newer version, and forget this whole episode, but we would still need to consider these patches.
Closing remarks
We have not decided on the direction to take yet. This issue summarizes the situation for lmdb-go users and other LMDB wrapper maintainers.
The most likely directions are Option C and Option D.
Option C is the most minimalistic one that still allows loading both versions within the same process.
Option D provides a better experience for applications that need both versions, at the cost of maintaining the anylmdb layer. This maintenance cost would be easier to justify if it were shared with other wrappers, and used as the single place for additional security patches.
In the meantime, v1 in this repo continues to ship and support LMDB v0.9.x ("old LMDB"). We promise we will not switch the current v1 version to the new LMDB and suddenly break your application in the process.
Feel free to try out the experimental Option D branch at https://github.com/wojas/lmdb-go/tree/anylmdb and share feedback if you feel adventurous.
More info
Related links:
Activity
miodvallat commentedon Aug 6, 2026
I think options C and D are clearly better than A and B. We should also try to aim for the smallest amount of involvement with the liblmdb code, which makes IMHO option C preferable to option D.
jnwatson commentedon Aug 16, 2026
py-lmdb went with another option, implemented here: jnwatson/py-lmdb#479
I link with both versions and use macros to put each library's symbols in a different namespace.
Luit commentedon Aug 20, 2026
I think for Option B, if we want to try that, that should be a different package/module altogether. That'll make it clearer the implementation is significantly different from the current one, regardless of the v0.9/v1 trouble. That implementation will have its own issues with that. I have no idea what the performance of this approach will be, relative to the current. Would be interesting to see.
I also see two potential approaches for the dynamic linking option: CGo and purego.
wojas commentedon Sep 3, 2026
PR #42 implements a similar approach as taken by @jnwatson in jnwatson/py-lmdb#479 (thanks for the insightful comments and prior art!).
It is effectively option D (anylmdb), but with the following differences:
mdb_*symbols, all symbols can be renamed, and there is no need for C trampolines. This makes the glue layer slightly easier to understand.The reasons we effectively went with option D over C: