# DBENV->remove |

`

###

    #include <db.h>

    int
    DBENV->remove(DB_ENV *, char *db_home, u_int32_t flags);

# Description

The DBENV->remove function destroys a Berkeley DB environment, if it is not currently in use. The environment regions, including any backing files, are removed. Any log or database files and the environment directory are not removed.

The db_home argument to DBENV->remove is described in Berkeley DB File Naming.

If there are processes that have called DBENV->open without calling DBENV->close (i.e., there are processes currently using the environment), DBENV->remove will fail without further action, unless the DB_FORCE flag is set, in which case DBENV->remove will attempt to remove the environment regardless of any processes still using it.

The result of attempting to forcibly destroy the environment when it is in use is unspecified. Processes using an environment often maintain open file descriptors for shared regions within it. On UNIX systems, the environment removal will usually succeed and processes that have already joined the region will continue to run in that region without change, however processes attempting to join the environment will either fail or create new regions. On other systems (e.g., Windows/NT), where the unlink(2) system call will fail if any process has an open file descriptor for the file, the region removal will fail.

Calling DBENV->remove should not be necessary for most applications, as the Berkeley DB environment is cleaned up as part of normal database recovery procedures, however, applications may wish to call DBENV->remove as part of application shutdown to free up system resources. Specifically, when the DB_SYSTEM_MEM flag was specified to DBENV->open, it may be useful to call DBENV->remove in order to release system shared memory segments that have been allocated.

In the case of catastrophic or system failure, database recovery must be performed (see db_recover), or the DB_RECOVER and DB_RECOVER_FATAL flags to DBENV->open must be specified when the environment is re-opened. Alternatively, if recovery is not required because no database state is maintained across failures, and the DB_SYSTEM_MEM flag was not specified when the environment was created, it is possible to clean up an environment by removing all of the files in the environment directory that begin with the string prefix "__db", as no backing files are created in any other directory.

The flags value must be set to 0 or by bitwise inclusively OR'ing together one or more of the following values.

DB_FORCE
  If the DB_FORCE flag is set, the environment is removed regardless of any processes that may still using it, and, no locks are acquired during this process. (Generally, the DB_FORCE flag is only specified when applications were unable to shut down cleanly, and there is a risk that an application may have died holding a Berkeley DB lock.)

DB_USE_ENVIRON
  The Berkeley DB process' environment may be permitted to specify information to be used when naming files; see Berkeley DB File Naming. As permitting users to specify which files are used can create security problems, environment information will be used in file naming for all users only if the DB_USE_ENVIRON flag is set.

DB_USE_ENVIRON_ROOT
  The Berkeley DB process' environment may be permitted to specify information to be used when naming files; see Berkeley DB File Naming. As permitting users to specify which files are used can create security problems, if the DB_USE_ENVIRON_ROOT flag is set, environment information will be used for file naming only for users with appropriate permissions (e.g., on UNIX systems, users with a user-ID of 0).

In multi-threaded applications, only a single thread may call DBENV->remove.

A DB_ENV handle which has already been used to open an environment should not be used to call the DBENV->remove function, a new DB_ENV handle should be created for that purpose.

Once DBENV->remove has been called, regardless of its return, the Berkeley DB environment handle may not be accessed again.

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

# Errors

EBUSY
  The shared memory region was in use and the force flag was not set.

The DBENV->remove 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 DBENV->remove function may fail and return DB_RUNRECOVERY, in which case all subsequent Berkeley DB calls will fail in the same way.

# See Also

DBENV->close, db_env_create, DBENV->open, DBENV->remove, DBENV->err, db_strerror, db_version, DBENV->set_cachesize, DBENV->set_errcall, DBENV->set_errfile, DBENV->set_errpfx, DBENV->set_flags, DBENV->set_mutexlocks, DBENV->set_paniccall, and DBENV->set_verbose.`

Copyright Sleepycat Software