|
The most important task of the environment is to structure file naming within Berkeley DB.
Each of the locking, logging, memory pool and transaction subsystems of Berkeley DB require shared memory regions, backed by the filesystem. Further, cooperating applications (or multiple invocations of the same application) must agree on the location of the shared memory regions and other files used by the Berkeley DB subsystems, the log files used by the logging subsystem, and, of course, the data files. Although it is possible to specify full pathnames to all Berkeley DB functions, this is cumbersome and requires that applications be recompiled when database files are moved.
Applications are normally expected to specify a single directory home for their database. This can be done easily in the call to DBENV->open by specifying a value for the db_home argument. There are more complex configurations where it may be desirable to override db_home or provide supplementary path information.
The following describes the possible ways in which file naming information may be specified to the Berkeley DB library. The specific circumstances and order in which these ways are applied are described in a subsequent paragraph.
The DB_HOME environment variable is intended to permit users and system administrators to override application and installation defaults, e.g.:
env DB_HOME=/database/my_home application
Application writers are encouraged to support the -h option found in the supporting Berkeley DB utilities to let users specify a database home.
The characters delimiting the two parts of the entry may be one or more whitespace characters, and trailing whitespace characters are discarded. All empty lines or lines whose first character is a whitespace or hash (#) character will be ignored. Each line must specify both the NAME and the VALUE of the pair. The specific NAME VALUE pairs are documented in the manual DBENV->set_data_dir, DBENV->set_lg_dir and DBENV->set_tmp_dir pages.
The DB_CONFIG configuration file is intended to permit systems to customize file location for an environment independent of applications using that database. For example, a database administrator can move the database log and data files to a different location without application recompilation.
The following describes the specific circumstances and order in which the different ways of specifying file naming information are applied. Berkeley DB file name processing proceeds sequentially through the following steps:
On UNIX systems, an absolute pathname is defined as any pathname that begins with a leading slash (/).
On Windows systems, an absolute pathname is any pathname that begins with a leading slash or leading backslash (\), or any pathname beginning with a single alphabetic character, a colon and a leading slash or backslash, e.g., C:/tmp.
The common model for a Berkeley DB environment is one where only the DB_HOME environment variable, or the db_home argument, is specified. In this case, all data file names are relative to that directory, and all files created by the Berkeley DB subsystems will be created in that directory.
The more complex model for a transaction environment might be one where a database home is specified, using either the DB_HOME environment variable or the db_home argument to DBENV->open, and then the data directory and logging directory are set to the relative path names of directories underneath the environment home.
Create temporary backing files in /b/temporary, and all other files in /a/database:DBENV->open(DBENV, "/a/database", ...);
Store data files in /a/database/datadir, log files in /a/database/logdir, and all other files in the directory /a/database:DBENV->set_tmp_dir(DBENV, "/b/temporary"); DBENV->open(DBENV, "/a/database", ...);
DBENV->set_lg_dir("logdir"); DBENV->set_data_dir("datadir"); DBENV->open(DBENV, "/a/database", ...);
Store data files in /a/database/data1 and /b/data2, and all other files in the directory /a/database. Any data files that are created will be created in /b/data2, because it is the first DB_DATA_DIR directory specified:
DBENV->set_data_dir(DBENV, "/b/data2"); DBENV->set_data_dir(DBENV, "data1"); DBENV->open(DBENV, "/a/database", ...);