# DB_ENV->close

`

###

    #include <db.h>

    int
    DB_ENV->close(DB_ENV *dbenv, u_int32_t flags);

# Description

The DB_ENV->close function closes the Berkeley DB environment, freeing any allocated resources and closing any underlying subsystems.

Calling DB_ENV->close does not imply closing any databases that were opened in the environment, and all databases opened in the environment should be closed before the environment is closed.

The flags parameter is currently unused, and must be set to 0.

Where the environment was initialized with the DB_INIT_LOCK flag, calling DB_ENV->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 DB_ENV->lock_vec call.

Where the environment was initialized with the DB_INIT_MPOOL flag, calling DB_ENV->close implies calls to DB_MPOOLFILE->close for any remaining open files in the memory pool that were returned to this process by calls to DB_MPOOLFILE->open. It does not imply a call to DB_MPOOLFILE->sync for those files.

Where the environment was initialized with the DB_INIT_TXN flag, calling DB_ENV->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 DB_ENV->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 DB_ENV->log_cursor function, calling DB_ENV->close does not imply closing those cursors.

In multithreaded applications, only a single thread may call DB_ENV->close.

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

The DB_ENV->close function returns a non-zero error value on failure and 0 on success.

# Errors

The DB_ENV->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_ENV->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_env_create, DB_ENV->close, DB_ENV->err, DB_ENV->errx DB_ENV->open, DB_ENV->remove, DB_ENV->set_alloc, DB_ENV->set_cachesize, DB_ENV->set_data_dir, DB_ENV->set_errcall, DB_ENV->set_errfile, DB_ENV->set_errpfx, DB_ENV->set_feedback, DB_ENV->set_flags, DB_ENV->set_paniccall, DB_ENV->set_recovery_init, DB_ENV->set_rpc_server, DB_ENV->set_shm_key, DB_ENV->set_tas_spins, DB_ENV->set_tmp_dir, DB_ENV->set_timeout, DB_ENV->set_verbose, db_strerror and db_version.`

Copyright Sleepycat Software