---
name: "mdb_lmdb.h"
section: "3"
platform: "linux"
package: "lmdb-doc"
version: "0.9.31-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mdb_lmdb.h"
---

# mdb\_lmdb.h(3)

Lightning memory-mapped database library.

## NAME

lmdb.h - Lightning memory-mapped database library.

## SYNOPSIS

`#include <sys/types.h>`\

### Data Structures

struct **MDB\_val**\
 Generic structure used for passing keys and data in and out of the database.  struct **MDB\_stat**\
 Statistics for a database in the environment.  struct **MDB\_envinfo**\
 Information about the environment.

### Macros

\#define **MDB\_VERSION\_MAJOR**   0\
 \#define **MDB\_VERSION\_MINOR**   9\
 \#define **MDB\_VERSION\_PATCH**   31\
 \#define **MDB\_VERINT**(a,  b,  c)   (((a) \<\< 24) \| ((b) \<\< 16) \| (c))\
 \#define **MDB\_VERSION\_FULL**   	**MDB\_VERINT**(**MDB\_VERSION\_MAJOR**,**MDB\_VERSION\_MINOR**,**MDB\_VERSION\_PATCH**)\
 \#define **MDB\_VERSION\_DATE**   'July 10, 2023'\
 \#define **MDB\_VERSTR**(a,  b,  c,  d)   'LMDB ' #a '.' #b '.' #c ': (' d ')'\
 \#define **MDB\_VERFOO**(a,  b,  c,  d)   **MDB\_VERSTR**(a,b,c,d)\
 \#define **MDB\_VERSION\_STRING**   	**MDB\_VERFOO**(**MDB\_VERSION\_MAJOR**,**MDB\_VERSION\_MINOR**,**MDB\_VERSION\_PATCH**,**MDB\_VERSION\_DATE**)\
 \#define **MDB\_FIXEDMAP**   0x01\
 \#define **MDB\_NOSUBDIR**   0x4000\
 \#define **MDB\_NOSYNC**   0x10000\
 \#define **MDB\_RDONLY**   0x20000\
 \#define **MDB\_NOMETASYNC**   0x40000\
 \#define **MDB\_WRITEMAP**   0x80000\
 \#define **MDB\_MAPASYNC**   0x100000\
 \#define **MDB\_NOTLS**   0x200000\
 \#define **MDB\_NOLOCK**   0x400000\
 \#define **MDB\_NORDAHEAD**   0x800000\
 \#define **MDB\_NOMEMINIT**   0x1000000\
 \#define **MDB\_REVERSEKEY**   0x02\
 \#define **MDB\_DUPSORT**   0x04\
 \#define **MDB\_INTEGERKEY**   0x08\
 \#define **MDB\_DUPFIXED**   0x10\
 \#define **MDB\_INTEGERDUP**   0x20\
 \#define **MDB\_REVERSEDUP**   0x40\
 \#define **MDB\_CREATE**   0x40000\
 \#define **MDB\_NOOVERWRITE**   0x10\
 \#define **MDB\_NODUPDATA**   0x20\
 \#define **MDB\_CURRENT**   0x40\
 \#define **MDB\_RESERVE**   0x10000\
 \#define **MDB\_APPEND**   0x20000\
 \#define **MDB\_APPENDDUP**   0x40000\
 \#define **MDB\_MULTIPLE**   0x80000\
 \#define **MDB\_CP\_COMPACT**   0x01\
 \#define **MDB\_SUCCESS**   0\
 \#define **MDB\_KEYEXIST**   (-30799)\
 \#define **MDB\_NOTFOUND**   (-30798)\
 \#define **MDB\_PAGE\_NOTFOUND**   (-30797)\
 \#define **MDB\_CORRUPTED**   (-30796)\
 \#define **MDB\_PANIC**   (-30795)\
 \#define **MDB\_VERSION\_MISMATCH**   (-30794)\
 \#define **MDB\_INVALID**   (-30793)\
 \#define **MDB\_MAP\_FULL**   (-30792)\
 \#define **MDB\_DBS\_FULL**   (-30791)\
 \#define **MDB\_READERS\_FULL**   (-30790)\
 \#define **MDB\_TLS\_FULL**   (-30789)\
 \#define **MDB\_TXN\_FULL**   (-30788)\
 \#define **MDB\_CURSOR\_FULL**   (-30787)\
 \#define **MDB\_PAGE\_FULL**   (-30786)\
 \#define **MDB\_MAP\_RESIZED**   (-30785)\
 \#define **MDB\_INCOMPATIBLE**   (-30784)\
 \#define **MDB\_BAD\_RSLOT**   (-30783)\
 \#define **MDB\_BAD\_TXN**   (-30782)\
 \#define **MDB\_BAD\_VALSIZE**   (-30781)\
 \#define **MDB\_BAD\_DBI**   (-30780)\
 \#define **MDB\_LAST\_ERRCODE**   **MDB\_BAD\_DBI**\
 \#define **mdb\_open**(txn,  name,  flags,  dbi)   **mdb\_dbi\_open**(txn,name,flags,dbi)\
 \#define **mdb\_close**(env,  dbi)   **mdb\_dbi\_close**(env,dbi)\

