One of the most important tasks of the database environment is to structure file naming within Berkeley DB. Cooperating applications (or multiple invocations of the same application) must agree on the location of the database environment, log files and other files used by the Berkeley DB subsystems, and, of course, the database 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 the database environment. This can be done easily in the call to DB_ENV->open by specifying a value for the db_home argument. There are more complex configurations in which it may be desirable to override db_home or provide supplementary path information.
The following list 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. For example::
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 following list describes the specific circumstances and order in which the different ways of specifying file naming information are applied. Berkeley DB filename 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 (for example, C:/tmp).
The common model for a Berkeley DB environment is one in which only the DB_HOME environment variable, or the db_home argument is specified. In this case, all data filenames 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 in which a database home is specified, using either the DB_HOME environment variable or the db_home argument to DB_ENV->open; and then the data directory and logging directory are set to the relative pathnames of directories underneath the environment home.
Store all files in the directory /a/database:
dbenv->open(dbenv, "/a/database", flags, mode);
Create temporary backing files in /b/temporary, and all other files in /a/database:
dbenv->set_tmp_dir(dbenv, "/b/temporary"); dbenv->open(dbenv, "/a/database", flags, mode);
Store data files in /a/database/datadir, log files in /a/database/logdir, and all other files in the directory /a/database:
dbenv->set_lg_dir(dbenv, "logdir"); dbenv->set_data_dir(dbenv, "datadir"); dbenv->open(dbenv, "/a/database", flags, mode);
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 data file directory specified:
dbenv->set_data_dir(dbenv, "/b/data2"); dbenv->set_data_dir(dbenv, "data1"); dbenv->open(dbenv, "/a/database", flags, mode);
Copyright Sleepycat Software