#include <db_cxx.h> DbEnv::close(u_int32_t flags);
The DbEnv::close()
method closes the Berkeley DB environment,
freeing any allocated resources and closing any underlying subsystems.
The DbEnv handle should not be closed while any other handle that refers to it is not yet closed; for example, database environment handles must not be closed while database handles remain open, or transactions in the environment have not yet been committed or aborted. Specifically, this includes the Db, Dbc, DbTxn, DbLogc and DbMpoolFile handles.
Where the environment was initialized with the
DB_INIT_LOCK flag,
calling DbEnv::close()
does not release any locks still held by the
closing process, providing functionality for long-lived locks.
Processes that want to have all their locks released can do so by
issuing the appropriate DbEnv::lock_vec() call.
Where the environment was initialized with the
DB_INIT_MPOOL flag,
calling DbEnv::close()
implies calls to
DbMpoolFile::close() for any
remaining open files in the memory pool that were returned to this
process by calls to DbMpoolFile::open(). It does
not imply a call to DbMpoolFile::sync() for those
files.
Where the environment was initialized with the
DB_INIT_TXN flag,
calling DbEnv::close()
aborts any unresolved transactions.
Applications should not depend on this behavior for transactions
involving Berkeley DB databases; all such transactions should be
explicitly resolved. The problem with depending on this semantic is
that aborting an unresolved transaction involving database operations
requires a database handle. Because the database handles should have
been closed before calling DbEnv::close()
, it will not be possible
to abort the transaction, and recovery will have to be run on the
Berkeley DB environment before further operations are done.
Where log cursors were created using the
DbEnv::log_cursor() method,
calling DbEnv::close()
does not imply closing those cursors.
In multithreaded applications, only a single thread may call the
DbEnv::close()
method.
After DbEnv::close()
has been called, regardless of its return, the
Berkeley DB environment handle may not be accessed again.
The DbEnv::close()
method either returns a non-zero error value or throws an
exception that encapsulates a non-zero error value on
failure, and returns 0 on success.