Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LMDB increase map_size

Tags:

c++

database

lmdb

I was working with LMDB++ (the C++ wrapper for LMDB) and I got this error:

terminate called after throwing an instance of 'lmdb::map_full_error' what(): mdb_put: MDB_MAP_FULL: Environment mapsize limit reached

Some googling told me that the default map_size is set low in LMDB. How do I go about increasing map_size?

like image 405
shrayus gupta Avatar asked Oct 27 '25 17:10

shrayus gupta


1 Answers

The default LMDB map size is 10 MiB, which is indeed too small for most uses.

To set the LMDB map size using the C++ wrapper, you ought to call lmdb::env#set_mapsize() right after creating your LMDB environment and prior to opening the environment or creating your transaction.

Here's a basic example that increases the map size to 1 GiB:

/* Create and open the LMDB environment: */
auto env = lmdb::env::create();
env.set_mapsize(1UL * 1024UL * 1024UL * 1024UL);
env.open("./example.mdb", 0, 0664);

If you are calculating a large map size as in the above example, take care to include the appropriate type suffix (UL or ULL) on your integer literals, or else you may encounter silent integer overflow and be left wondering why the map size did not increase to what you expected.

See also the documentation for LMDB's underlying C function mdb_env_set_mapsize() for the authoritative word on how the map size works.

like image 73
Arto Bendiken Avatar answered Oct 30 '25 07:10

Arto Bendiken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!