2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB Reference Guide: Flat-text backing files</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<a name="2"><!--meow--></a>
13
<table width="100%"><tr valign=top>
14
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Access Methods</dl></h3></td>
15
<td align=right><a href="../../ref/am_conf/extentsize.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/am_conf/renumber.html"><img src="../../images/next.gif" alt="Next"></a>
18
<h1 align=center>Flat-text backing files</h1>
19
<p>It is possible to back any Recno database (either fixed or variable
20
length) with a flat-text source file. This provides fast read (and
21
potentially write) access to databases that are normally created and
22
stored as flat-text files. The backing source file may be specified by
23
calling the <a href="../../api_c/db_set_re_source.html">DB->set_re_source</a> method.
24
<p>The backing source file will be read to initialize the database. In the
25
case of variable length records, the records are assumed to be separated
26
as described for the <a href="../../api_c/db_set_re_delim.html">DB->set_re_delim</a> method interface. For example,
27
standard UNIX byte stream files can be interpreted as a sequence of
28
variable length records separated by ASCII newline characters. This is
30
<p>When cached data would normally be written back to the underlying
31
database file (for example, when the <a href="../../api_c/db_close.html">DB->close</a> or
32
<a href="../../api_c/db_sync.html">DB->sync</a> methods are called), the in-memory copy of the database will
33
be written back to the backing source file.
34
<p>The backing source file must already exist (but may be zero-length) when
35
<a href="../../api_c/db_open.html">DB->open</a> is called. By default, the backing source file is read
36
lazily, that is, records are not read from the backing source file until
37
they are requested by the application. If multiple processes (not
38
threads) are accessing a Recno database concurrently and either
39
inserting or deleting records, the backing source file must be read in
40
its entirety before more than a single process accesses the database,
41
and only that process should specify the backing source file as part of
42
the <a href="../../api_c/db_open.html">DB->open</a> call. This can be accomplished by calling the
43
<a href="../../api_c/db_set_flags.html">DB->set_flags</a> method with the <a href="../../api_c/db_set_flags.html#DB_SNAPSHOT">DB_SNAPSHOT</a> flag.
44
<p>Reading and writing the backing source file cannot be transactionally
45
protected because it involves filesystem operations that are not part of
46
the Berkeley DB transaction methodology. For this reason, if a temporary
47
database is used to hold the records (a NULL was specified as the file
48
argument to <a href="../../api_c/db_open.html">DB->open</a>), <b>it is possible to lose the
49
contents of the backing source file if the system crashes at the right
50
instant</b>. If a permanent file is used to hold the database (a filename
51
was specified as the file argument to <a href="../../api_c/db_open.html">DB->open</a>), normal database
52
recovery on that file can be used to prevent information loss. It is
53
still possible that the contents of the backing source file itself will
54
be corrupted or lost if the system crashes.
55
<p>For all of the above reasons, the backing source file is generally used
56
to specify databases that are read-only for Berkeley DB applications, and that
57
are either generated on the fly by software tools, or modified using a
58
different mechanism such as a text editor.
59
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/am_conf/extentsize.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/am_conf/renumber.html"><img src="../../images/next.gif" alt="Next"></a>
61
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>