| 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>Access method FAQ</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_misc.html" title="Chapter 4. Access Method Wrapup" /> |
| 11 | <link rel="prev" href="am_misc_tune.html" title="Access method tuning" /> |
| 12 | <link rel="next" href="java.html" title="Chapter 5. Java API" /> |
| 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">Access method FAQ</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="am_misc_tune.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 4. |
| 26 | Access Method Wrapup |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="java.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_misc_faq"></a>Access method FAQ</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <div class="orderedlist"> |
| 42 | <ol type="1"> |
| 43 | <li> |
| 44 | <span class="bold"> |
| 45 | <strong>Is a Berkeley DB database the same as a "table"?</strong> |
| 46 | </span> |
| 47 | <p>Yes; "tables" are databases, "rows" are key/data pairs, and "columns" |
| 48 | are application-encapsulated fields within a data item (to which Berkeley DB |
| 49 | does not directly provide access).</p> |
| 50 | </li> |
| 51 | <li> |
| 52 | <span class="bold"> |
| 53 | <strong>I'm getting an error return in my application, but I can't |
| 54 | figure out what the library is complaining about.</strong> |
| 55 | </span> |
| 56 | <p>See <a href="../api_reference/C/envset_errcall.html" class="olink">DB_ENV->set_errcall()</a>, <a href="../api_reference/C/envset_errfile.html" class="olink">DB_ENV->set_errfile()</a> and |
| 57 | <a href="../api_reference/C/dbset_errfile.html" class="olink">DB->set_errfile()</a> for ways to get additional information about |
| 58 | error returns from Berkeley DB.</p> |
| 59 | </li> |
| 60 | <li> |
| 61 | <span class="bold"> |
| 62 | <strong>Are Berkeley DB databases portable between architectures with |
| 63 | different integer sizes and different byte orders ?</strong> |
| 64 | </span> |
| 65 | <p>Yes. Specifically, databases can be moved between 32- and 64-bit |
| 66 | machines, as well as between little- and big-endian machines. See |
| 67 | <a class="xref" href="general_am_conf.html#am_conf_byteorder" title="Selecting a byte order">Selecting a byte order</a> for |
| 68 | more information.</p> |
| 69 | </li> |
| 70 | <li> |
| 71 | <span class="bold"> |
| 72 | <strong>I'm seeing database corruption when creating multiple databases |
| 73 | in a single physical file.</strong> |
| 74 | </span> |
| 75 | <p>This problem is usually the result of <a href="../api_reference/C/db.html" class="olink">DB</a> handles not sharing an |
| 76 | underlying database environment. See <a class="xref" href="am_opensub.html" title="Opening multiple databases in a single file">Opening multiple databases in a single file</a> for more information.</p> |
| 77 | </li> |
| 78 | <li> |
| 79 | <span class="bold"> |
| 80 | <strong>I'm using integers as keys for a Btree database, and even |
| 81 | though the key/data pairs are entered in sorted order, the page-fill |
| 82 | factor is low.</strong> |
| 83 | </span> |
| 84 | <p>This is usually the result of using integer keys on little-endian |
| 85 | architectures such as the x86. Berkeley DB sorts keys as byte strings, and |
| 86 | little-endian integers don't sort well when viewed as byte strings. |
| 87 | For example, take the numbers 254 through 257. Their byte patterns on |
| 88 | a little-endian system are:</p> |
| 89 | <pre class="programlisting">254 fe 0 0 0 |
| 90 | 255 ff 0 0 0 |
| 91 | 256 0 1 0 0 |
| 92 | 257 1 1 0 0</pre> |
| 93 | <p>If you treat them as strings, then they sort badly:</p> |
| 94 | <pre class="programlisting">256 |
| 95 | 257 |
| 96 | 254 |
| 97 | 255</pre> |
| 98 | <p>On a big-endian system, their byte patterns are:</p> |
| 99 | <pre class="programlisting">254 0 0 0 fe |
| 100 | 255 0 0 0 ff |
| 101 | 256 0 0 1 0 |
| 102 | 257 0 0 1 1</pre> |
| 103 | <p>and so, if you treat them as strings they sort nicely. Which means, if |
| 104 | you use steadily increasing integers as keys on a big-endian system |
| 105 | Berkeley DB behaves well and you get compact trees, but on a little-endian |
| 106 | system Berkeley DB produces much less compact trees. To avoid this problem, |
| 107 | you may want to convert the keys to flat text or big-endian |
| 108 | representations, or provide your own |
| 109 | <a class="xref" href="bt_conf.html#am_conf_bt_compare" title="Btree comparison">Btree comparison</a></p> |
| 110 | </li> |
| 111 | <li> |
| 112 | <span class="bold"> |
| 113 | <strong>Is there any way to avoid double buffering in the Berkeley DB system?</strong> |
| 114 | </span> |
| 115 | <p>While you cannot avoid double buffering entirely, there are a few things |
| 116 | you can do to address this issue:</p> |
| 117 | <p>First, the Berkeley DB cache size can be explicitly set. Rather than allocate |
| 118 | additional space in the Berkeley DB cache to cover unexpectedly heavy load or |
| 119 | large table sizes, double buffering may suggest you size the cache to |
| 120 | function well under normal conditions, and then depend on the file |
| 121 | buffer cache to cover abnormal conditions. Obviously, this is a |
| 122 | trade-off, as Berkeley DB may not then perform as well as usual under abnormal |
| 123 | conditions.</p> |
| 124 | <p>Second, depending on the underlying operating system you're using, you |
| 125 | may be able to alter the amount of physical memory devoted to the |
| 126 | system's file buffer cache. Altering this type of resource |
| 127 | configuration may require appropriate privileges, or even operating |
| 128 | system reboots and/or rebuilds, on some systems.</p> |
| 129 | <p>Third, changing the size of the Berkeley DB environment regions can change |
| 130 | the amount of space the operating system makes available for the file |
| 131 | buffer cache, and it's often worth considering exactly how the operating |
| 132 | system is dividing up its available memory. Further, moving the Berkeley DB |
| 133 | database environment regions from filesystem backed memory into system |
| 134 | memory (or heap memory), can often make additional system memory |
| 135 | available for the file buffer cache, especially on systems without a |
| 136 | unified buffer cache and VM system.</p> |
| 137 | <p>Finally, for operating systems that allow buffering to be turned off, |
| 138 | specifying the <a href="../api_reference/C/envset_flags.html#set_flags_DB_DIRECT_DB" class="olink">DB_DIRECT_DB</a> and <a href="../api_reference/C/envlog_set_config.html#log_set_config_DB_LOG_DIRECT" class="olink">DB_LOG_DIRECT</a> flags |
| 139 | will attempt to do so.</p> |
| 140 | </li> |
| 141 | <li> |
| 142 | <span class="bold"> |
| 143 | <strong>I'm seeing database corruption when I run out of disk space.</strong> |
| 144 | </span> |
| 145 | <p>Berkeley DB can continue to run when when out-of-disk-space errors occur, but |
| 146 | it requires the application to be transaction protected. Applications |
| 147 | which do not enclose update operations in transactions cannot recover |
| 148 | from out-of-disk-space errors, and the result of running out of disk |
| 149 | space may be database corruption.</p> |
| 150 | </li> |
| 151 | <li> |
| 152 | <span class="bold"> |
| 153 | <strong>How can I associate application information with a <a href="../api_reference/C/db.html" class="olink">DB</a> |
| 154 | or <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> handle?</strong> |
| 155 | </span> |
| 156 | <p>In the C API, the <a href="../api_reference/C/db.html" class="olink">DB</a> and <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> structures each contain |
| 157 | an "app_private" field intended to be used to reference |
| 158 | application-specific information. See the <a href="../api_reference/C/dbcreate.html" class="olink">db_create()</a> and |
| 159 | <a href="../api_reference/C/envcreate.html" class="olink">db_env_create()</a> documentation for more information.</p> |
| 160 | <p>In the C++ or Java APIs, the easiest way to associate |
| 161 | application-specific data with a handle is to subclass the <a href="../api_reference/CXX/db.html" class="olink">Db</a> |
| 162 | or <a href="../api_reference/CXX/env.html" class="olink">DbEnv</a>, for example subclassing <a href="../api_reference/CXX/db.html" class="olink">Db</a> to get MyDb. |
| 163 | Objects of type MyDb will still have the Berkeley DB API methods available on |
| 164 | them, and you can put any extra data or methods you want into the MyDb |
| 165 | class. If you are using "callback" APIs that take <a href="../api_reference/CXX/db.html" class="olink">Db</a> or |
| 166 | <a href="../api_reference/CXX/env.html" class="olink">DbEnv</a> arguments (for example, <a href="../api_reference/C/dbset_bt_compare.html" class="olink">DB->set_bt_compare()</a>) |
| 167 | these will always be called with the <a href="../api_reference/CXX/db.html" class="olink">Db</a> or <a href="../api_reference/CXX/env.html" class="olink">DbEnv</a> |
| 168 | objects you create. So if you always use MyDb objects, you will be able |
| 169 | to take the first argument to the callback function and cast it to a |
| 170 | MyDb (in C++, cast it to (MyDb*)). That will allow you to access your |
| 171 | data members or methods.</p> |
| 172 | </li> |
| 173 | </ol> |
| 174 | </div> |
| 175 | </div> |
| 176 | <div class="navfooter"> |
| 177 | <hr /> |
| 178 | <table width="100%" summary="Navigation footer"> |
| 179 | <tr> |
| 180 | <td width="40%" align="left"><a accesskey="p" href="am_misc_tune.html">Prev</a> </td> |
| 181 | <td width="20%" align="center"> |
| 182 | <a accesskey="u" href="am_misc.html">Up</a> |
| 183 | </td> |
| 184 | <td width="40%" align="right"> <a accesskey="n" href="java.html">Next</a></td> |
| 185 | </tr> |
| 186 | <tr> |
| 187 | <td width="40%" align="left" valign="top">Access method tuning </td> |
| 188 | <td width="20%" align="center"> |
| 189 | <a accesskey="h" href="index.html">Home</a> |
| 190 | </td> |
| 191 | <td width="40%" align="right" valign="top"> Chapter 5. |
| 192 | Java API |
| 193 | </td> |
| 194 | </tr> |
| 195 | </table> |
| 196 | </div> |
| 197 | </body> |
| 198 | </html> |