1<!--$Id: env_remove.so,v 10.45 2006/12/08 16:22:45 bostic Exp $-->
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: DB_ENV-&gt;remove</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>DB_ENV-&gt;remove</b>
14</td>
15<td align=right>
16<a href="/api_c/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.h&gt;
23<p>
24int
25DB_ENV-&gt;remove(DB_ENV *dbenv, char *db_home, u_int32_t flags);
26</pre></b>
27<hr size=1 noshade>
28<b>Description: DB_ENV-&gt;remove</b>
29<p>The DB_ENV-&gt;remove method destroys a Berkeley DB environment if it is not
30currently in use.  The environment regions, including any backing files,
31are removed.  Any log or database files and the environment directory are
32not removed.</p>
33<p>If there are processes that have called <a href="/api_c/env_open.html">DB_ENV-&gt;open</a> without
34calling <a href="/api_c/env_close.html">DB_ENV-&gt;close</a> (that is, there are processes currently
35using the environment), DB_ENV-&gt;remove will fail without further
36action unless the <a href="/api_c/env_remove.html#DB_FORCE">DB_FORCE</a> flag is set, in which case
37DB_ENV-&gt;remove will attempt to remove the environment, regardless
38of any processes still using it.</p>
39<p>The result of attempting to forcibly destroy the environment when it is
40in use is unspecified.  Processes using an environment often maintain open
41file descriptors for shared regions within it.  On UNIX systems, the
42environment removal will usually succeed, and processes that have already
43joined the region will continue to run in that region without change.
44However, processes attempting to join the environment will either fail
45or create new regions.  On other systems in which the <b>unlink</b>(2) system call will fail if any process has an open file descriptor for
46the file (for example Windows/NT), the region removal will fail.</p>
47<p>Calling DB_ENV-&gt;remove should not be necessary for most applications
48because the Berkeley DB environment is cleaned up as part of normal database
49recovery procedures. However, applications may want to call
50DB_ENV-&gt;remove as part of application shut down to free up system
51resources.  For example, if the <a href="/api_c/env_open.html#DB_SYSTEM_MEM">DB_SYSTEM_MEM</a> flag was specified
52to <a href="/api_c/env_open.html">DB_ENV-&gt;open</a>, it may be useful to call DB_ENV-&gt;remove in
53order to release system shared memory segments that have been allocated.
54Or, on architectures in which mutexes require allocation of underlying
55system resources, it may be useful to call DB_ENV-&gt;remove in order
56to release those resources.  Alternatively, if recovery is not required
57because no database state is maintained across failures, and no system
58resources need to be released, it is possible to clean up an environment
59by simply removing all the Berkeley DB files in the database environment's
60directories.</p>
61<p>In multithreaded applications, only a single thread may call
62DB_ENV-&gt;remove.</p>
63<p>A <a href="/api_c/env_class.html">DB_ENV</a> handle that has already been used to open an environment
64should not be used to call the DB_ENV-&gt;remove method; a new
65<a href="/api_c/env_class.html">DB_ENV</a> handle should be created for that purpose.</p>
66<p>After DB_ENV-&gt;remove has been called, regardless of its return,
67the Berkeley DB environment handle may not be accessed again.</p>
68<p>The DB_ENV-&gt;remove method
69returns a non-zero error value on failure
70and 0 on success.
71</p>
72<b>Parameters</b> <br>
73 <b>db_home</b><ul compact><li>The <b>db_home</b> parameter names the database environment to be removed.</ul>
74<p>When using a Unicode build on Windows (the default), the <b>db_home</b>
75argument will be interpreted as a UTF-8 string, which is equivalent to
76ASCII for Latin characters.</p>
77 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or by bitwise inclusively <b>OR</b>'ing together one
78or more of the following values:
79<br>
80<b><a name="DB_FORCE">DB_FORCE</a></b><ul compact><li>If the <a href="/api_c/env_remove.html#DB_FORCE">DB_FORCE</a> flag is set, the environment is removed, regardless
81of any processes that may still using it, and no locks are acquired
82during this process.  (Generally, the <a href="/api_c/env_remove.html#DB_FORCE">DB_FORCE</a> flag is
83specified only when applications were unable to shut down cleanly, and there
84is a risk that an application may have died holding a Berkeley DB lock.)</ul>
85<a name="2"><!--meow--></a>
86<b><a name="DB_USE_ENVIRON">DB_USE_ENVIRON</a></b><ul compact><li>The Berkeley DB process' environment may be permitted to specify information
87to be used when naming files; see <a href="/ref/env/naming.html">Berkeley DB File Naming</a>.  Because permitting users to specify which files
88are used can create security problems, environment information will be
89used in file naming for all users only if the DB_USE_ENVIRON
90flag is set.</ul>
91<b><a name="DB_USE_ENVIRON_ROOT">DB_USE_ENVIRON_ROOT</a></b><ul compact><li>The Berkeley DB process' environment may be permitted to specify information
92to be used when naming files; see <a href="/ref/env/naming.html">Berkeley DB File Naming</a>.  Because permitting users to specify which files
93are used can create security problems, if the
94DB_USE_ENVIRON_ROOT flag is set, environment information will
95be used for file naming only for users with appropriate permissions (for
96example, users with a user-ID of 0 on UNIX systems).</ul>
97<br></ul>
98<br>
99<br><b>Errors</b>
100<p>The DB_ENV-&gt;remove method
101may fail and return one of the following non-zero errors:</p>
102<br>
103<b>EBUSY</b><ul compact><li>The shared memory region was in use and the force flag was not set.</ul>
104<br>
105<hr size=1 noshade>
106<br><b>Class</b>
107<a href="/api_c/env_class.html">DB_ENV</a>
108<br><b>See Also</b>
109<a href="/api_c/env_list.html">Database Environments and Related Methods</a>
110</tt>
111<table width="100%"><tr><td><br></td><td align=right>
112<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a>
113</td></tr></table>
114<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
115</body>
116</html>
117