1<!--$Id: close.so,v 10.18 2003/10/18 19:15:51 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 Reference Guide: Database close</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<a name="2"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Access Methods</dl></b></td> 14<td align=right><a href="/am/sync.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/am/second.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Database close</b></p> 17<p>The <a href="/api_c/db_close.html">DB->close</a> method closes the <a href="/api_c/db_class.html">DB</a> database handle. By 18default, <a href="/api_c/db_close.html">DB->close</a> also flushes all modified records from the 19database cache to disk.</p> 20<p>There is one flag that you can set to customize <a href="/api_c/db_close.html">DB->close</a>:</p> 21<br> 22<b><a href="/api_c/db_close.html#DB_NOSYNC">DB_NOSYNC</a></b><ul compact><li>Do not flush cached information to disk.</ul> 23<br> 24<b>It is important to understand that flushing cached information 25to disk only minimizes the window of opportunity for corrupted data, it 26does not eliminate the possibility.</b> 27<p>While unlikely, it is possible for database corruption to happen if a 28system or application crash occurs while writing data to the database. To 29ensure that database corruption never occurs, applications must either:</p> 30<p><ul type=disc> 31<li>Use transactions and logging with automatic recovery. 32<li>Use logging and application-specific recovery. 33<li>Edit a copy of the database, and, once all applications 34using the database have successfully called <a href="/api_c/db_close.html">DB->close</a>, use 35system operations (for example, the POSIX rename system call) to 36atomically replace the original database with the updated copy. 37</ul> 38<table width="100%"><tr><td><br></td><td align=right><a href="/am/sync.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/am/second.html"><img src="/images/next.gif" alt="Next"></a> 39</td></tr></table> 40<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 41</body> 42</html> 43