Berkeley DB: DB->close
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++

# DB->close |

`

###

    #include <db.h>

    int
    DB->close(DB *db, u_int32_t flags);

# Description

The DB->close function flushes any cached database information to disk, closes any open cursors, frees any allocated resources, and closes any underlying files. Because key/data pairs are cached in memory, failing to sync the file with the DB->close or DB->sync function may result in inconsistent or lost information.

The flags value must be set to 0 or the following value:

DB_NOSYNC
  Do not flush cached information to disk. The DB_NOSYNC flag is a dangerous option. It should be set only if the application is doing logging (with transactions) so that the database is recoverable after a system or application crash, or if the database is always generated from scratch after any system or application crash.

  It is important to understand that flushing cached information to disk only minimizes the window of opportunity for corrupted data. Although unlikely, it is possible for database corruption to happen if a system or application crash occurs while writing data to the database. To ensure that database corruption never occurs, applications must either: use transactions and logging with automatic recovery; use logging and application-specific recovery; or edit a copy of the database, and once all applications using the database have successfully called DB->close, atomically replace the original database with the updated copy.

When multiple threads are using the Berkeley DB handle concurrently, only a single thread may call the DB->close function.

After DB->close has been called, regardless of its return, the DB handle may not be accessed again.

The DB->close function returns a non-zero error value on failure, 0 on success, and returns DB_INCOMPLETE if the underlying database still has dirty pages in the cache. (The only reason to return DB_INCOMPLETE is if another thread of control were writing pages in the underlying database file at the same time as the DB->close function was called. For this reason, a return of DB_INCOMPLETE can normally be ignored; or, in cases where it is a possible return value, the DB_NOSYNC option should probably have been specified.)

# Errors

The DB->close function may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions. If a catastrophic error has occurred, the DB->close function may fail and return DB_RUNRECOVERY, in which case all subsequent Berkeley DB calls will fail in the same way.

# See Also

db_create, DB->associate, DB->close, DB->cursor, DB->del, DB->err, DB->errx DB->fd, DB->get, DB->pget, DB->get_byteswapped, DB->get_type, DB->join, DB->key_range, DB->open, DB->put, DB->remove, DB->rename, DB->set_alloc, DB->set_append_recno, DB->set_bt_compare, DB->set_bt_minkey, DB->set_bt_prefix, DB->set_cachesize, DB->set_dup_compare, DB->set_errcall, DB->set_errfile, DB->set_errpfx, DB->set_feedback, DB->set_flags, DB->set_h_ffactor, DB->set_h_hash, DB->set_h_nelem, DB->set_lorder, DB->set_pagesize, DB->set_paniccall, DB->set_q_extentsize, DB->set_re_delim, DB->set_re_len, DB->set_re_pad, DB->set_re_source, DB->stat, DB->sync, DB->truncate, DB->upgrade, and DB->verify.`

Copyright Sleepycat Software