1<!--$Id-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB: DbEnv::set_flags</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<table width="100%"><tr valign=top>
12<td>
13<b>DbEnv::set_flags</b>
14</td>
15<td align=right>
16<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a>
17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db_cxx.h&gt;
23<p>
24int
25DbEnv::set_flags(u_int32_t flags, int onoff);
26<p>
27int
28DbEnv::get_flags(u_int32_t *flagsp)
29</pre></b>
30<hr size=1 noshade>
31<b>Description: DbEnv::set_flags</b>
32<p>Configure a database environment.</p>
33<p>The database environment's flag values may also be configured using the
34environment's <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> file.  The syntax of the entry in that
35file is a single line with the string "set_flags", one or more whitespace
36characters, and the method flag parameter as a string; for example, "set_flags
37DB_TXN_NOSYNC".
38Because the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> file is read when the database environment
39is opened, it will silently overrule configuration done before that
40time.</p>
41<p>The DbEnv::set_flags method
42either returns a non-zero error value
43or throws an exception that encapsulates a non-zero error value on
44failure, and returns 0 on success.
45</p>
46<b>Parameters</b> <br>
47 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set by bitwise inclusively <b>OR</b>'ing together one or more
48of the following values:
49<br>
50<b><a name="DB_AUTO_COMMIT">DB_AUTO_COMMIT</a></b><ul compact><li>If set, <a href="../api_cxx/db_class.html">Db</a> handle operations for which no explicit transaction
51handle was specified, and which modify databases in the database
52environment, will be automatically enclosed within a transaction.
53<p>Calling DbEnv::set_flags with the <a href="../api_cxx/env_set_flags.html#DB_AUTO_COMMIT">DB_AUTO_COMMIT</a> flag only affects
54the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
55within the scope of that handle).
56For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
57handles opened in the environment must either set the <a href="../api_cxx/env_set_flags.html#DB_AUTO_COMMIT">DB_AUTO_COMMIT</a> flag
58or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
59file.</p>
60<p>The <a href="../api_cxx/env_set_flags.html#DB_AUTO_COMMIT">DB_AUTO_COMMIT</a> flag may be used to configure Berkeley DB at any time during
61the life of the application.</p></ul>
62<a name="2"><!--meow--></a>
63<b><a name="DB_CDB_ALLDB">DB_CDB_ALLDB</a></b><ul compact><li>If set, Berkeley DB Concurrent Data Store applications will perform locking on an environment-wide
64basis rather than on a per-database basis.
65<p>Calling DbEnv::set_flags with the DB_CDB_ALLDB flag only affects
66the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
67within the scope of that handle).
68For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
69handles opened in the environment must either set the DB_CDB_ALLDB flag
70or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
71file.</p>
72<p>The DB_CDB_ALLDB flag may be used to configure Berkeley DB only before the
73<a href="../api_cxx/env_open.html">DbEnv::open</a> method is called.</p></ul>
74<a name="3"><!--meow--></a>
75<b><a name="DB_DIRECT_DB">DB_DIRECT_DB</a></b><ul compact><li>Turn off system buffering of Berkeley DB database files to avoid double caching.
76<p>Calling DbEnv::set_flags with the DB_DIRECT_DB flag only affects
77the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
78within the scope of that handle).
79For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
80handles opened in the environment must either set the DB_DIRECT_DB flag
81or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
82file.</p>
83<p>The DB_DIRECT_DB flag may be used to configure Berkeley DB at any time during
84the life of the application.</p></ul>
85<a name="4"><!--meow--></a>
86<b><a name="DB_DSYNC_DB">DB_DSYNC_DB</a></b><ul compact><li>Configure Berkeley DB to flush database writes to the backing disk before
87returning from the write system call, rather than flushing database
88writes explicitly in a separate system call, as necessary.  This is only
89available on some systems (for example, systems supporting the
90IEEE/ANSI Std 1003.1 (POSIX) standard O_DSYNC flag, or systems supporting the Windows
91FILE_FLAG_WRITE_THROUGH flag).  This flag may result in inaccurate file
92modification times and other file-level information for Berkeley DB database
93files.  This flag will almost certainly result in a performance decrease
94on most systems.  This flag is only applicable to certain filesysystem
95(for example, the Veritas VxFS filesystem), where the filesystem's
96support for trickling writes back to stable storage behaves badly (or
97more likely, has been misconfigured).
98<p>Calling DbEnv::set_flags with the DB_DSYNC_DB flag only affects
99the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
100within the scope of that handle).
101For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
102handles opened in the environment must either set the DB_DSYNC_DB flag
103or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
104file.</p>
105<p>The DB_DSYNC_DB flag may be used to configure Berkeley DB at any time during
106the life of the application.</p></ul>
107<b><a name="DB_MULTIVERSION">DB_MULTIVERSION</a></b><ul compact><li>If set, all databases in the environment will be opened as if
108DB_MULTIVERSION is passed to <a href="../api_cxx/db_open.html">Db::open</a>.  This flag will
109be ignored for queue databases for which DB_MULTIVERSION is not
110supported.
111<p>Calling DbEnv::set_flags with the DB_MULTIVERSION flag only affects
112the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
113within the scope of that handle).
114For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
115handles opened in the environment must either set the DB_MULTIVERSION flag
116or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
117file.</p>
118<p>The DB_MULTIVERSION flag may be used to configure Berkeley DB at any time during
119the life of the application.</p></ul>
120<a name="5"><!--meow--></a>
121<b><a name="DB_NOLOCKING">DB_NOLOCKING</a></b><ul compact><li>If set, Berkeley DB will grant all requested mutual exclusion mutexes and
122database locks without regard for their actual availability.  This
123functionality should never be used for purposes other than debugging.
124<p>Calling DbEnv::set_flags with the DB_NOLOCKING flag only affects
125the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
126within the scope of that handle).
127</p>
128<p>The DB_NOLOCKING flag may be used to configure Berkeley DB at any time during
129the life of the application.</p></ul>
130<a name="6"><!--meow--></a>
131<b><a name="DB_NOMMAP">DB_NOMMAP</a></b><ul compact><li>If set, Berkeley DB will copy read-only database files into the local cache
132instead of potentially mapping them into process memory (see the
133description of the <a href="../api_cxx/env_set_mp_mmapsize.html">DbEnv::set_mp_mmapsize</a> method for further
134information).
135<p>Calling DbEnv::set_flags with the DB_NOMMAP flag only affects
136the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
137within the scope of that handle).
138For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
139handles opened in the environment must either set the DB_NOMMAP flag
140or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
141file.</p>
142<p>The DB_NOMMAP flag may be used to configure Berkeley DB at any time during
143the life of the application.</p></ul>
144<a name="7"><!--meow--></a>
145<b><a name="DB_NOPANIC">DB_NOPANIC</a></b><ul compact><li>If set, Berkeley DB will ignore any panic state in the database environment.
146(Database environments in a panic state normally refuse all attempts to
147call Berkeley DB functions, returning <a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a>.) This
148functionality should never be used for purposes other than debugging.
149<p>Calling DbEnv::set_flags with the DB_NOPANIC flag only affects
150the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
151within the scope of that handle).
152</p>
153<p>The DB_NOPANIC flag may be used to configure Berkeley DB at any time during
154the life of the application.</p></ul>
155<b><a name="DB_OVERWRITE">DB_OVERWRITE</a></b><ul compact><li>Overwrite files stored in encrypted formats before deleting them.  Berkeley DB
156overwrites files using alternating 0xff, 0x00 and 0xff byte patterns.
157For file overwriting to be effective, the underlying file must be stored
158on a fixed-block filesystem.  Systems with journaling or logging filesystems
159will require operating system support and probably modification of the
160Berkeley DB sources.
161<p>Calling DbEnv::set_flags with the DB_OVERWRITE flag only affects
162the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
163within the scope of that handle).
164</p>
165<p>The DB_OVERWRITE flag may be used to configure Berkeley DB at any time during
166the life of the application.</p></ul>
167<a name="8"><!--meow--></a>
168<b><a name="DB_PANIC_ENVIRONMENT">DB_PANIC_ENVIRONMENT</a></b><ul compact><li>If set, Berkeley DB will set the panic state for the database environment.
169(Database environments in a panic state normally refuse all attempts to
170call Berkeley DB functions, returning <a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a>.) This flag may
171not be specified using the environment's <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> file.
172<p>Calling DbEnv::set_flags with the DB_PANIC_ENVIRONMENT flag affects the
173database environment, including all threads of control accessing the
174database environment.</p>
175<p>The DB_PANIC_ENVIRONMENT flag may be used to configure Berkeley DB only after the
176<a href="../api_cxx/env_open.html">DbEnv::open</a> method is called.</p></ul>
177<a name="9"><!--meow--></a>
178<b><a name="DB_REGION_INIT">DB_REGION_INIT</a></b><ul compact><li>In some applications, the expense of page-faulting the underlying shared
179memory regions can affect performance.  (For example, if the page-fault
180occurs while holding a lock, other lock requests can convoy, and overall
181throughput may decrease.)  If set, Berkeley DB will page-fault shared regions
182into memory when initially creating or joining a Berkeley DB environment.  In
183addition, Berkeley DB will write the shared regions when creating an
184environment, forcing the underlying virtual memory and filesystems to
185instantiate both the necessary memory and the necessary disk space.
186This can also avoid out-of-disk space failures later on.
187<p>Calling DbEnv::set_flags with the DB_REGION_INIT flag only affects
188the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
189within the scope of that handle).
190For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
191handles opened in the environment must either set the DB_REGION_INIT flag
192or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
193file.</p>
194<p>The DB_REGION_INIT flag may be used to configure Berkeley DB at any time during
195the life of the application.</p></ul>
196<b><a name="DB_TIME_NOTGRANTED">DB_TIME_NOTGRANTED</a></b><ul compact><li>If set, database calls timing out based on lock or transaction timeout
197values will
198throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> exception instead of
199<a href="../api_cxx/deadlock_class.html">DbDeadlockException</a>.
200This allows applications to distinguish between operations which have
201deadlocked and operations which have exceeded their time limits.
202<p>Calling DbEnv::set_flags with the DB_TIME_NOTGRANTED flag only affects
203the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
204within the scope of that handle).
205For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
206handles opened in the environment must either set the DB_TIME_NOTGRANTED flag
207or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
208file.</p>
209<p>The DB_TIME_NOTGRANTED flag may be used to configure Berkeley DB at any time during
210the life of the application.</p></ul>
211<a name="10"><!--meow--></a>
212<b><a name="DB_TXN_NOSYNC">DB_TXN_NOSYNC</a></b><ul compact><li>If set, Berkeley DB will not write or synchronously flush the log on transaction
213commit.
214This means that transactions exhibit the ACI (atomicity, consistency,
215and isolation) properties, but not D (durability); that is, database
216integrity will be maintained, but if the application or system fails,
217it is possible some number of the most recently committed transactions
218may be undone during recovery.  The number of transactions at risk is
219governed by how many log updates can fit into the log buffer, how often
220the operating system flushes dirty buffers to disk, and how often the
221log is checkpointed.
222<p>Calling DbEnv::set_flags with the DB_TXN_NOSYNC flag only affects
223the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
224within the scope of that handle).
225For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
226handles opened in the environment must either set the DB_TXN_NOSYNC flag
227or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
228file.</p> <p>The DB_TXN_NOSYNC flag may be used to configure Berkeley DB at any time during
229the life of the application.</p></ul>
230<b><a name="DB_TXN_NOWAIT">DB_TXN_NOWAIT</a></b><ul compact><li>If set and a lock is unavailable for any Berkeley DB operation performed in
231the context of a transaction, cause the operation to
232either return <a href="../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> or throw a
233<a href="../api_cxx/deadlock_class.html">DbDeadlockException</a> exception (or return
234<a href="../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> or throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a>
235exception if configured using the DB_TIME_NOTGRANTED flag).
236<p>Calling DbEnv::set_flags with the DB_TXN_NOWAIT flag only affects
237the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
238within the scope of that handle).
239For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
240handles opened in the environment must either set the DB_TXN_NOWAIT flag
241or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
242file.</p>
243<p>The DB_TXN_NOWAIT flag may be used to configure Berkeley DB at any time during
244the life of the application.</p></ul>
245<b><a name="DB_TXN_SNAPSHOT">DB_TXN_SNAPSHOT</a></b><ul compact><li>If set, all transactions in the environment will be started as if
246DB_TXN_SNAPSHOT were passed to <a href="../api_cxx/txn_begin.html">DbEnv::txn_begin</a>, and all
247non-transactional cursors will be opened as if DB_TXN_SNAPSHOT
248were passed to <a href="../api_cxx/db_cursor.html">Db::cursor</a>.
249<p>Calling DbEnv::set_flags with the DB_TXN_SNAPSHOT flag only affects
250the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
251within the scope of that handle).
252For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
253handles opened in the environment must either set the DB_TXN_SNAPSHOT flag
254or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
255file.</p>
256<p>The DB_TXN_SNAPSHOT flag may be used to configure Berkeley DB at any time during
257the life of the application.</p></ul>
258<a name="11"><!--meow--></a>
259<b><a name="DB_TXN_WRITE_NOSYNC">DB_TXN_WRITE_NOSYNC</a></b><ul compact><li>If set, Berkeley DB will write, but will not synchronously flush, the log on
260transaction commit.
261This means that transactions exhibit the ACI (atomicity, consistency,
262and isolation) properties, but not D (durability); that is, database
263integrity will be maintained, but if the system fails, it is possible
264some number of the most recently committed transactions may be undone
265during recovery.  The number of transactions at risk is governed by how
266often the system flushes dirty buffers to disk and how often the log is
267checkpointed.
268<p>Calling DbEnv::set_flags with the DB_TXN_WRITE_NOSYNC flag only affects
269the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
270within the scope of that handle).
271For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
272handles opened in the environment must either set the DB_TXN_WRITE_NOSYNC flag
273or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
274file.</p>
275<p>The DB_TXN_WRITE_NOSYNC flag may be used to configure Berkeley DB at any time during
276the life of the application.</p></ul>
277<a name="12"><!--meow--></a>
278<b><a name="DB_YIELDCPU">DB_YIELDCPU</a></b><ul compact><li>If set, Berkeley DB will yield the processor immediately after each page or
279mutex acquisition.  This functionality should never be used for purposes
280other than stress testing.
281<p>Calling DbEnv::set_flags with the DB_YIELDCPU flag only affects
282the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle (and any other Berkeley DB handles opened
283within the scope of that handle).
284For consistent behavior across the environment, all <a href="../api_cxx/env_class.html">DbEnv</a>
285handles opened in the environment must either set the DB_YIELDCPU flag
286or the flag should be specified in the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration
287file.</p>
288<p>The DB_YIELDCPU flag may be used to configure Berkeley DB at any time during
289the life of the application.</p></ul>
290<br></ul>
291 <b>onoff</b><ul compact><li>If the <b>onoff</b> parameter is zero, the specified flags are cleared;
292otherwise they are set.</ul>
293<br>
294<br><b>Errors</b>
295<p>The DbEnv::set_flags method
296may fail and throw
297<a href="../api_cxx/except_class.html">DbException</a>,
298encapsulating one of the following non-zero errors, or return one of
299the following non-zero errors:</p>
300<br>
301<b>EINVAL</b><ul compact><li>An
302invalid flag value or parameter was specified.</ul>
303<br>
304<hr size=1 noshade>
305<b>Description: DbEnv::get_flags</b>
306<p>The DbEnv::get_flags method returns the configuration flags.</p>
307<p>The DbEnv::get_flags method may be called at any time during the life of the
308application.</p>
309<p>The DbEnv::get_flags method
310either returns a non-zero error value
311or throws an exception that encapsulates a non-zero error value on
312failure, and returns 0 on success.
313</p>
314<b>Parameters</b> <br>
315 <b>flagsp</b><ul compact><li>The DbEnv::get_flags method returns  the
316configuration flags in <b>flagsp</b>.</ul>
317<br>
318<hr size=1 noshade>
319<br><b>Class</b>
320<a href="../api_cxx/env_class.html">DbEnv</a>
321<br><b>See Also</b>
322<a href="../api_cxx/env_list.html">Database Environments and Related Methods</a>
323</tt>
324<table width="100%"><tr><td><br></td><td align=right>
325<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
326</td></tr></table>
327<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
328</body>
329</html>
330