1<!--$Id: sync.so,v 10.18 2003/10/18 19:15:53 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: Flushing the database cache</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/verify.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/am/close.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Flushing the database cache</b></p> 17<p>The <a href="/api_c/db_sync.html">DB->sync</a> method flushes all modified records from the database 18cache to disk.</p> 19<p><b>It is important to understand that flushing cached information 20to disk only minimizes the window of opportunity for corrupted data, it 21does not eliminate the possibility.</b></p> 22<p>While unlikely, it is possible for database corruption to happen if a 23system or application crash occurs while writing data to the database. To 24ensure that database corruption never occurs, applications must either:</p> 25<p><ul type=disc> 26<li>Use transactions and logging with automatic recovery. 27<li>Use logging and application-specific recovery. 28<li>Edit a copy of the database, and, once all applications 29using the database have successfully called <a href="/api_c/db_close.html">DB->close</a>, use 30system operations (for example, the POSIX rename system call) to 31atomically replace the original database with the updated copy. 32</ul> 33<table width="100%"><tr><td><br></td><td align=right><a href="/am/verify.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/am/close.html"><img src="/images/next.gif" alt="Next"></a> 34</td></tr></table> 35<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 36</body> 37</html> 38