### Typedefs

typedef mode\_t **mdb\_mode\_t**\
 typedef int **mdb\_filehandle\_t**\
 typedef unsigned int **MDB\_dbi**\
 A handle for an individual database in the DB environment.  typedef int() **MDB\_cmp\_func**(const **MDB\_val** \*a, const **MDB\_val** \*b)\
 A callback function used to compare two keys in a database.  typedef void() **MDB\_rel\_func**(**MDB\_val** \*item, void \*oldptr, void \*newptr, void \*relctx)\
 A callback function used to relocate a position-dependent data item in a fixed-address database.  typedef void **MDB\_assert\_func**(**MDB\_env** \*env, const char \*msg)\
 A callback function for most LMDB assert() failures, called before printing the message and aborting.  typedef int() **MDB\_msg\_func**(const char \*msg, void \*ctx)\
 A callback function used to print a message from the library.

### Enumerations

enum **MDB\_cursor\_op** { **MDB\_FIRST**, **MDB\_FIRST\_DUP**, **MDB\_GET\_BOTH**, **MDB\_GET\_BOTH\_RANGE**, **MDB\_GET\_CURRENT**, **MDB\_GET\_MULTIPLE**, **MDB\_LAST**, **MDB\_LAST\_DUP**, **MDB\_NEXT**, **MDB\_NEXT\_DUP**, **MDB\_NEXT\_MULTIPLE**, **MDB\_NEXT\_NODUP**, **MDB\_PREV**, **MDB\_PREV\_DUP**, **MDB\_PREV\_NODUP**, **MDB\_SET**, **MDB\_SET\_KEY**, **MDB\_SET\_RANGE**, **MDB\_PREV\_MULTIPLE** }\
 Cursor Get operations.

### Functions

