2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB: db_load</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<a name="2"><!--meow--></a>
13
<table width="100%"><tr valign=top>
18
<a href="../api_c/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
22
<h3><pre>db_load [<b>-nTV</b>] [<b>-c name=value</b>] [<b>-f file</b>]
23
[<b>-h home</b>] [<b>-P password</b>] [<b>-t btree | hash | queue | recno</b>] file</pre></h3>
25
<a name="3"><!--meow--></a>
26
<p>The db_load utility reads from the standard input and loads it
27
into the database <b>file</b>. The database <b>file</b> is created if
28
it does not already exist.
29
<p>The input to db_load must be in the output format specified by the
30
<a href="../utility/db_dump.html">db_dump</a> utility, utilities, or as specified for the <b>-T</b>
32
<p>The options are as follows:
34
<p><dt><b>-c</b><dd>Specify configuration options ignoring any value they may have based on
35
the input. The command-line format is <b>name=value</b>. See the
36
Supported Keywords section below for a list of keywords supported by
38
<p><dt><b>-f</b><dd>Read from the specified <b>input</b> file instead of from the standard
40
<p><dt><b>-h</b><dd>Specify a home directory for the database environment.
41
<p>If a home directory is specified, the database environment is opened
42
using the <a href="../api_c/env_open.html#DB_INIT_LOCK">DB_INIT_LOCK</a>, <a href="../api_c/env_open.html#DB_INIT_LOG">DB_INIT_LOG</a>,
43
<a href="../api_c/env_open.html#DB_INIT_MPOOL">DB_INIT_MPOOL</a>, <a href="../api_c/env_open.html#DB_INIT_TXN">DB_INIT_TXN</a>, and <a href="../api_c/env_open.html#DB_USE_ENVIRON">DB_USE_ENVIRON</a>
44
flags to <a href="../api_c/env_open.html">DB_ENV->open</a>. (This means that db_load can be
45
used to load data into databases while they are in use by other
46
processes.) If the <a href="../api_c/env_open.html">DB_ENV->open</a> call fails, or if no home
47
directory is specified, the database is still updated, but the
48
environment is ignored; for example, no locking is done.
49
<p><dt><b>-n</b><dd>Do not overwrite existing keys in the database when loading into an
50
already existing database. If a key/data pair cannot be loaded into the
51
database for this reason, a warning message is displayed on the standard
52
error output, and the key/data pair are skipped.
53
<p><dt><b>-P</b><dd>Specify an environment password. Although Berkeley DB utilities overwrite
54
password strings as soon as possible, be aware there may be a window of
55
vulnerability on systems where unprivileged users can see command-line
56
arguments or where utilities are not able to overwrite the memory
57
containing the command-line arguments.
58
<p><dt><b>-T</b><dd>The <b>-T</b> option allows non-Berkeley DB applications to easily load text
60
<p>If the database to be created is of type Btree or Hash, or the keyword
61
<b>keys</b> is specified as set, the input must be paired lines of text,
62
where the first line of the pair is the key item, and the second line of
63
the pair is its corresponding data item. If the database to be created
64
is of type Queue or Recno and the keywork <b>keys</b> is not set, the
65
input must be lines of text, where each line is a new data item for the
67
<p>A simple escape mechanism, where newline and backslash (\)
68
characters are special, is applied to the text input. Newline characters
69
are interpreted as record separators. Backslash characters in the text
70
will be interpreted in one of two ways: If the backslash character
71
precedes another backslash character, the pair will be interpreted as a
72
literal backslash. If the backslash character precedes any other
73
character, the two characters following the backslash will be interpreted
74
as a hexadecimal specification of a single character; for example,
75
\0a is a newline character in the ASCII character set.
76
<p>For this reason, any backslash or newline characters that naturally
77
occur in the text input must be escaped to avoid misinterpretation by
79
<p>If the <b>-T</b> option is specified, the underlying access method type
80
must be specified using the <b>-t</b> option.
81
<p><dt><b>-t</b><dd>Specify the underlying access method. If no <b>-t</b> option is
82
specified, the database will be loaded into a database of the same type
83
as was dumped; for example, a Hash database will be created if a Hash
85
<p>Btree and Hash databases may be converted from one to the other. Queue
86
and Recno databases may be converted from one to the other. If the
87
<b>-k</b> option was specified on the call to <a href="../utility/db_dump.html">db_dump</a> then Queue
88
and Recno databases may be converted to Btree or Hash, with the key being
89
the integer record number.
90
<p><dt><b>-V</b><dd>Write the library version number to the standard output, and exit.
92
<p>The db_load utility may be used with a Berkeley DB environment (as described for the
93
<b>-h</b> option, the environment variable <b>DB_HOME</b>, or
94
because the utility was run in a directory containing a Berkeley DB
95
environment). In order to avoid environment corruption when using a
96
Berkeley DB environment, db_load should always be given the chance to
97
detach from the environment and exit gracefully. To cause db_load
98
to release all environment resources and exit cleanly, send it an
99
interrupt signal (SIGINT).
100
<p>The db_load utility exits 0 on success, 1 if one or more key/data
101
pairs were not loaded into the database because the key already existed,
102
and >1 if an error occurs.
104
<p>The db_load utility can be used to load text files into databases.
105
For example, the following command loads the standard UNIX
106
<i>/etc/passwd</i> file into a database, with the login name as the
107
key item and the entire password entry as the data item:
108
<p><blockquote><pre>awk -F: '{print $1; print $0}' < /etc/passwd |
109
sed 's/\\/\\\\/g' | db_load -T -t hash passwd.db</pre></blockquote>
110
<p>Note that backslash characters naturally occurring in the text are escaped
111
to avoid interpretation as escape characters by db_load.
112
<h1>Environment Variables</h1>
114
<p><dt>DB_HOME<dd>If the <b>-h</b> option is not specified and the environment variable
115
DB_HOME is set, it is used as the path of the database home, as described
116
in <a href="../api_c/env_open.html">DB_ENV->open</a>.
118
<h3>Supported Keywords</h3>
119
The following keywords are supported for the <b>-c</b> command-line
120
option to the db_load utility. See <a href="../api_c/db_open.html">DB->open</a> for further
121
discussion of these keywords and what values should be specified.
122
<p>The parenthetical listing specifies how the value part of the
123
<b>name=value</b> pair is interpreted. Items listed as (boolean)
124
expect value to be <b>1</b> (set) or <b>0</b> (unset). Items listed
125
as (number) convert value to a number. Items listed as (string) use
126
the string value without modification.
128
<dt>bt_minkey (number)<dd>The minimum number of keys per page.
129
<dt>chksum (boolean)<dd>Enable page checksums.
130
<dt>database (string)<dd>The database to load.
131
<dt>db_lorder (number)<dd>The byte order for integers in the stored database metadata.
132
<dt>db_pagesize (number)<dd>The size of database pages, in bytes.
133
<dt>duplicates (boolean)<dd>The value of the <a href="../api_c/db_set_flags.html#DB_DUP">DB_DUP</a> flag.
134
<dt>dupsort (boolean)<dd>The value of the <a href="../api_c/db_set_flags.html#DB_DUPSORT">DB_DUPSORT</a> flag.
135
<dt>extentsize (number)<dd>The size of database extents, in pages, for Queue databases configured
137
<dt>h_ffactor (number)<dd>The density within the Hash database.
138
<dt>h_nelem (number)<dd>The size of the Hash database.
139
<dt>keys (boolean)<dd>Specify whether keys are present for Queue or Recno databases.
140
<dt>re_len (number)<dd>Specify fixed-length records of the specified length.
141
<dt>re_pad (string)<dd>Specify the fixed-length record pad character.
142
<dt>recnum (boolean)<dd>The value of the <a href="../api_c/db_set_flags.html#DB_RECNUM">DB_RECNUM</a> flag.
143
<dt>renumber (boolean)<dd>The value of the <a href="../api_c/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a> flag.
144
<dt>subdatabase (string)<dd>The subdatabase to load.
147
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>