<!--$Id: copy.so,v 10.17 2005/06/16 17:07:07 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle. All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Copying or moving databases</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Programmer Notes</dl></b></td>
<td align=right><a href="../program/cache.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../program/compatible.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Copying or moving databases</b></p>
<a name="2"><!--meow--></a>
<a name="3"><!--meow--></a>
<p>There are two issues with copying or moving databases: database page log
sequence numbers (LSNs), and database file identification strings.</p>
<p>Because database pages contain references to the database environment
log records (LSNs), databases cannot be copied or moved from one
transactional database environment to another without first clearing the
LSNs. Note that this is not a concern for non-transactional database
environments and applications, and can be ignored if the database is not
being used transactionally. Specifically, databases created and written
non-transactionally (for example, as part of a bulk load procedure), can
be copied or moved into a transactional database environment without
resetting the LSNs. The database's LSNs may be reset in one of three
ways: the application can call the <a href="../../api_c/env_lsn_reset.html">DB_ENV->lsn_reset</a> method to reset the
LSNs in place, or a system administrator can reset the LSNs in place
using the <b>-r</b> option to the <a href="../../utility/db_load.html">db_load</a> utility, or by
dumping and reloading the database (using the <a href="../../utility/db_dump.html">db_dump</a> and
<a href="../../utility/db_load.html">db_load</a> utilities).</p>
<p>Because system file identification information (for example, filenames,
device and inode numbers, volume and file IDs, and so on) are not
necessarily unique or maintained across system reboots, each Berkeley DB
database file contains a unique 20-byte file identification bytestring.
When multiple processes or threads open the same database file in Berkeley DB,
it is this bytestring that is used to ensure the same underlying pages
are updated in the database environment cache, no matter which Berkeley DB
handle is used for the operation.</p>
<p>The database file identification string is not a concern when moving
databases, and databases may be moved or renamed without resetting the
identification string. However, when copying a database, you must
ensure there are never two databases with the same file identification
bytestring in the same cache at the same time. Copying databases is
further complicated because Berkeley DB caches do not discard cached database
pages when database handles are closed. Cached pages are only discarded
when the database is removed by calling the <a href="../../api_c/env_remove.html">DB_ENV->remove</a> or
<a href="../../api_c/db_remove.html">DB->remove</a> methods.</p>
<p>Before physically copying a database file, first ensure that all
modified pages have been written from the cache to the backing database
file. This is done using the <a href="../../api_c/db_sync.html">DB->sync</a> or <a href="../../api_c/db_close.html">DB->close</a> methods.</p>
<p>Before using a copy of a database file in a database environment, you
must ensure that all pages from any other database with the same
bytestring have been removed from the memory pool cache. If the
environment in which you will open the copy of the database has pages
from files with identical bytestrings to the copied database, there are
a few possible solutions:</p>
<ol>
<p><li>Remove the environment, either using system utilities or by calling the
<a href="../../api_c/env_remove.html">DB_ENV->remove</a> method. Obviously, this will not allow you to access
both the original database and the copy of the database at the same
time.
<p><li>Create a new file that will have a new bytestring. The simplest way to
create a new file that will have a new bytestring is to call the
<a href="../../utility/db_dump.html">db_dump</a> utility to dump out the contents of the database and
then use the <a href="../../utility/db_load.html">db_load</a> utility to load the dumped output into a
new file. This allows you to access both the original and copy of the
database at the same time.
<p><li>If your database is too large to be dumped and reloaded, you can copy
the database by other means, and then reset the bytestring in the copied
database to a new bytestring. There are two ways to reset the
bytestring in the copy: the application can call the
<a href="../../api_c/env_fileid_reset.html">DB_ENV->fileid_reset</a> method, or a system administrator can use the
<b>-r</b> option to the <a href="../../utility/db_load.html">db_load</a> utility. This allows you to
access both the original and copy of the database at the same time.
</ol>
<table width="100%"><tr><td><br></td><td align=right><a href="../program/cache.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../program/compatible.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font>
</body>
</html>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez