| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 | <title>File naming</title> |
| 7 | <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> |
| 8 | <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> |
| 9 | <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="env.html" title="Chapter 9. The Berkeley DB Environment" /> |
| 11 | <link rel="prev" href="env_db_config.html" title="DB_CONFIG configuration file" /> |
| 12 | <link rel="next" href="env_region.html" title="Shared memory regions" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">File naming</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="env_db_config.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 9. |
| 26 | The Berkeley DB Environment |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="env_region.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="env_naming"></a>File naming</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <div class="toc"> |
| 42 | <dl> |
| 43 | <dt> |
| 44 | <span class="sect2"> |
| 45 | <a href="env_naming.html#idp51749352">Specifying file naming to Berkeley DB</a> |
| 46 | </span> |
| 47 | </dt> |
| 48 | <dt> |
| 49 | <span class="sect2"> |
| 50 | <a href="env_naming.html#idp51763728">Filename resolution in Berkeley DB</a> |
| 51 | </span> |
| 52 | </dt> |
| 53 | <dt> |
| 54 | <span class="sect2"> |
| 55 | <a href="env_naming.html#idp51756464">Examples</a> |
| 56 | </span> |
| 57 | </dt> |
| 58 | </dl> |
| 59 | </div> |
| 60 | <p> |
| 61 | One of the most important tasks of the database environment is to |
| 62 | structure file naming within Berkeley DB. Cooperating applications (or |
| 63 | multiple invocations of the same application) must agree on the |
| 64 | location of the database environment, log files and other files used by |
| 65 | the Berkeley DB subsystems, and, of course, the database files. |
| 66 | Although it is possible to specify full pathnames to all Berkeley DB |
| 67 | methods, this is cumbersome and requires applications be recompiled |
| 68 | when database files are moved. |
| 69 | </p> |
| 70 | <p> |
| 71 | Applications are normally expected to specify a single directory home |
| 72 | for the database environment. This can be done easily in the call to |
| 73 | <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> by specifying a value for the |
| 74 | <span class="bold"><strong>db_home</strong></span> argument. There are more |
| 75 | complex configurations in which it may be desirable to override |
| 76 | <span class="bold"><strong>db_home</strong></span> or provide supplementary path |
| 77 | information. |
| 78 | </p> |
| 79 | <div class="sect2" lang="en" xml:lang="en"> |
| 80 | <div class="titlepage"> |
| 81 | <div> |
| 82 | <div> |
| 83 | <h3 class="title"><a id="idp51749352"></a>Specifying file naming to Berkeley DB</h3> |
| 84 | </div> |
| 85 | </div> |
| 86 | </div> |
| 87 | <p> |
| 88 | The following list describes the possible ways in which file naming |
| 89 | information may be specified to the Berkeley DB library. The |
| 90 | specific circumstances and order in which these ways are applied |
| 91 | are described in a subsequent paragraph. |
| 92 | </p> |
| 93 | <div class="variablelist"> |
| 94 | <dl> |
| 95 | <dt> |
| 96 | <span class="term">db_home</span> |
| 97 | </dt> |
| 98 | <dd> |
| 99 | If the <span class="bold"><strong>db_home</strong></span> argument to |
| 100 | <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> is non-NULL, its value may be used as the |
| 101 | database home, and files named relative to its path. |
| 102 | </dd> |
| 103 | <dt> |
| 104 | <span class="term">DB_HOME</span> |
| 105 | </dt> |
| 106 | <dd> |
| 107 | <p> |
| 108 | If the DB_HOME environment variable is set when |
| 109 | <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> is called, its value may be used as the |
| 110 | database home, and files named relative to its |
| 111 | path. |
| 112 | </p> |
| 113 | <p> |
| 114 | The DB_HOME environment variable is intended to permit |
| 115 | users and system administrators to override application |
| 116 | and installation defaults. For example: |
| 117 | </p> |
| 118 | <pre class="programlisting">env DB_HOME=/database/my_home application</pre> |
| 119 | <p> |
| 120 | Application writers are encouraged to support the |
| 121 | <span class="bold"><strong>-h</strong></span> option found in the |
| 122 | supporting Berkeley DB utilities to let users specify a |
| 123 | database home. |
| 124 | </p> |
| 125 | </dd> |
| 126 | <dt> |
| 127 | <span class="term"><a href="../api_reference/C/env.html" class="olink">DB_ENV</a> methods</span> |
| 128 | </dt> |
| 129 | <dd> |
| 130 | <p> |
| 131 | There are four <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> methods that affect file naming: |
| 132 | </p> |
| 133 | <div class="itemizedlist"> |
| 134 | <ul type="disc"> |
| 135 | <li> |
| 136 | <p> |
| 137 | The <a href="../api_reference/C/envadd_data_dir.html" class="olink">DB_ENV->add_data_dir()</a> method specifies a |
| 138 | directory to search for database files. |
| 139 | </p> |
| 140 | </li> |
| 141 | <li> |
| 142 | <p> |
| 143 | The <a href="../api_reference/C/envset_lg_dir.html" class="olink">DB_ENV->set_lg_dir()</a> method specifies a |
| 144 | directory in which to create logging files. |
| 145 | </p> |
| 146 | </li> |
| 147 | <li> |
| 148 | <p> |
| 149 | The <a href="../api_reference/C/envset_tmp_dir.html" class="olink">DB_ENV->set_tmp_dir()</a> method specifies a |
| 150 | directory in which to create backing temporary |
| 151 | files. |
| 152 | </p> |
| 153 | </li> |
| 154 | <li> |
| 155 | <p> |
| 156 | The <a href="../api_reference/C/envset_metadata_dir.html" class="olink">DB_ENV->set_metadata_dir()</a> method specifies the |
| 157 | directory in which to create persistent |
| 158 | metadata files used by the environment. |
| 159 | </p> |
| 160 | </li> |
| 161 | </ul> |
| 162 | </div> |
| 163 | <p> |
| 164 | These methods are intended to permit applications to |
| 165 | customize a file locations for an environment. For example, |
| 166 | an application writer can place data files and log |
| 167 | files in different directories or instantiate a new log |
| 168 | directory each time the application runs. |
| 169 | </p> |
| 170 | </dd> |
| 171 | <dt> |
| 172 | <span class="term"> |
| 173 | <a class="link" href="env_db_config.html" title="DB_CONFIG configuration file">DB_CONFIG</a> |
| 174 | </span> |
| 175 | </dt> |
| 176 | <dd> |
| 177 | The same information specified to the <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> methods may |
| 178 | also be specified using the |
| 179 | <a class="link" href="env_db_config.html" title="DB_CONFIG configuration file">DB_CONFIG</a> |
| 180 | configuration file. |
| 181 | </dd> |
| 182 | </dl> |
| 183 | </div> |
| 184 | </div> |
| 185 | <div class="sect2" lang="en" xml:lang="en"> |
| 186 | <div class="titlepage"> |
| 187 | <div> |
| 188 | <div> |
| 189 | <h3 class="title"><a id="idp51763728"></a>Filename resolution in Berkeley DB</h3> |
| 190 | </div> |
| 191 | </div> |
| 192 | </div> |
| 193 | <p> |
| 194 | The following list describes the specific circumstances and order |
| 195 | in which the different ways of specifying file naming information |
| 196 | are applied. Berkeley DB filename processing proceeds sequentially |
| 197 | through the following steps: |
| 198 | </p> |
| 199 | <div class="variablelist"> |
| 200 | <dl> |
| 201 | <dt> |
| 202 | <span class="term">absolute pathnames</span> |
| 203 | </dt> |
| 204 | <dd> |
| 205 | <p> |
| 206 | If the filename specified to a Berkeley DB function is |
| 207 | an <span class="emphasis"><em>absolute pathname</em></span>, that |
| 208 | filename is used without modification by Berkeley DB. |
| 209 | </p> |
| 210 | <p> |
| 211 | On UNIX systems, an absolute pathname is defined as any |
| 212 | pathname that begins with a leading slash |
| 213 | (<span class="bold"><strong>/</strong></span>). |
| 214 | </p> |
| 215 | <p> |
| 216 | On Windows systems, an absolute pathname is any |
| 217 | pathname that begins with a leading slash or leading |
| 218 | backslash (<span class="bold"><strong>\</strong></span>); or any |
| 219 | pathname beginning with a single alphabetic character, |
| 220 | a colon and a leading slash or backslash (for example, |
| 221 | <code class="filename">C:/tmp</code>). |
| 222 | </p> |
| 223 | </dd> |
| 224 | <dt> |
| 225 | <span class="term"><a href="../api_reference/C/env.html" class="olink">DB_ENV</a> methods, DB_CONFIG</span> |
| 226 | </dt> |
| 227 | <dd> |
| 228 | If a relevant configuration string (for example, |
| 229 | set_data_dir), is specified either by calling a <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> |
| 230 | method or as a line in the |
| 231 | <a class="link" href="env_db_config.html" title="DB_CONFIG configuration file">DB_CONFIG</a> configuration |
| 232 | file, the value is prepended to the filename. If the |
| 233 | resulting filename is an absolute pathname, the filename is |
| 234 | used without further modification by Berkeley |
| 235 | DB. |
| 236 | </dd> |
| 237 | <dt> |
| 238 | <span class="term">db_home</span> |
| 239 | </dt> |
| 240 | <dd> |
| 241 | If the application specified a non-NULL |
| 242 | <span class="bold"><strong>db_home</strong></span> argument to |
| 243 | <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a>, its value is prepended to the filename. If the |
| 244 | resulting filename is an absolute pathname, the filename is |
| 245 | used without further modification by Berkeley |
| 246 | DB. |
| 247 | </dd> |
| 248 | <dt> |
| 249 | <span class="term">DB_HOME</span> |
| 250 | </dt> |
| 251 | <dd> |
| 252 | If the <span class="bold"><strong>db_home</strong></span> argument is |
| 253 | NULL, the DB_HOME environment variable was set, and the |
| 254 | application has set the appropriate <a href="../api_reference/C/envopen.html#envopen_DB_USE_ENVIRON" class="olink">DB_USE_ENVIRON</a> or |
| 255 | <a href="../api_reference/C/envopen.html#envopen_DB_USE_ENVIRON_ROOT" class="olink">DB_USE_ENVIRON_ROOT</a> flags, its value is prepended to the |
| 256 | filename. If the resulting filename is an absolute |
| 257 | pathname, the filename is used without further modification |
| 258 | by Berkeley DB. |
| 259 | </dd> |
| 260 | <dt> |
| 261 | <span class="term">default</span> |
| 262 | </dt> |
| 263 | <dd> |
| 264 | Finally, all filenames are interpreted relative to the |
| 265 | current working directory of the process. |
| 266 | </dd> |
| 267 | </dl> |
| 268 | </div> |
| 269 | <p> |
| 270 | The common model for a Berkeley DB environment is one in which only |
| 271 | the DB_HOME environment variable, or the |
| 272 | <span class="bold"><strong>db_home</strong></span> argument is specified. In |
| 273 | this case, all data filenames are relative to that directory, and |
| 274 | all files created by the Berkeley DB subsystems will be created in |
| 275 | that directory. |
| 276 | </p> |
| 277 | <p> |
| 278 | The more complex model for a transaction environment might be one |
| 279 | in which a database home is specified, using either the DB_HOME |
| 280 | environment variable or the |
| 281 | <span class="bold"><strong>db_home</strong></span> argument to <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a>; and |
| 282 | then the data directory and logging directory are set to the |
| 283 | relative pathnames of directories underneath the environment |
| 284 | home. |
| 285 | </p> |
| 286 | </div> |
| 287 | <div class="sect2" lang="en" xml:lang="en"> |
| 288 | <div class="titlepage"> |
| 289 | <div> |
| 290 | <div> |
| 291 | <h3 class="title"><a id="idp51756464"></a>Examples</h3> |
| 292 | </div> |
| 293 | </div> |
| 294 | </div> |
| 295 | <p> |
| 296 | Store all files in the directory <code class="filename">/a/database</code>: |
| 297 | </p> |
| 298 | <pre class="programlisting">dbenv->open(dbenv, "/a/database", flags, mode);</pre> |
| 299 | <p> |
| 300 | Create temporary backing files in |
| 301 | <code class="filename">/b/temporary</code>, and all other files in |
| 302 | <code class="filename">/a/database</code>: |
| 303 | </p> |
| 304 | <pre class="programlisting">dbenv->set_tmp_dir(dbenv, "/b/temporary"); |
| 305 | dbenv->open(dbenv, "/a/database", flags, mode);</pre> |
| 306 | <p> |
| 307 | Store data files in <code class="filename">/a/database/datadir</code>, log |
| 308 | files in <code class="filename">/a/database/logdir</code>, and all other |
| 309 | files in the directory <code class="filename">/a/database</code>: |
| 310 | </p> |
| 311 | <pre class="programlisting">dbenv->set_lg_dir(dbenv, "logdir"); |
| 312 | dbenv->set_data_dir(dbenv, "datadir"); |
| 313 | dbenv->open(dbenv, "/a/database", flags, mode);</pre> |
| 314 | <p> |
| 315 | Store data files in <code class="filename">/a/database/data1</code> and |
| 316 | <code class="filename">/b/data2</code>, and all other files in the directory |
| 317 | <code class="filename">/a/database</code>. Any data files that are created |
| 318 | will be created in <code class="filename">/b/data2</code>, because it is the |
| 319 | first data file directory specified: |
| 320 | </p> |
| 321 | <pre class="programlisting">dbenv->set_data_dir(dbenv, "/b/data2"); |
| 322 | dbenv->set_data_dir(dbenv, "data1"); |
| 323 | dbenv->open(dbenv, "/a/database", flags, mode);</pre> |
| 324 | </div> |
| 325 | </div> |
| 326 | <div class="navfooter"> |
| 327 | <hr /> |
| 328 | <table width="100%" summary="Navigation footer"> |
| 329 | <tr> |
| 330 | <td width="40%" align="left"><a accesskey="p" href="env_db_config.html">Prev</a> </td> |
| 331 | <td width="20%" align="center"> |
| 332 | <a accesskey="u" href="env.html">Up</a> |
| 333 | </td> |
| 334 | <td width="40%" align="right"> <a accesskey="n" href="env_region.html">Next</a></td> |
| 335 | </tr> |
| 336 | <tr> |
| 337 | <td width="40%" align="left" valign="top">DB_CONFIG configuration file </td> |
| 338 | <td width="20%" align="center"> |
| 339 | <a accesskey="h" href="index.html">Home</a> |
| 340 | </td> |
| 341 | <td width="40%" align="right" valign="top"> Shared memory regions</td> |
| 342 | </tr> |
| 343 | </table> |
| 344 | </div> |
| 345 | </body> |
| 346 | </html> |