*I8Berkeley DB Reference Guide: Architecture[P2

Berkeley DB Reference Guide: Architecture



!

Environment



HThe Berkeley DB environment is the encapsulation of the five Berkeley DBDsubsystems, a collection of related applications, and the databases accessed by those applications./The applications we will be describing here are)similar to the Access Method applicationsDpreviously described in the Reference Guide, but they are also fully recoverableJin the face of application or system failure. The Berkeley DB applicationnenvironment is created and described by the db_appinit interface.@This interface creates a consistent naming scheme for all of the#subsystems sharing the environment.

FIt is important to realize that all applications sharing a single homeHdirectory implicitly trust each other. They have access to each other'sBdata as it resides in the shared memory buffer pool and will share@resources such as buffer space and locks. At the same time, anyHapplications that access the same files must share an environmentEif consistency is to be maintained across the different applications.

JThe simplest way to administer a Berkeley DB application environment is toCcreate a single home directory that stores the files for theJapplications that will share the environment. The environment can then beHidentified by the name of that directory. The environment may be sharedHby any number of applications as well as by any number of threads withinthe applications.

ENote that it is possible for an environment to include resources fromAother directories on the system, and applications often choose toEdistribute resources to other directories or disks for performance orIother reasons. However, by default, the shared memory regions (i.e., theJlocking, logging, memory pool, and transaction regions) and log files willDbe stored in the specified directory hierarchy. In situations whereDfurther customization is desired, such as placing the log files on aDseparate device, it is recommended that the application installationAprocess create a configuration file named DB_CONFIG in the;database home directory, specifying the customization. SeeVdb_appinit for details on this procedure.

DOnce an environment has been created, database files specified usingFrelative pathnames will be named relative to the home directory. WhenJrecovery needs to be run (e.g., after system or application failure), thisjdirectory is specified as the home directory to db_recover andHthe system is restored to a consistent state, ready for the applicationsOto be restarted. Note that the use of pathnames relative to the home directoryHis encouraged, so that the entire environment can be moved to facilitateGrestoring and recovering a database in a different directory or even ona different system.

?When transactions have been configured for the environment, themcheckpoint daemon, db_checkpoint, must be run as long as thereCare applications present. When locking is being used, the deadlockldetection daemon, db_deadlock, must be run as long as there arenapplications present. The db_archive utility provides informationHto facilitate log reclamation and creation of database snapshots. Afterjapplication or system failure, the db_recover, utility must beErun before any applications are restarted to return the database to aconsistent state.

LFinally, Berkeley DB applications that run with additional privileges shouldlalways call the db_appinit function to initialize namingCfor their application. This ensures that the environment variables–DB_HOME and TMPDIR will be used only if the application(explicitly specifies that they are safe.

JAMÿÿ