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>db_load</title> 7 <link rel="stylesheet" href="apiReference.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 C++ API Reference" /> 10 <link rel="up" href="utilities.html" title="Appendix��1.�� Berkeley DB Command Line Utilities" /> 11 <link rel="prev" href="db_hotbackup.html" title="db_hotbackup" /> 12 <link rel="next" href="db_printlog.html" title="db_printlog" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">db_load</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="db_hotbackup.html">Prev</a>��</td> 22 <th width="60%" align="center">Appendix��1.�� 23 Berkeley DB Command Line Utilities 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="db_printlog.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="db_load"></a>db_load</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">db_load [-nTV] [-c name=value] [-f file] 39 [-h home] [-P password] [-t btree | hash | queue | recno] file 40 41db_load [-r lsn | fileid] [-h home] [-P password] file </pre> 42 <p> 43 The <span class="command"><strong>db_load</strong></span> utility reads from the standard input and loads it into 44 the database <span class="bold"><strong>file</strong></span>. The database 45 <span class="bold"><strong>file</strong></span> is created if it does not 46 already exist. 47 </p> 48 <p> 49 The input to <span class="command"><strong>db_load</strong></span> must be in the output format specified by the 50 <a class="xref" href="db_dump.html" title="db_dump">db_dump</a> utility, 51 utilities, or as specified for the <span class="bold"><strong>-T</strong></span> 52 below. 53 </p> 54 <p> 55 The options are as follows: 56 </p> 57 <div class="itemizedlist"> 58 <ul type="disc"> 59 <li> 60 <p> 61 <span class="bold"><strong>-c</strong></span> 62 </p> 63 <p> 64 Specify configuration options ignoring any value they may have based 65 on the input. The command-line format is <span class="bold"><strong>name=value</strong></span>. See the Supported Keywords section 66 below for a list of keywords supported by the <span class="bold"><strong>-c</strong></span> option. 67 </p> 68 </li> 69 <li> 70 <p> 71 <span class="bold"><strong>-f</strong></span> 72 </p> 73 <p> 74 Read from the specified <span class="bold"><strong>input</strong></span> file 75 instead of from the standard input. 76 </p> 77 </li> 78 <li> 79 <p> 80 <span class="bold"><strong>-h</strong></span> 81 </p> 82 <p> 83 Specify a home directory for the database environment. 84 </p> 85 <p> 86 If a home directory is specified, the database environment is opened 87 using the 88 <a class="link" href="envopen.html#envopen_DB_INIT_LOCK">DB_INIT_LOCK</a>, 89 <a class="link" href="envopen.html#envopen_DB_INIT_LOG">DB_INIT_LOG</a>, 90 <a class="link" href="envopen.html#envopen_DB_INIT_MPOOL">DB_INIT_MPOOL</a>, 91 <a class="link" href="envopen.html#envopen_DB_INIT_TXN">DB_INIT_TXN</a>, and 92 <a class="link" href="envopen.html#envopen_DB_USE_ENVIRON">DB_USE_ENVIRON</a> 93 flags to <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> 94 (This means that <span class="command"><strong>db_load</strong></span> can be used to load data into databases while 95 they are in use by other processes.) If the 96 <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> call fails, or if 97 no home directory is specified, the database is still updated, but the 98 environment is ignored; for example, no locking is done. 99 </p> 100 </li> 101 <li> 102 <p> 103 <span class="bold"><strong>-n</strong></span> 104 </p> 105 <p> 106 Do not overwrite existing keys in the database when loading into an 107 already existing database. If a key/data pair cannot be loaded into 108 the database for this reason, a warning message is displayed on the 109 standard error output, and the key/data pair are skipped. 110 </p> 111 </li> 112 <li> 113 <p> 114 <span class="bold"><strong>-P</strong></span> 115 </p> 116 <p> 117 Specify an environment password. Although Berkeley DB utilities 118 overwrite password strings as soon as possible, be aware there may be 119 a window of vulnerability on systems where unprivileged users can see 120 command-line arguments or where utilities are not able to overwrite 121 the memory containing the command-line arguments. 122 </p> 123 </li> 124 <li> 125 <p> 126 <span class="bold"><strong>-r</strong></span> 127 </p> 128 <p> 129 Reset the database's file ID or log sequence numbers (LSNs). 130 </p> 131 <p> 132 All database pages in transactional environments contain references to 133 the environment's log records. In order to copy a database into a 134 different database environment, database page references to the old 135 environment's log records must be reset, otherwise data corruption can 136 occur when the database is modified in the new environment. The 137 <span class="bold"><strong>-r</strong></span> <span class="bold"><strong>lsn</strong></span> option resets a database's log sequence 138 numbers. 139 </p> 140 <p> 141 All databases contain an ID string used to identify the database in 142 the database environment cache. If a database is copied, and used in 143 the same environment as another file with the same ID string, 144 corruption can occur. The <span class="bold"><strong>-r</strong></span> 145 <span class="bold"><strong>fileid</strong></span> option resets a database's 146 file ID to a new value. 147 </p> 148 <p> 149 <span class="bold"><strong>In both cases, the physical file specified by 150 the <span class="bold"><strong>file</strong></span> argument is modified 151 in-place.</strong></span> 152 </p> 153 </li> 154 <li> 155 <p> 156 <span class="bold"><strong>-T</strong></span> 157 </p> 158 <p> 159 The <span class="bold"><strong>-T</strong></span> option allows non-Berkeley DB 160 applications to easily load text files into databases. 161 </p> 162 <p> 163 If the database to be created is of type Btree or Hash, or the keyword 164 <span class="bold"><strong>keys</strong></span> is specified as set, the input 165 must be paired lines of text, where the first line of the pair is the 166 key item, and the second line of the pair is its corresponding data 167 item. If the database to be created is of type Queue or Recno and the 168 keyword <span class="bold"><strong>keys</strong></span> is not set, the input 169 must be lines of text, where each line is a new data item for the 170 database. 171 </p> 172 <p> 173 A simple escape mechanism, where newline and backslash (\) characters 174 are special, is applied to the text input. Newline characters are 175 interpreted as record separators. Backslash characters in the text 176 will be interpreted in one of two ways: If the backslash character 177 precedes another backslash character, the pair will be interpreted as 178 a literal backslash. If the backslash character precedes any other 179 character, the two characters following the backslash will be 180 interpreted as a hexadecimal specification of a single character; for 181 example, \0a is a newline character in the ASCII character set. 182 </p> 183 <p> 184 For this reason, any backslash or newline characters that naturally 185 occur in the text input must be escaped to avoid misinterpretation by 186 <span class="command"><strong>db_load</strong></span>. 187 </p> 188 <p> 189 If the <span class="bold"><strong>-T</strong></span> option is specified, the 190 underlying access method type must be specified using the <span class="bold"><strong>-t</strong></span> option. 191 </p> 192 </li> 193 <li> 194 <p> 195 <span class="bold"><strong>-t</strong></span> 196 </p> 197 <p> 198 Specify the underlying access method. If no <span class="bold"><strong>-t</strong></span> option is specified, the database will be 199 loaded into a database of the same type as was dumped; for example, a 200 Hash database will be created if a Hash database was dumped. 201 </p> 202 <p> 203 Btree and Hash databases may be converted from one to the other. 204 Queue and Recno databases may be converted from one to the other. If 205 the <span class="bold"><strong>-k</strong></span> option was specified on the 206 call to <a class="xref" href="db_dump.html" title="db_dump">db_dump</a> then 207 Queue and Recno databases may be converted to Btree or Hash, with the 208 key being the integer record number. 209 </p> 210 </li> 211 <li> 212 <p> 213 <span class="bold"><strong>-V</strong></span> 214 </p> 215 <p> 216 Write the library version number to the standard output, and exit. 217 </p> 218 </li> 219 </ul> 220 </div> 221 <p> 222 The <span class="command"><strong>db_load</strong></span> utility may be used with a Berkeley DB environment (as 223 described for the <span class="bold"><strong>-h</strong></span> option, the 224 environment variable <span class="bold"><strong>DB_HOME</strong></span>, or 225 because the utility was run in a directory containing a Berkeley DB 226 environment). In order to avoid environment corruption when using a 227 Berkeley DB environment, <span class="command"><strong>db_load</strong></span> should always be given the chance to 228 detach from the environment and exit gracefully. To cause <span class="command"><strong>db_load</strong></span> to 229 release all environment resources and exit cleanly, send it an 230 interrupt signal (SIGINT). 231 </p> 232 <p> 233 The <span class="command"><strong>db_load</strong></span> utility exits 0 on success, 1 if one or more key/data 234 pairs were not loaded into the database because the key already 235 existed, and >1 if an error occurs. 236 </p> 237 <div class="sect2" lang="en" xml:lang="en"> 238 <div class="titlepage"> 239 <div> 240 <div> 241 <h3 class="title"><a id="id1718840"></a>Examples</h3> 242 </div> 243 </div> 244 </div> 245 <p> 246 The <span class="command"><strong>db_load</strong></span> utility can be used to load text files into databases. For 247 example, the following command loads the standard UNIX 248 <span class="emphasis"><em>/etc/passwd</em></span> file into a database, with the login 249 name as the key item and the entire password entry as the data item: 250 </p> 251 <pre class="programlisting"> awk -F: '{print $1; print $0}' < /etc/passwd | 252 sed 's/\\/\\\\/g' | db_load -T -t hash passwd.db </pre> 253 <p> 254 Note that backslash characters naturally occurring in the text are 255 escaped to avoid interpretation as escape characters by 256 <span class="command"><strong>db_load</strong></span>. 257 </p> 258 </div> 259 <div class="sect2" lang="en" xml:lang="en"> 260 <div class="titlepage"> 261 <div> 262 <div> 263 <h3 class="title"><a id="id1718897"></a>Environment Variables</h3> 264 </div> 265 </div> 266 </div> 267 <div class="sect3" lang="en" xml:lang="en"> 268 <div class="titlepage"> 269 <div> 270 <div> 271 <h4 class="title"><a id="id1719359"></a>DB_HOME</h4> 272 </div> 273 </div> 274 </div> 275 <p> 276 If the <span class="bold"><strong>-h</strong></span> option is not specified and 277 the environment variable DB_HOME is set, it is used as the path of the 278 database home, as described in the 279 <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> method. 280 </p> 281 </div> 282 </div> 283 <div class="sect2" lang="en" xml:lang="en"> 284 <div class="titlepage"> 285 <div> 286 <div> 287 <h3 class="title"><a id="id1719360"></a>Supported Keywords</h3> 288 </div> 289 </div> 290 </div> 291 <p> 292 The following keywords are supported for the <span class="bold"><strong>-c</strong></span> command-line 293 option to the <span class="command"><strong>db_load</strong></span> utility. See the 294 <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> method 295 for further discussion of these keywords and what values should be 296 specified. 297 </p> 298 <p> 299 The parenthetical listing specifies how the value part of the <span class="bold"><strong>name=value</strong></span> pair is interpreted. Items listed as (boolean) 300 expect value to be <span class="bold"><strong>1</strong></span> (set) or <span class="bold"><strong>0</strong></span> (unset). Items listed as (number) convert value to a 301 number. Items listed as (string) use the string value without modification. 302 </p> 303 <div class="itemizedlist"> 304 <ul type="disc"> 305 <li> 306 <p> 307 <span class="bold"><strong>bt_minkey (number)</strong></span> 308 </p> 309 <p> 310 The minimum number of keys per page. 311 </p> 312 </li> 313 <li> 314 <p> 315 <span class="bold"><strong>chksum (boolean)</strong></span> 316 </p> 317 <p> 318 Enable page checksums. 319 </p> 320 </li> 321 <li> 322 <p> 323 <span class="bold"><strong>database (string)</strong></span> 324 </p> 325 <p> 326 The database to load. 327 </p> 328 </li> 329 <li> 330 <p> 331 <span class="bold"><strong>db_lorder (number)</strong></span> 332 </p> 333 <p> 334 The byte order for integers in the stored database metadata. 335 For big endian systems, the order should be 4,321 while 336 for little endian systems is should be 1,234. 337 </p> 338 </li> 339 <li> 340 <p> 341 <span class="bold"><strong>db_pagesize (number)</strong></span> 342 </p> 343 <p> 344 The size of database pages, in bytes. 345 </p> 346 </li> 347 <li> 348 <p> 349 <span class="bold"><strong>duplicates (boolean)</strong></span> 350 </p> 351 <p> 352 The value of the 353 <a class="link" href="dbset_flags.html#dbset_flags_DB_DUP">DB_DUP</a> 354 flag. 355 </p> 356 </li> 357 <li> 358 <p> 359 <span class="bold"><strong>dupsort (boolean)</strong></span> 360 </p> 361 <p> 362 The value of the 363 <a class="link" href="dbset_flags.html#dbset_flags_DB_DUPSORT">DB_DUPSORT</a> 364 flag. 365 </p> 366 </li> 367 <li> 368 <p> 369 <span class="bold"><strong>extentsize (number)</strong></span> 370 </p> 371 <p> 372 The size of database extents, in pages, for Queue databases configured to use 373 extents. 374 </p> 375 </li> 376 <li> 377 <p> 378 <span class="bold"><strong>h_ffactor (number)</strong></span> 379 </p> 380 <p> 381 The density within the Hash database. 382 </p> 383 </li> 384 <li> 385 <p> 386 <span class="bold"><strong>h_nelem (number)</strong></span> 387 </p> 388 <p> 389 The size of the Hash database. 390 </p> 391 </li> 392 <li> 393 <p> 394 <span class="bold"><strong>keys (boolean)</strong></span> 395 </p> 396 <p> 397 Specify whether keys are present for Queue or Recno databases. 398 </p> 399 </li> 400 <li> 401 <p> 402 <span class="bold"><strong>re_len (number)</strong></span> 403 </p> 404 <p> 405 Specify the length for fixed-length records. This 406 number represents different things, depending on the 407 access method the database is using. See the 408 <a class="xref" href="dbset_re_len.html" title="Db::set_re_len()">Db::set_re_len()</a> 409 method for details on what this number represents. 410 </p> 411 </li> 412 <li> 413 <p> 414 <span class="bold"><strong>re_pad (string)</strong></span> 415 </p> 416 <p> 417 Specify the fixed-length record pad character. 418 </p> 419 </li> 420 <li> 421 <p> 422 <span class="bold"><strong>recnum (boolean)</strong></span> 423 </p> 424 <p> 425 The value of the 426 <a class="link" href="dbset_flags.html#dbset_flags_DB_RECNUM">DB_RECNUM</a> 427 flag. 428 </p> 429 </li> 430 <li> 431 <p> 432 <span class="bold"><strong>renumber (boolean)</strong></span> 433 </p> 434 <p> 435 The value of the 436 <a class="link" href="dbset_flags.html#dbset_flags_DB_RECNUM">DB_RENUMBER</a> 437 flag. 438 </p> 439 </li> 440 <li> 441 <p> 442 <span class="bold"><strong>subdatabase (string)</strong></span> 443 </p> 444 <p> 445 The subdatabase to load. 446 </p> 447 </li> 448 </ul> 449 </div> 450 </div> 451 </div> 452 <div class="navfooter"> 453 <hr /> 454 <table width="100%" summary="Navigation footer"> 455 <tr> 456 <td width="40%" align="left"><a accesskey="p" href="db_hotbackup.html">Prev</a>��</td> 457 <td width="20%" align="center"> 458 <a accesskey="u" href="utilities.html">Up</a> 459 </td> 460 <td width="40%" align="right">��<a accesskey="n" href="db_printlog.html">Next</a></td> 461 </tr> 462 <tr> 463 <td width="40%" align="left" valign="top">db_hotbackup��</td> 464 <td width="20%" align="center"> 465 <a accesskey="h" href="index.html">Home</a> 466 </td> 467 <td width="40%" align="right" valign="top">��db_printlog</td> 468 </tr> 469 </table> 470 </div> 471 </body> 472</html> 473