~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/docs/api_c/env_open.html

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--$Id: env_open.so,v 10.69 2001/05/15 14:44:07 bostic Exp $-->
 
2
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
 
3
<!--All rights reserved.-->
 
4
<html>
 
5
<head>
 
6
<title>Berkeley DB: DB_ENV-&gt;open</title>
 
7
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
 
8
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
 
9
</head>
 
10
<body bgcolor=white>
 
11
<a name="2"><!--meow--></a>
 
12
<table width="100%"><tr valign=top>
 
13
<td>
 
14
<h1>DB_ENV-&gt;open</h1>
 
15
</td>
 
16
<td align=right>
 
17
<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>
 
18
</td></tr></table>
 
19
<hr size=1 noshade>
 
20
<tt>
 
21
<h3><pre>
 
22
#include &lt;db.h&gt;
 
23
<p>
 
24
int
 
25
DB_ENV-&gt;open(DB_ENV *, char *db_home, u_int32_t flags, int mode);
 
26
</pre></h3>
 
27
<h1>Description</h1>
 
28
<p>The DB_ENV-&gt;open function is the interface for opening the Berkeley DB
 
29
environment.  It provides a structure for creating a consistent
 
30
environment for processes using one or more of the features of Berkeley DB.
 
31
<p>The <b>db_home</b> argument to DB_ENV-&gt;open (and filename
 
32
resolution in general) is described in
 
33
<a href="../ref/env/naming.html">Berkeley DB File Naming</a>.
 
34
<p>The <b>flags</b> argument specifies the subsystems that are initialized
 
35
and how the application's environment affects Berkeley DB file naming, among
 
36
other things.
 
37
<p>The <b>flags</b> value must be set to 0 or by bitwise inclusively <b>OR</b>'ing together one or
 
38
more of the following values:
 
39
<p>Because there are a large number of flags that can be specified, they
 
40
have been grouped together by functionality.  The first group of flags
 
41
indicates which of the Berkeley DB subsystems should be initialized:
 
42
<p><dl compact>
 
43
<p><dt><a name="DB_JOINENV">DB_JOINENV</a><dd>Join an existing environment.  This option allows applications to
 
44
join an existing environment without knowing which Berkeley DB subsystems
 
45
the environment supports.
 
46
<p><dt><a name="DB_INIT_CDB">DB_INIT_CDB</a><dd>Initialize locking for the <a href="../ref/cam/intro.html">Berkeley DB Concurrent Data Store</a>
 
47
product.  In this mode, Berkeley DB provides multiple reader/single writer
 
48
access.  The only other subsystem that should be specified with the
 
49
DB_INIT_CDB flag is DB_INIT_MPOOL.
 
50
<p><dt><a name="DB_INIT_LOCK">DB_INIT_LOCK</a><dd>Initialize the locking subsystem.  This subsystem should be used when
 
51
multiple processes or threads are going to be reading and writing a
 
52
Berkeley DB database, so that they do not interfere with each other.  If all
 
53
threads are accessing the database(s) read-only, locking is unnecessary.
 
54
When the DB_INIT_LOCK flag is specified, it is usually necessary
 
55
to run a deadlock detector, as well.  See <a href="../utility/db_deadlock.html">db_deadlock</a> and
 
56
<a href="../api_c/lock_detect.html">lock_detect</a> for more information.
 
57
<p><dt><a name="DB_INIT_LOG">DB_INIT_LOG</a><dd>Initialize the logging subsystem.  This subsystem should be used when
 
58
recovery from application or system failure is necessary.  If the log
 
59
region is being created and log files are already present, the log files
 
60
are reviewed; subsequent log writes are appended to the end of the log,
 
61
rather than overwriting current log entries.
 
62
<p><dt><a name="DB_INIT_MPOOL">DB_INIT_MPOOL</a><dd>Initialize the shared memory buffer pool subsystem.  This subsystem
 
63
should be used whenever an application is using any Berkeley DB access
 
64
method.
 
65
<p><dt><a name="DB_INIT_TXN">DB_INIT_TXN</a><dd>Initialize the transaction subsystem.  This subsystem should be used
 
66
when recovery and atomicity of multiple operations are important.  The
 
67
DB_INIT_TXN flag implies the DB_INIT_LOG flag.
 
68
</dl>
 
69
<p>The second group of flags govern what recovery, if any, is performed when
 
70
the environment is initialized:
 
71
<p><dl compact>
 
72
<p><dt><a name="DB_RECOVER">DB_RECOVER</a><dd>Run normal recovery on this environment before opening it for normal
 
73
use.  If this flag is set, the DB_CREATE flag must also be set
 
74
because the regions will be removed and re-created.
 
75
<p><dt><a name="DB_RECOVER_FATAL">DB_RECOVER_FATAL</a><dd>Run catastrophic recovery on this environment before opening it for
 
76
normal use.  If this flag is set, the DB_CREATE flag must also
 
