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_ENV->close()</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="env.html" title="Chapter��5.�� The DB_ENV Handle" /> 11 <link rel="prev" href="envadd_data_dir.html" title="DB_ENV->add_data_dir()" /> 12 <link rel="next" href="envcreate.html" title="db_env_create" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DB_ENV->close()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="envadd_data_dir.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��5.�� 23 The DB_ENV Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="envcreate.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="envclose"></a>DB_ENV->close()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db.h> 39 40int 41DB_ENV->close(DB_ENV *dbenv, u_int32_t flags); </pre> 42 <p> 43 The <code class="methodname">DB_ENV->close()</code> method closes the Berkeley DB environment, 44 freeing any allocated resources and closing any underlying subsystems. 45 </p> 46 <p> 47 The <a class="link" href="env.html" title="Chapter��5.�� The DB_ENV Handle">DB_ENV</a> handle should 48 not be closed while any other handle that refers to it is not yet 49 closed; for example, database environment handles must not be closed 50 while database handles remain open, or transactions in the environment 51 have not yet been committed or aborted. Specifically, this includes the 52 <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a>, 53 <a class="link" href="dbc.html" title="Chapter��3.�� The DBcursor Handle">DBcursor</a>, 54 <a class="link" href="txn.html" title="Chapter��12.�� The DB_TXN Handle">DB_TXN</a>, 55 <a class="link" href="logc.html" title="The DB_LOGC Handle">DB_LOGC</a> and 56 <a class="link" href="memp.html" title="Chapter��8.�� The DB_MPOOLFILE Handle">DB_MPOOLFILE</a> handles. 57 </p> 58 <p> 59 Where the environment was initialized with the 60 <a class="link" href="envopen.html#envopen_DB_INIT_LOCK">DB_INIT_LOCK</a> flag, 61 calling <code class="methodname">DB_ENV->close()</code> does not release any locks still held by the 62 closing process, providing functionality for long-lived locks. 63 Processes that want to have all their locks released can do so by 64 issuing the appropriate <a class="xref" href="lockvec.html" title="DB_ENV->lock_vec()">DB_ENV->lock_vec()</a> call. 65 </p> 66 <p> 67 Where the environment was initialized with the 68 <a class="link" href="envopen.html#envopen_DB_INIT_MPOOL">DB_INIT_MPOOL</a> flag, 69 calling <code class="methodname">DB_ENV->close()</code> implies calls to 70 <a class="xref" href="mempfclose.html" title="DB_MPOOLFILE->close()">DB_MPOOLFILE->close()</a> for any 71 remaining open files in the memory pool that were returned to this 72 process by calls to <a class="xref" href="mempfopen.html" title="DB_MPOOLFILE->open()">DB_MPOOLFILE->open()</a>. It does 73 not imply a call to <a class="xref" href="mempfsync.html" title="DB_MPOOLFILE->sync()">DB_MPOOLFILE->sync()</a> for those 74 files. 75 </p> 76 <p> 77 Where the environment was initialized with the 78 <a class="link" href="envopen.html#envopen_DB_INIT_TXN">DB_INIT_TXN</a> flag, 79 calling <code class="methodname">DB_ENV->close()</code> aborts any unresolved transactions. 80 Applications should not depend on this behavior for transactions 81 involving Berkeley DB databases; all such transactions should be 82 explicitly resolved. The problem with depending on this semantic is 83 that aborting an unresolved transaction involving database operations 84 requires a database handle. Because the database handles should have 85 been closed before calling <code class="methodname">DB_ENV->close()</code>, it will not be possible 86 to abort the transaction, and recovery will have to be run on the 87 Berkeley DB environment before further operations are done. 88 </p> 89 <p> 90 Where log cursors were created using the 91 <a class="xref" href="logcursor.html" title="DB_ENV->log_cursor()">DB_ENV->log_cursor()</a> method, 92 calling <code class="methodname">DB_ENV->close()</code> does not imply closing those cursors. 93 </p> 94 <p> 95 In multithreaded applications, only a single thread may call the 96 <code class="methodname">DB_ENV->close()</code> method. 97 </p> 98 <p> 99 After <code class="methodname">DB_ENV->close()</code> has been called, regardless of its return, the 100 Berkeley DB environment handle may not be accessed again. 101 </p> 102 <p> 103 The <code class="methodname">DB_ENV->close()</code> <span> 104 <span> 105 method returns a non-zero error value on failure and 0 on success. 106 </span> 107 108 </span> 109 </p> 110 <div class="sect2" lang="en" xml:lang="en"> 111 <div class="titlepage"> 112 <div> 113 <div> 114 <h3 class="title"><a id="id1660579"></a>Parameters</h3> 115 </div> 116 </div> 117 </div> 118 <div class="sect3" lang="en" xml:lang="en"> 119 <div class="titlepage"> 120 <div> 121 <div> 122 <h4 class="title"><a id="id1660937"></a>flags</h4> 123 </div> 124 </div> 125 </div> 126 <p> 127 The <span class="bold"><strong>flags</strong></span> parameter is currently 128 unused, and must be set to 0. 129 </p> 130 </div> 131 </div> 132 <div class="sect2" lang="en" xml:lang="en"> 133 <div class="titlepage"> 134 <div> 135 <div> 136 <h3 class="title"><a id="id1661084"></a>Class</h3> 137 </div> 138 </div> 139 </div> 140 <p> 141 <a class="link" href="env.html" title="Chapter��5.�� The DB_ENV Handle">DB_ENV</a> 142 </p> 143 </div> 144 <div class="sect2" lang="en" xml:lang="en"> 145 <div class="titlepage"> 146 <div> 147 <div> 148 <h3 class="title"><a id="id1660580"></a>See Also</h3> 149 </div> 150 </div> 151 </div> 152 <p> 153 <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> 154 </p> 155 </div> 156 </div> 157 <div class="navfooter"> 158 <hr /> 159 <table width="100%" summary="Navigation footer"> 160 <tr> 161 <td width="40%" align="left"><a accesskey="p" href="envadd_data_dir.html">Prev</a>��</td> 162 <td width="20%" align="center"> 163 <a accesskey="u" href="env.html">Up</a> 164 </td> 165 <td width="40%" align="right">��<a accesskey="n" href="envcreate.html">Next</a></td> 166 </tr> 167 <tr> 168 <td width="40%" align="left" valign="top">DB_ENV->add_data_dir()��</td> 169 <td width="20%" align="center"> 170 <a accesskey="h" href="index.html">Home</a> 171 </td> 172 <td width="40%" align="right" valign="top">��db_env_create</td> 173 </tr> 174 </table> 175 </div> 176 </body> 177</html> 178