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_create function. 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 DB_ENV 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 | 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_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_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
DB_HEAP_RID |
Database Utilities
db_copy | Copy a named database to a target directory

Prev |  | Next
Chapter 1. Introduction to Berkeley DB APIs | Home | DB->associate()