77
be set because the regions will be removed and re-created.
 
78
</dl>
 
79
<p>A standard part of the recovery process is to remove the existing Berkeley DB
 
80
environment and create a new one in which to perform recovery.  If the
 
81
thread of control performing recovery does not specify the correct
 
82
region initialization information (for example, the correct memory pool
 
83
cache size), the result can be an application running in an environment
 
84
with incorrect cache and other subsystem sizes.  For this reason, the
 
85
thread of control performing recovery should specify correct
 
86
configuration information before calling the DB_ENV-&gt;open function; or it
 
87
should remove the environment after recovery is completed, leaving
 
88
creation of the correctly sized environment to a subsequent call to
 
89
DB_ENV-&gt;open.
 
90
<p>All Berkeley DB recovery processing must be single-threaded; that is, only a
 
91
single thread of control may perform recovery or access a Berkeley DB
 
92
environment while recovery is being performed.  Because it is not an
 
93
error to specify DB_RECOVER for an environment for which no
 
94
recovery is required, it is reasonable programming practice for the
 
95
thread of control responsible for performing recovery and creating the
 
96
environment to always specify the DB_CREATE and
 
97
DB_RECOVER flags during startup.
 
98
<p>The DB_ENV-&gt;open function returns successfully if DB_RECOVER
 
99
or DB_RECOVER_FATAL is specified and no log files exist, so it
 
100
is necessary to ensure that all necessary log files are present before
 
101
running recovery.  For further information, consult <a href="../utility/db_archive.html">db_archive</a>
 
102
and <a href="../utility/db_recover.html">db_recover</a>.
 
103
<p>The third group of flags govern file-naming extensions in the environment:
 
104
<p><dl compact>
 
105
<a name="3"><!--meow--></a>
 
106
<p><dt><a name="DB_USE_ENVIRON">DB_USE_ENVIRON</a><dd>The Berkeley DB process' environment may be permitted to specify information
 
107
to be used when naming files; see <a href="../ref/env/naming.html">Berkeley DB File Naming</a>.  Because permitting users to specify which files
 
108
are used can create security problems, environment information will be
 
109
used in file naming for all users only if the DB_USE_ENVIRON flag is
 
110
set.
 
111
<p><dt><a name="DB_USE_ENVIRON_ROOT">DB_USE_ENVIRON_ROOT</a><dd>The Berkeley DB process' environment may be permitted to specify information
 
112
to be used when naming files; see <a href="../ref/env/naming.html">Berkeley DB File Naming</a>.  Because permitting users to specify which files
 
113
are used can create security problems, if the DB_USE_ENVIRON_ROOT flag
 
114
is set, environment information will be used for file naming only for
 
115
users with appropriate permissions (for example, users with a user-ID
 
116
of 0 on UNIX systems).
 
117
</dl>
 
118
<p>Finally, there are a few additional unrelated flags:
 
119
<p><dl compact>
 
120
<p><dt><a name="DB_CREATE">DB_CREATE</a><dd>Cause Berkeley DB subsystems to create any underlying files, as necessary.
 
121
<p><dt><a name="DB_LOCKDOWN">DB_LOCKDOWN</a><dd>Lock shared Berkeley DB environment files and memory-mapped databases into
 
122
memory.
 
123
<p><dt><a name="DB_PRIVATE">DB_PRIVATE</a><dd>Specify that the environment will only be accessed by a single process
 
124
(although that process may be multithreaded).  This flag has two effects
 
125
on the Berkeley DB environment.  First, all underlying data structures are
 
126
allocated from per-process memory instead of from shared memory that is
 
127
potentially accessible to more than a single process.  Second, mutexes
 
128
are only configured to work between threads.
 
129
<p>This flag should not be specified if more than a single process is
 
130
accessing the environment because it is likely to cause database
 
131
corruption and unpredictable behavior.  For example, if both a server
 
132
application and the Berkeley DB utility <a href="../utility/db_stat.html">db_stat</a> are expected to access
 
133
the environment, the DB_PRIVATE flag should not be
 
134
specified.
 
135
<p><dt><a name="DB_SYSTEM_MEM">DB_SYSTEM_MEM</a><dd>Allocate memory from system shared memory instead of from memory backed
 
136
by the filesystem.  See <a href="../ref/env/region.html">Shared Memory
 
137
Regions</a> for more information.
 
138
<p><dt><a name="DB_THREAD">DB_THREAD</a><dd>Cause the DB_ENV handle returned by DB_ENV-&gt;open to be
 
139
<i>free-threaded</i>; that is, usable by multiple threads within a
 
140
single address space.
 
141
</dl>
 
142
<p>On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, all files created by
 
143
Berkeley DB are created with mode <b>mode</b> (as described in <b>chmod</b>(2)) and modified by the process' umask value at the time of creation
 
