Debian Codegraph @

docs/programmer_reference/am_opensub.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Opening multiple databases in a single file</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="am.html" title="Chapter 3.  Access Method Operations" />
11 <link rel="prev" href="am.html" title="Chapter 3.  Access Method Operations" />
12 <link rel="next" href="am_partition.html" title="Partitioning databases" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Opening multiple databases in a single file</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="am.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 3. 
26 Access Method Operations
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="am_partition.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="am_opensub"></a>Opening multiple databases in a single file</h2>
38 </div>
39 </div>
40 </div>
41 <div class="toc">
42 <dl>
43 <dt>
44 <span class="sect2">
45 <a href="am_opensub.html#idp50943544">Configuring databases sharing a file</a>
46 </span>
47 </dt>
48 <dt>
49 <span class="sect2">
50 <a href="am_opensub.html#idp50944288">Caching databases sharing a file</a>
51 </span>
52 </dt>
53 <dt>
54 <span class="sect2">
55 <a href="am_opensub.html#idp50944984">Locking in databases based on sharing a file</a>
56 </span>
57 </dt>
58 </dl>
59 </div>
60 <p>Applications may create multiple databases within a single physical
61 file. This is useful when the databases are both numerous and
62 reasonably small, in order to avoid creating a large number of
63 underlying files, or when it is desirable to include secondary index
64 databases in the same file as the primary index database. Putting
65 multiple databases in a single physical file is an administrative
66 convenience and unlikely to affect database performance.</p>
67 <p>To open or create a file that will include more than a single database,
68 specify a database name when calling the <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a> method.</p>
69 <p>Physical files do not need to be comprised of a single type of database,
70 and databases in a file may be of any mixture of types, except for Queue and Heap
71 databases. Queue and Heap databases must be created one per file and cannot
72 share a file with any other database type. There is no limit on the
73 number of databases that may be created in a single file other than the
74 standard Berkeley DB file size and disk space limitations.</p>
75 <p>It is an error to attempt to open a second database in a file that was
76 not initially created using a database name, that is, the file must
77 initially be specified as capable of containing multiple databases for a
78 second database to be created in it.</p>
79 <p>It is not an error to open a file that contains multiple databases
80 without specifying a database name, however the database type should be
81 specified as DB_UNKNOWN and the database must be opened read-only. The
82 handle that is returned from such a call is a handle on a database whose
83 key values are the names of the databases stored in the database file
84 and whose data values are opaque objects. No keys or data values may be
85 modified or stored using this database handle.</p>
86 <div class="sect2" lang="en" xml:lang="en">
87 <div class="titlepage">
88 <div>
89 <div>
90 <h3 class="title"><a id="idp50943544"></a>Configuring databases sharing a file</h3>
91 </div>
92 </div>
93 </div>
94 <p>There are four pieces of configuration information which must be
95 specified consistently for all databases in a file, rather than
96 differing on a per-database basis. They are: byte order, checksum and
97 encryption behavior, and page size. When creating additional databases
98 in a file, any of these configuration values specified must be
99 consistent with the existing databases in the file or an error will be
100 returned.</p>
101 </div>
102 <div class="sect2" lang="en" xml:lang="en">
103 <div class="titlepage">
104 <div>
105 <div>
106 <h3 class="title"><a id="idp50944288"></a>Caching databases sharing a file</h3>
107 </div>
108 </div>
109 </div>
110 <p>When storing multiple databases in a single physical file rather than
111 in separate files, if any of the databases in a file is opened for
112 update, all of the databases in the file must share a memory pool. In
113 other words, they must be opened in the same database environment. This
114 is so per-physical-file information common between the two databases is
115 updated correctly.</p>
116 </div>
117 <div class="sect2" lang="en" xml:lang="en">
118 <div class="titlepage">
119 <div>
120 <div>
121 <h3 class="title"><a id="idp50944984"></a>Locking in databases based on sharing a file</h3>
122 </div>
123 </div>
124 </div>
125 <p>If databases are in separate files (and access to each separate database
126 is single-threaded), there is no reason to perform any locking of any
127 kind, and the two databases may be read and written simultaneously.
128 Further, there would be no requirement to create a shared database
129 environment in which to open those two databases.</p>
130 <p>However, since multiple databases in a file exist in a single physical
131 file, opening two databases in the same file simultaneously requires
132 locking be enabled, unless all of the databases are read-only. As the
133 locks for the two databases can only conflict during page allocation,
134 this additional locking is unlikely to affect performance. The
135 exception is when Berkeley DB Concurrent Data Store is configured; a single lock is used for all
136 databases in the file when Berkeley DB Concurrent Data Store is configured, and a write to one
137 database will block all accesses to all databases.</p>
138 <p>In summary, programmers writing applications that open multiple
139 databases in a single file will almost certainly need to create a shared
140 database environment in the application as well. For more information
141 on database environments, see <a class="xref" href="env.html#env_intro" title="Database environment introduction">Database environment introduction</a></p>
142 </div>
143 </div>
144 <div class="navfooter">
145 <hr />
146 <table width="100%" summary="Navigation footer">
147 <tr>
148 <td width="40%" align="left"><a accesskey="p" href="am.html">Prev</a> </td>
149 <td width="20%" align="center">
150 <a accesskey="u" href="am.html">Up</a>
151 </td>
152 <td width="40%" align="right"> <a accesskey="n" href="am_partition.html">Next</a></td>
153 </tr>
154 <tr>
155 <td width="40%" align="left" valign="top">Chapter 3. 
156 Access Method Operations
157  </td>
158 <td width="20%" align="center">
159 <a accesskey="h" href="index.html">Home</a>
160 </td>
161 <td width="40%" align="right" valign="top"> Partitioning databases</td>
162 </tr>
163 </table>
164 </div>
165 </body>
166 </html>