Chapter 2.  The Db Handle

The Db is the handle for a single Berkeley DB database. A Berkeley DB database provides a mechanism for organizing key-data pairs of information. From the perspective of some database systems, a Berkeley DB database could be thought of as a single table within a larger database.

You create a Db handle using the Db constructor. For most database activities, you must then open the handle using the Db::open() method. When you are done with them, handles must be closed using the Db::close() method.

Alternatively, you can create a Db and then rename, remove or verify the database without performing an open. See Db::rename(), Db::remove() or Db::verify() for information on these activities.

It is possible to create databases such that they are organized within a database environment. Environments are optional for simple Berkeley DB applications that do not use transactions, recovery, replication or any other advanced features. For simple Berkeley DB applications, environments still offer some advantages. For example, they provide some organizational benefits on-disk (all databases are located on disk relative to the environment). Also, if you are using multiple databases, then environments allow your databases to share a common in-memory cache, which makes for more efficient usage of your hardware's resources.

See DbEnv for information on using database environments.

You specify the underlying organization of the data in the database (e.g. BTree, Hash, Queue, and Recno) when you open the database. When you create a database, you are free to specify any of the available database types. On subsequent opens, you must either specify the access method used when you first opened the database, or you can specify DB_UNKNOWN in order to have this information retrieved for you. See the Db::open() method for information on specifying database types.

Database and Related Methods