144
(see <b>umask</b>(2)).  If <b>mode</b> is 0, Berkeley DB will use a default
 
145
mode of readable and writable by both owner and group.  On Windows
 
146
systems, the mode argument is ignored. The group ownership of created
 
147
files is based on the system and directory defaults, and is not further
 
148
specified by Berkeley DB.
 
149
<p>The DB_ENV-&gt;open function returns a non-zero error value on failure and 0 on success.
 
150
<h1>Environment Variables</h1>
 
151
<p><dl compact>
 
152
<p><dt>DB_HOME<dd>The environment variable <b>DB_HOME</b> may be used as the path of
 
153
the database home, as described in
 
154
<a href="../ref/env/naming.html">Berkeley DB File Naming</a>.
 
155
</dl>
 
156
<h1>Errors</h1>
 
157
<p>The DB_ENV-&gt;open function may fail and return a non-zero error for the following conditions:
 
158
<p><dl compact>
 
159
<p><dt>EAGAIN<dd>The shared memory region was locked and (repeatedly) unavailable.
 
160
</dl>
 
161
<p><dl compact>
 
162
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
 
163
<p>
 
164
The DB_THREAD flag was specified and fast mutexes are not
 
165
available for this architecture.
 
166
<p>The DB_HOME or TMPDIR environment variables were set, but empty.
 
167
<p>An incorrectly formatted <b>NAME VALUE</b> entry or line was found.
 
168
</dl>
 
169
<p><dl compact>
 
170
<p><dt>ENOSPC<dd>HP-UX only: a previously created Berkeley DB environment for this process still
 
171
exists.
 
172
</dl>
 
173
<p>The DB_ENV-&gt;open function may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions.
 
174
If a catastrophic error has occurred, the DB_ENV-&gt;open function may fail and return
 
175
<a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a>, in which case all subsequent Berkeley DB calls will fail
 
176
in the same way.
 
177
<h1>See Also</h1>
 
178
<a href="../api_c/env_create.html">db_env_create</a>,
 
179
<a href="../api_c/env_close.html">DB_ENV-&gt;close</a>,
 
180
<a href="../api_c/env_err.html">DB_ENV-&gt;err</a>, <a href="../api_c/env_err.html">DB_ENV-&gt;errx</a>
 
181
<a href="../api_c/env_open.html">DB_ENV-&gt;open</a>,
 
182
<a href="../api_c/env_remove.html">DB_ENV-&gt;remove</a>,
 
183
<a href="../api_c/env_set_alloc.html">DB_ENV-&gt;set_alloc</a>,
 
184
<a href="../api_c/env_set_cachesize.html">DB_ENV-&gt;set_cachesize</a>,
 
185
<a href="../api_c/env_set_data_dir.html">DB_ENV-&gt;set_data_dir</a>,
 
186
<a href="../api_c/env_set_errcall.html">DB_ENV-&gt;set_errcall</a>,
 
187
<a href="../api_c/env_set_errfile.html">DB_ENV-&gt;set_errfile</a>,
 
188
<a href="../api_c/env_set_errpfx.html">DB_ENV-&gt;set_errpfx</a>,
 
189
<a href="../api_c/env_set_feedback.html">DB_ENV-&gt;set_feedback</a>,
 
190
<a href="../api_c/env_set_flags.html">DB_ENV-&gt;set_flags</a>,
 
191
<a href="../api_c/env_set_mutexlocks.html">DB_ENV-&gt;set_mutexlocks</a>,
 
192
<a href="../api_c/env_set_pageyield.html">db_env_set_pageyield</a>,
 
193
<a href="../api_c/env_set_paniccall.html">DB_ENV-&gt;set_paniccall</a>,
 
194
<a href="../api_c/env_set_panicstate.html">db_env_set_panicstate</a>,
 
195
<a href="../api_c/env_set_rec_init.html">DB_ENV-&gt;set_recovery_init</a>,
 
196
<a href="../api_c/env_set_rpc_server.html">DB_ENV-&gt;set_rpc_server</a>,
 
197
<a href="../api_c/env_set_region_init.html">db_env_set_region_init</a>,
 
198
<a href="../api_c/env_set_shm_key.html">DB_ENV-&gt;set_shm_key</a>,
 
199
<a href="../api_c/env_set_tas_spins.html">db_env_set_tas_spins</a>,
 
200
<a href="../api_c/env_set_tmp_dir.html">DB_ENV-&gt;set_tmp_dir</a>,
 
201
<a href="../api_c/env_set_verbose.html">DB_ENV-&gt;set_verbose</a>,
 
202
<a href="../api_c/env_strerror.html">db_strerror</a>
 
203
and
 
204
<a href="../api_c/env_version.html">db_version</a>.
 
205
</tt>
 
206
<table width="100%"><tr><td><br></td><td align=right>
 
207
<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>
 
208
</td></tr></table>
 
209
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
 
210
</body>
 
211
</html>