<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>DB->sync()</title> <link rel="stylesheet" href="apiReference.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> <link rel="start" href="index.html" title="Berkeley DB C API Reference" /> <link rel="up" href="db.html" title="Chapter 2. The DB Handle" /> <link rel="prev" href="dbstat_print.html" title="DB->stat_print()" /> <link rel="next" href="dbtruncate.html" title="DB->truncate()" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">DB->sync()</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="dbstat_print.html">Prev</a> </td> <th width="60%" align="center">Chapter 2. The DB Handle </th> <td width="20%" align="right"> <a accesskey="n" href="dbtruncate.html">Next</a></td> </tr> </table> <hr /> </div> <div class="sect1" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h2 class="title" style="clear: both"><a id="dbsync"></a>DB->sync()</h2> </div> </div> </div> <pre class="programlisting">#include <db.h> int DB->sync(DB *db, u_int32_t flags); </pre> <p> The <code class="methodname">DB->sync()</code> method flushes any cached information to disk. </p> <p> If the database is in memory only, the <code class="methodname">DB->sync()</code> method has no effect and will always succeed. </p> <p> <span class="bold"><strong>It is important to understand that flushing cached information to disk only minimizes the window of opportunity for corrupted data.</strong></span> Although unlikely, it is possible for database corruption to happen if a system or application crash occurs while writing data to the database. To ensure that database corruption never occurs, applications must either: use transactions and logging with automatic recovery; use logging and application-specific recovery; or edit a copy of the database, and once all applications using the database have successfully called <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a>, atomically replace the original database with the updated copy. </p> <p> The <code class="methodname">DB->sync()</code> <span> <span> method returns a non-zero error value on failure and 0 on success. </span> </span> </p> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1651993"></a>Parameters</h3> </div> </div> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1651971"></a>flags</h4> </div> </div> </div> <p> The <span class="bold"><strong>flags</strong></span> parameter is currently unused, and must be set to 0. </p> </div> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1652141"></a>Errors</h3> </div> </div> </div> <p> The <code class="methodname">DB->sync()</code> <span> <span> method may fail and return one of the following non-zero errors: </span> </span> </p> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1652133"></a> DB_REP_HANDLE_DEAD</h4> </div> </div> </div> <p> When a client synchronizes with the master, it is possible for committed transactions to be rolled back. This invalidates all the database and cursor handles opened in the replication environment. Once this occurs, an attempt to use such a handle will return <code class="literal">DB_REP_HANDLE_DEAD</code>. The application will need to discard the handle and open a new one in order to continue processing. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1651970"></a>DB_REP_LOCKOUT</h4> </div> </div> </div> <p> The operation was blocked by client/master synchronization. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1651997"></a>EINVAL</h4> </div> </div> </div> <p> An invalid flag value or parameter was specified. </p> </div> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1651965"></a>Class</h3> </div> </div> </div> <p> <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> </p> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1651554"></a>See Also</h3> </div> </div> </div> <p> <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="dbstat_print.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="db.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="dbtruncate.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">DB->stat_print() </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> DB->truncate()</td> </tr> </table> </div> </body> </html>