Library Version 11.2.5.3

Chapter 2. The Db Handle
Prev |  | Next

## 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

Database Operations | Description
--- | ---
Db::associate() | Associate a secondary index
Db::associate_foreign() | Associate a foreign index
Db::close() | Close a database
Db::compact() | Compact a database
Db | Create a database handle
Db::del() | Delete items from a database
Db::err() | Error message
Db::exists() | Return if an item appears in a database
Db::fd() | Return a file descriptor from a database
Db::get() | Get items from a database
Db::get_byteswapped() | Return if the underlying database is in host order
Db::get_dbname() | Return the file and database name
Db::get_multiple() | Return if the database handle references multiple databases
Db::get_open_flags() | Returns the flags specified to Db::open
Db::get_type() | Return the database type
Db::join() | Perform a database join on cursors
Db::key_range() | Return estimate of key location
Db::open() | Open a database
Db::put() | Store items into a database
Db::remove() | Remove a database
Db::rename() | Rename a database
Db::set_priority(), Db::get_priority() | Set/get cache page priority
Db::stat() | Database statistics
Db::stat_print() | Display database statistics
Db::sync() | Flush a database to stable storage
Db::truncate() | Empty a database
Db::upgrade() | Upgrade a database
Db::verify() | Verify/salvage a database
Db::cursor() | Create a cursor handle
Database Configuration
Db::set_alloc() | Set local space allocation functions
Db::set_cachesize(), Db::get_cachesize() | Set/get the database cache size
Db::set_create_dir(), Db::get_create_dir() | Set/get the directory in which a database is placed
Db::set_dup_compare() | Set a duplicate comparison function
Db::set_encrypt(), Db::get_encrypt_flags() | Set/get the database cryptographic key
Db::set_errcall() | Set error message callback
Db::set_errfile(), Db::get_errfile() | Set/get error message FILE
Db::set_error_stream() | Set C++ ostream used for error messages
Db::set_errpfx(), Db::get_errpfx() | Set/get error message prefix
Db::set_feedback() | Set feedback callback
Db::set_flags(), Db::get_flags() | Set/get general database configuration
Db::set_lk_exclusive(), Db::get_lk_exclusive() | Set/get exclusive database locking
Db::set_lorder(), Db::get_lorder() | Set/get the database byte order
Db::set_message_stream() | Set C++ ostream used for informational messages
Db::set_msgcall() | Set informational message callback
Db::set_msgfile(), Db::get_msgfile() | Set/get informational message FILE
Db::set_pagesize(), Db::get_pagesize() | Set/get the underlying database page size
Db::set_partition() | Set database partitioning
Db::set_partition_dirs(), Db::get_partition_dirs() | Set/get the directories used for database partitions
Btree/Recno Configuration
Db::set_append_recno() | Set record append callback
Db::set_bt_compare() | Set a Btree comparison function
Db::set_bt_compress() | Set Btree compression functions
Db::set_bt_minkey(), Db::get_bt_minkey() | Set/get the minimum number of keys per Btree page
Db::set_bt_prefix() | Set a Btree prefix comparison function
Db::set_re_delim(), Db::get_re_delim() | Set/get the variable-length record delimiter
Db::set_re_len(), Db::get_re_len() | Set/get the fixed-length record length
Db::set_re_pad(), Db::get_re_pad() | Set/get the fixed-length record pad byte
Db::set_re_source(), Db::get_re_source() | Set/get the backing Recno text file
Hash Configuration
Db::set_h_compare() | Set a Hash comparison function
Db::set_h_ffactor(), Db::get_h_ffactor() | Set/get the Hash table density
Db::set_h_hash() | Set a hashing function
Db::set_h_nelem(), Db::get_h_nelem() | Set/get the Hash table size
Queue Configuration
Db::set_q_extentsize(), Db::get_q_extentsize() | Set/get Queue database extent size
Heap
Db::set_heapsize(), Db::get_heapsize() | Set/get the database heap size
Db::set_heap_regionsize(), Db::get_heap_regionsize() | Set/get the database region size
DbHeapRecordId |
Database Utilities
db_copy | Copy a named database to a target directory

Prev |  | Next
Chapter 1. Introduction to Berkeley DB APIs | Home | Db::associate()