char \* **mdb\_version** (int \*major, int \*minor, int \*patch)\
 Return the LMDB library version information.  char \* **mdb\_strerror** (int err)\
 Return a string describing a given error code.  int **mdb\_env\_create** (**MDB\_env** \*\*env)\
 Create an LMDB environment handle.  int **mdb\_env\_open** (**MDB\_env** \*env, const char \*path, unsigned int flags, **mdb\_mode\_t** mode)\
 Open an environment handle.  int **mdb\_env\_copy** (**MDB\_env** \*env, const char \*path)\
 Copy an LMDB environment to the specified path.  int **mdb\_env\_copyfd** (**MDB\_env** \*env, **mdb\_filehandle\_t** fd)\
 Copy an LMDB environment to the specified file descriptor.  int **mdb\_env\_copy2** (**MDB\_env** \*env, const char \*path, unsigned int flags)\
 Copy an LMDB environment to the specified path, with options.  int **mdb\_env\_copyfd2** (**MDB\_env** \*env, **mdb\_filehandle\_t** fd, unsigned int flags)\
 Copy an LMDB environment to the specified file descriptor, with options.  int **mdb\_env\_stat** (**MDB\_env** \*env, **MDB\_stat** \*stat)\
 Return statistics about the LMDB environment.  int **mdb\_env\_info** (**MDB\_env** \*env, **MDB\_envinfo** \*stat)\
 Return information about the LMDB environment.  int **mdb\_env\_sync** (**MDB\_env** \*env, int force)\
 Flush the data buffers to disk.  void **mdb\_env\_close** (**MDB\_env** \*env)\
 Close the environment and release the memory map.  int **mdb\_env\_set\_flags** (**MDB\_env** \*env, unsigned int flags, int onoff)\
 Set environment flags.  int **mdb\_env\_get\_flags** (**MDB\_env** \*env, unsigned int \*flags)\
 Get environment flags.  int **mdb\_env\_get\_path** (**MDB\_env** \*env, const char \*\*path)\
 Return the path that was used in **mdb\_env\_open()**.  int **mdb\_env\_get\_fd** (**MDB\_env** \*env, **mdb\_filehandle\_t** \*fd)\
 Return the filedescriptor for the given environment.  int **mdb\_env\_set\_mapsize** (**MDB\_env** \*env, size\_t size)\
 Set the size of the memory map to use for this environment.  int **mdb\_env\_set\_maxreaders** (**MDB\_env** \*env, unsigned int readers)\
 Set the maximum number of threads/reader slots for the environment.  int **mdb\_env\_get\_maxreaders** (**MDB\_env** \*env, unsigned int \*readers)\
 Get the maximum number of threads/reader slots for the environment.  int **mdb\_env\_set\_maxdbs** (**MDB\_env** \*env, **MDB\_dbi** dbs)\
 Set the maximum number of named databases for the environment.  int **mdb\_env\_get\_maxkeysize** (**MDB\_env** \*env)\
 Get the maximum size of keys and **MDB\_DUPSORT** data we can write.  int **mdb\_env\_set\_userctx** (**MDB\_env** \*env, void \*ctx)\
 Set application information associated with the **MDB\_env**.  void \* **mdb\_env\_get\_userctx** (**MDB\_env** \*env)\
 Get the application information associated with the **MDB\_env**.  int **mdb\_env\_set\_assert** (**MDB\_env** \*env, **MDB\_assert\_func** \*func)\
 int **mdb\_txn\_begin** (**MDB\_env** \*env, **MDB\_txn** \*parent, unsigned int flags, **MDB\_txn** \*\*txn)\
 Create a transaction for use with the environment.  **MDB\_env** \* **mdb\_txn\_env** (**MDB\_txn** \*txn)\
 Returns the transaction's **MDB\_env**.  size\_t **mdb\_txn\_id** (**MDB\_txn** \*txn)\
 Return the transaction's ID.  int **mdb\_txn\_commit** (**MDB\_txn** \*txn)\
 Commit all the operations of a transaction into the database.  void **mdb\_txn\_abort** (**MDB\_txn** \*txn)\
 Abandon all the operations of the transaction instead of saving them.  void **mdb\_txn\_reset** (**MDB\_txn** \*txn)\
 Reset a read-only transaction.  int **mdb\_txn\_renew** (**MDB\_txn** \*txn)\
 Renew a read-only transaction.  int **mdb\_dbi\_open** (**MDB\_txn** \*txn, const char \*name, unsigned int flags, **MDB\_dbi** \*dbi)\
 Open a database in the environment.  int **mdb\_stat** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_stat** \*stat)\
 Retrieve statistics for a database.  int **mdb\_dbi\_flags** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, unsigned int \*flags)\
 Retrieve the DB flags for a database handle.  void **mdb\_dbi\_close** (**MDB\_env** \*env, **MDB\_dbi** dbi)\
 Close a database handle. Normally unnecessary. Use with care:  int **mdb\_drop** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, int del)\
 Empty or delete+close a database.  int **mdb\_set\_compare** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_cmp\_func** \*cmp)\
 Set a custom key comparison function for a database.  int **mdb\_set\_dupsort** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_cmp\_func** \*cmp)\
 Set a custom data comparison function for a **MDB\_DUPSORT** database.  int **mdb\_set\_relfunc** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_rel\_func** \*rel)\
 Set a relocation function for a **MDB\_FIXEDMAP** database.  int **mdb\_set\_relctx** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, void \*ctx)\
 Set a context pointer for a **MDB\_FIXEDMAP** database's relocation function.  int **mdb\_get** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_val** \*key, **MDB\_val** \*data)\
 Get items from a database.  int **mdb\_put** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_val** \*key, **MDB\_val** \*data, unsigned int flags)\
 Store items into a database.  int **mdb\_del** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_val** \*key, **MDB\_val** \*data)\
 Delete items from a database.  int **mdb\_cursor\_open** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, **MDB\_cursor** \*\*cursor)\
 Create a cursor handle.  void **mdb\_cursor\_close** (**MDB\_cursor** \*cursor)\
 Close a cursor handle.  int **mdb\_cursor\_renew** (**MDB\_txn** \*txn, **MDB\_cursor** \*cursor)\
 Renew a cursor handle.  **MDB\_txn** \* **mdb\_cursor\_txn** (**MDB\_cursor** \*cursor)\
 Return the cursor's transaction handle.  **MDB\_dbi** **mdb\_cursor\_dbi** (**MDB\_cursor** \*cursor)\
 Return the cursor's database handle.  int **mdb\_cursor\_get** (**MDB\_cursor** \*cursor, **MDB\_val** \*key, **MDB\_val** \*data, **MDB\_cursor\_op** op)\
 Retrieve by cursor.  int **mdb\_cursor\_put** (**MDB\_cursor** \*cursor, **MDB\_val** \*key, **MDB\_val** \*data, unsigned int flags)\
 Store by cursor.  int **mdb\_cursor\_del** (**MDB\_cursor** \*cursor, unsigned int flags)\
 Delete current key/data pair.  int **mdb\_cursor\_count** (**MDB\_cursor** \*cursor, size\_t \*countp)\
 Return count of duplicates for current key.  int **mdb\_cmp** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, const **MDB\_val** \*a, const **MDB\_val** \*b)\
 Compare two data items according to a particular database.  int **mdb\_dcmp** (**MDB\_txn** \*txn, **MDB\_dbi** dbi, const **MDB\_val** \*a, const **MDB\_val** \*b)\
 Compare two data items according to a particular database.  int **mdb\_reader\_list** (**MDB\_env** \*env, **MDB\_msg\_func** \*func, void \*ctx)\
 Dump the entries in the reader lock table.  int **mdb\_reader\_check** (**MDB\_env** \*env, int \*dead)\
 Check for stale entries in the reader lock table.

## Detailed Description

Lightning memory-mapped database library.

## Typedef Documentation

### typedef mode\_t mdb\_mode\_t

Unix permissions for creating files, or dummy definition for Windows

### typedef int mdb\_filehandle\_t

An abstraction for a file handle. On POSIX systems file handles are small integers. On Windows they're opaque pointers.

## Author

Generated automatically by Doxygen for LMDB from the source code.
