| 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="envbackup.html" title="DB_ENV->backup()" /> |
| 12 | <link rel="next" href="envcreate.html" title="db_env_create" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">DB_ENV->close()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="envbackup.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 5. |
| 26 | The DB_ENV Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="envcreate.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="envclose"></a>DB_ENV->close()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB_ENV->close(DB_ENV *dbenv, u_int32_t flags); </pre> |
| 45 | <p> |
| 46 | The <code class="methodname">DB_ENV->close()</code> method closes the |
| 47 | Berkeley DB environment, freeing any allocated resources and |
| 48 | closing all database handles opened with this environment handle, |
| 49 | as well as closing any underlying subsystems. |
| 50 | </p> |
| 51 | <p> |
| 52 | When you call the <code class="methodname">DB_ENV->close()</code> method, |
| 53 | all open <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> handles and |
| 54 | <a class="link" href="dbc.html" title="Chapter 3. The DBcursor Handle">DBcursor</a> handles are closed |
| 55 | automatically by this function. And, when you close a database |
| 56 | handle, all cursors opened with it are closed automatically. |
| 57 | </p> |
| 58 | <p> |
| 59 | In multiple threads of control, each thread of control opens a |
| 60 | database environment and the database handles within it. When you |
| 61 | close each database handle using the |
| 62 | <code class="methodname">DB_ENV->close()</code> method, by default, the |
| 63 | database is not synchronized and is similar to calling the |
| 64 | <code class="methodname">DB->close(DB_NOSYNC)</code> method. This is to |
| 65 | avoid unncessary database synchronization when there are multiple |
| 66 | environment handles open. To ensure all open database handles are |
| 67 | synchronized when you close the last environment handle, set the |
| 68 | flag parameter value of the <code class="methodname">DB_ENV->close()</code> |
| 69 | method to DB_FORCESYNC. This is similar to calling the |
| 70 | <code class="methodname">DB->close(0)</code> method to close each database |
| 71 | handle. |
| 72 | </p> |
| 73 | <p> |
| 74 | If a database close operation fails, the method returns a non-zero |
| 75 | error value for the first instance of such an error, and continues |
| 76 | to close the rest of the database and environment handles. |
| 77 | </p> |
| 78 | <p> |
| 79 | The <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> handle should |
| 80 | not be closed while any other handle that refers to it is not yet |
| 81 | closed; for example, database environment handles must not be closed |
| 82 | while transactions in the environment |
| 83 | have not yet been committed or aborted. Specifically, this includes the |
| 84 | <a class="link" href="txn.html" title="Chapter 12. The DB_TXN Handle">DB_TXN</a>, |
| 85 | <a class="link" href="logc.html" title="The DB_LOGC Handle">DB_LOGC</a> and |
| 86 | <a class="link" href="memp.html" title="Chapter 8. The DB_MPOOLFILE Handle">DB_MPOOLFILE</a> handles. |
| 87 | </p> |
| 88 | <p> |
| 89 | Where the environment was initialized with the |
| 90 | <a class="link" href="envopen.html#envopen_DB_INIT_LOCK">DB_INIT_LOCK</a> flag, |
| 91 | calling <code class="methodname">DB_ENV->close()</code> does not release any locks still held by the |
| 92 | closing process, providing functionality for long-lived locks. |
| 93 | Processes that want to have all their locks released can do so by |
| 94 | issuing the appropriate <a class="xref" href="lockvec.html" title="DB_ENV->lock_vec()">DB_ENV->lock_vec()</a> call. |
| 95 | </p> |
| 96 | <p> |
| 97 | Where the environment was initialized with the |
| 98 | <a class="link" href="envopen.html#envopen_DB_INIT_MPOOL">DB_INIT_MPOOL</a> flag, |
| 99 | calling <code class="methodname">DB_ENV->close()</code> implies calls to |
| 100 | <a class="xref" href="mempfclose.html" title="DB_MPOOLFILE->close()">DB_MPOOLFILE->close()</a> for any |
| 101 | remaining open files in the memory pool that were returned to this |
| 102 | process by calls to <a class="xref" href="mempfopen.html" title="DB_MPOOLFILE->open()">DB_MPOOLFILE->open()</a>. It does |
| 103 | not imply a call to <a class="xref" href="mempfsync.html" title="DB_MPOOLFILE->sync()">DB_MPOOLFILE->sync()</a> for those |
| 104 | files. |
| 105 | </p> |
| 106 | <p> |
| 107 | Where the environment was initialized with the |
| 108 | <a class="link" href="envopen.html#envopen_DB_INIT_TXN">DB_INIT_TXN</a> |
| 109 | flag, calling <code class="methodname">DB_ENV->close()</code> aborts any |
| 110 | unresolved transactions. Applications should not depend on this |
| 111 | behavior for transactions involving Berkeley DB databases; all |
| 112 | such transactions should be explicitly resolved. The problem with |
| 113 | depending on this semantic is that aborting an unresolved |
| 114 | transaction involving database operations requires a database |
| 115 | handle. Because the database handles should have been closed |
| 116 | before calling <code class="methodname">DB_ENV->close()</code>, it will not |
| 117 | be possible to abort the transaction, and recovery will have to be |
| 118 | run on the Berkeley DB environment before further operations are |
| 119 | done. |
| 120 | </p> |
| 121 | <p> |
| 122 | Where log cursors were created using the |
| 123 | <a class="xref" href="logcursor.html" title="DB_ENV->log_cursor()">DB_ENV->log_cursor()</a> method, |
| 124 | calling <code class="methodname">DB_ENV->close()</code> does not imply |
| 125 | closing those cursors. |
| 126 | </p> |
| 127 | <p> |
| 128 | In multithreaded applications, only a single thread may call the |
| 129 | <code class="methodname">DB_ENV->close()</code> method. |
| 130 | </p> |
| 131 | <p> |
| 132 | After <code class="methodname">DB_ENV->close()</code> has been called, |
| 133 | regardless of its return, the Berkeley DB environment handle may |
| 134 | not be accessed again. |
| 135 | </p> |
| 136 | <p> |
| 137 | The <code class="methodname">DB_ENV->close()</code> <span> |
| 138 | <span> |
| 139 | method returns a non-zero error value on failure and 0 on success. |
| 140 | </span> |
| 141 | |
| 142 | </span> |
| 143 | </p> |
| 144 | <div class="sect2" lang="en" xml:lang="en"> |
| 145 | <div class="titlepage"> |
| 146 | <div> |
| 147 | <div> |
| 148 | <h3 class="title"><a id="idp51260384"></a>Parameters</h3> |
| 149 | </div> |
| 150 | </div> |
| 151 | </div> |
| 152 | <div class="sect3" lang="en" xml:lang="en"> |
| 153 | <div class="titlepage"> |
| 154 | <div> |
| 155 | <div> |
| 156 | <h4 class="title"><a id="idp51253848"></a>flags</h4> |
| 157 | </div> |
| 158 | </div> |
| 159 | </div> |
| 160 | <p> |
| 161 | The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 |
| 162 | or be set to the following value: |
| 163 | </p> |
| 164 | <div class="itemizedlist"> |
| 165 | <ul type="disc"> |
| 166 | <li> |
| 167 | <p><a id="dbenvclose_DB_FORCESYNC"></a> |
| 168 | <code class="literal">DB_FORCESYNC</code> |
| 169 | </p> |
| 170 | <p> |
| 171 | When closing each database handle internally, |
| 172 | synchronize the database. If this flag is not |
| 173 | specified, the database handle is closed without |
| 174 | synchronizing the database. |
| 175 | </p> |
| 176 | </li> |
| 177 | </ul> |
| 178 | </div> |
| 179 | </div> |
| 180 | </div> |
| 181 | <div class="sect2" lang="en" xml:lang="en"> |
| 182 | <div class="titlepage"> |
| 183 | <div> |
| 184 | <div> |
| 185 | <h3 class="title"><a id="idp51306112"></a>Class</h3> |
| 186 | </div> |
| 187 | </div> |
| 188 | </div> |
| 189 | <p> |
| 190 | <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> |
| 191 | </p> |
| 192 | </div> |
| 193 | <div class="sect2" lang="en" xml:lang="en"> |
| 194 | <div class="titlepage"> |
| 195 | <div> |
| 196 | <div> |
| 197 | <h3 class="title"><a id="idp51301256"></a>See Also</h3> |
| 198 | </div> |
| 199 | </div> |
| 200 | </div> |
| 201 | <p> |
| 202 | <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> |
| 203 | </p> |
| 204 | </div> |
| 205 | </div> |
| 206 | <div class="navfooter"> |
| 207 | <hr /> |
| 208 | <table width="100%" summary="Navigation footer"> |
| 209 | <tr> |
| 210 | <td width="40%" align="left"><a accesskey="p" href="envbackup.html">Prev</a> </td> |
| 211 | <td width="20%" align="center"> |
| 212 | <a accesskey="u" href="env.html">Up</a> |
| 213 | </td> |
| 214 | <td width="40%" align="right"> <a accesskey="n" href="envcreate.html">Next</a></td> |
| 215 | </tr> |
| 216 | <tr> |
| 217 | <td width="40%" align="left" valign="top">DB_ENV->backup() </td> |
| 218 | <td width="20%" align="center"> |
| 219 | <a accesskey="h" href="index.html">Home</a> |
| 220 | </td> |
| 221 | <td width="40%" align="right" valign="top"> db_env_create</td> |
| 222 | </tr> |
| 223 | </table> |
| 224 | </div> |
| 225 | </body> |
| 226 | </html> |