| 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>Chapter 4. Using Replication with the SQL API</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="Getting Started with the Oracle Berkeley DB SQL APIs" /> |
| 10 | <link rel="up" href="index.html" title="Getting Started with the Oracle Berkeley DB SQL APIs" /> |
| 11 | <link rel="prev" href="selectpage_size.html" title="Selecting the Page Size" /> |
| 12 | <link rel="next" href="reppragma.html" title="Replication PRAGMAs" /> |
| 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">Chapter 4. Using Replication with the SQL API</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="selectpage_size.html">Prev</a> </td> |
| 25 | <th width="60%" align="center"> </th> |
| 26 | <td width="20%" align="right"> <a accesskey="n" href="reppragma.html">Next</a></td> |
| 27 | </tr> |
| 28 | </table> |
| 29 | <hr /> |
| 30 | </div> |
| 31 | <div class="chapter" lang="en" xml:lang="en"> |
| 32 | <div class="titlepage"> |
| 33 | <div> |
| 34 | <div> |
| 35 | <h2 class="title"><a id="sqlrep"></a>Chapter 4. Using Replication with the SQL API</h2> |
| 36 | </div> |
| 37 | </div> |
| 38 | </div> |
| 39 | <div class="toc"> |
| 40 | <p> |
| 41 | <b>Table of Contents</b> |
| 42 | </p> |
| 43 | <dl> |
| 44 | <dt> |
| 45 | <span class="sect1"> |
| 46 | <a href="sqlrep.html#repoverview">Replication Overview</a> |
| 47 | </span> |
| 48 | </dt> |
| 49 | <dd> |
| 50 | <dl> |
| 51 | <dt> |
| 52 | <span class="sect2"> |
| 53 | <a href="sqlrep.html#repmasters">Replication Masters</a> |
| 54 | </span> |
| 55 | </dt> |
| 56 | <dt> |
| 57 | <span class="sect2"> |
| 58 | <a href="sqlrep.html#repelect">Elections</a> |
| 59 | </span> |
| 60 | </dt> |
| 61 | <dt> |
| 62 | <span class="sect2"> |
| 63 | <a href="sqlrep.html#repdurability">Durability Guarantees</a> |
| 64 | </span> |
| 65 | </dt> |
| 66 | <dt> |
| 67 | <span class="sect2"> |
| 68 | <a href="sqlrep.html#twositerep">Two-Site Replication Groups</a> |
| 69 | </span> |
| 70 | </dt> |
| 71 | </dl> |
| 72 | </dd> |
| 73 | <dt> |
| 74 | <span class="sect1"> |
| 75 | <a href="reppragma.html">Replication PRAGMAs</a> |
| 76 | </span> |
| 77 | </dt> |
| 78 | <dd> |
| 79 | <dl> |
| 80 | <dt> |
| 81 | <span class="sect2"> |
| 82 | <a href="reppragma.html#pragma_replication">PRAGMA replication</a> |
| 83 | </span> |
| 84 | </dt> |
| 85 | <dt> |
| 86 | <span class="sect2"> |
| 87 | <a href="reppragma.html#pragma_replication_initial_master">PRAGMA replication_initial_master</a> |
| 88 | </span> |
| 89 | </dt> |
| 90 | <dt> |
| 91 | <span class="sect2"> |
| 92 | <a href="reppragma.html#pragma_replication_local_site">PRAGMA replication_local_site</a> |
| 93 | </span> |
| 94 | </dt> |
| 95 | <dt> |
| 96 | <span class="sect2"> |
| 97 | <a href="reppragma.html#pragma_replication_remote_site">PRAGMA replication_remote_site</a> |
| 98 | </span> |
| 99 | </dt> |
| 100 | <dt> |
| 101 | <span class="sect2"> |
| 102 | <a href="reppragma.html#pragma_replication_remove_site">PRAGMA replication_remove_site</a> |
| 103 | </span> |
| 104 | </dt> |
| 105 | <dt> |
| 106 | <span class="sect2"> |
| 107 | <a href="reppragma.html#pragma_replication_verbose_output">PRAGMA replication_verbose_output</a> |
| 108 | </span> |
| 109 | </dt> |
| 110 | <dt> |
| 111 | <span class="sect2"> |
| 112 | <a href="reppragma.html#pragma_replication_verbose_file">PRAGMA replication_verbose_file</a> |
| 113 | </span> |
| 114 | </dt> |
| 115 | </dl> |
| 116 | </dd> |
| 117 | <dt> |
| 118 | <span class="sect1"> |
| 119 | <a href="repstatistics.html">Displaying Replication Statistics</a> |
| 120 | </span> |
| 121 | </dt> |
| 122 | <dt> |
| 123 | <span class="sect1"> |
| 124 | <a href="rep_usageexamples.html">Replication Usage Examples</a> |
| 125 | </span> |
| 126 | </dt> |
| 127 | <dd> |
| 128 | <dl> |
| 129 | <dt> |
| 130 | <span class="sect2"> |
| 131 | <a href="rep_usageexamples.html#rep_ex1">Example 1: Distributed Read at 3 Sites</a> |
| 132 | </span> |
| 133 | </dt> |
| 134 | <dt> |
| 135 | <span class="sect2"> |
| 136 | <a href="rep_usageexamples.html#rep_ex2">Example 2: 2-Site Failover</a> |
| 137 | </span> |
| 138 | </dt> |
| 139 | </dl> |
| 140 | </dd> |
| 141 | </dl> |
| 142 | </div> |
| 143 | <p> |
| 144 | The Berkeley DB SQL interface allows you to use Berkeley DB's |
| 145 | replication feature. You configure and start replication using |
| 146 | PRAGMAs that are specific to the task. |
| 147 | </p> |
| 148 | <p> |
| 149 | This chapter provides a high-level introduction of |
| 150 | Berkeley DB replication. It then shows how to configure and use |
| 151 | replication with the SQL API. |
| 152 | </p> |
| 153 | <p> |
| 154 | For a more detailed description of Berkeley DB replication, |
| 155 | see: |
| 156 | </p> |
| 157 | <div class="itemizedlist"> |
| 158 | <ul type="disc"> |
| 159 | <li> |
| 160 | <p> |
| 161 | <em class="citetitle">Berkeley DB Getting Started with Replicated Applications</em> |
| 162 | </p> |
| 163 | </li> |
| 164 | <li> |
| 165 | <p> |
| 166 | <em class="citetitle">Berkeley DB Programmer's Reference Guide</em> |
| 167 | </p> |
| 168 | </li> |
| 169 | </ul> |
| 170 | </div> |
| 171 | <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> |
| 172 | <h3 class="title">Note</h3> |
| 173 | <p> |
| 174 | You cannot access a BDB SQL database using multiple |
| 175 | processes if you enable replication for that database. |
| 176 | </p> |
| 177 | </div> |
| 178 | <div class="sect1" lang="en" xml:lang="en"> |
| 179 | <div class="titlepage"> |
| 180 | <div> |
| 181 | <div> |
| 182 | <h2 class="title" style="clear: both"><a id="repoverview"></a>Replication Overview</h2> |
| 183 | </div> |
| 184 | </div> |
| 185 | </div> |
| 186 | <div class="toc"> |
| 187 | <dl> |
| 188 | <dt> |
| 189 | <span class="sect2"> |
| 190 | <a href="sqlrep.html#repmasters">Replication Masters</a> |
| 191 | </span> |
| 192 | </dt> |
| 193 | <dt> |
| 194 | <span class="sect2"> |
| 195 | <a href="sqlrep.html#repelect">Elections</a> |
| 196 | </span> |
| 197 | </dt> |
| 198 | <dt> |
| 199 | <span class="sect2"> |
| 200 | <a href="sqlrep.html#repdurability">Durability Guarantees</a> |
| 201 | </span> |
| 202 | </dt> |
| 203 | <dt> |
| 204 | <span class="sect2"> |
| 205 | <a href="sqlrep.html#twositerep">Two-Site Replication Groups</a> |
| 206 | </span> |
| 207 | </dt> |
| 208 | </dl> |
| 209 | </div> |
| 210 | <p> |
| 211 | Berkeley DB's replication feature allows you to automatically |
| 212 | distribute your database write operations to one or more |
| 213 | read-only <span class="emphasis"><em>replicas</em></span>. For this reason, BDB's |
| 214 | replication implementation is said to be a <span class="emphasis"><em>single |
| 215 | master, multiple replica</em></span> replication strategy. |
| 216 | </p> |
| 217 | <p> |
| 218 | A single replication master and all of its replicas are |
| 219 | referred to as a <span class="emphasis"><em>replication group</em></span>. |
| 220 | Each replication group can have one and only one master |
| 221 | site. |
| 222 | </p> |
| 223 | <p> |
| 224 | When discussing Berkeley DB replication, we sometimes refer |
| 225 | to <span class="emphasis"><em>replication sites</em></span>. This is because |
| 226 | most production applications place each of their replication |
| 227 | participants on separate physical machines. In fact, each |
| 228 | replication participant must be assigned a hostname/port |
| 229 | pair that is unique within the replication group. |
| 230 | </p> |
| 231 | <p> |
| 232 | Note that under the hood, the unit of replication is the |
| 233 | environment. That is, data is replicated from one Berkeley |
| 234 | DB environment to one or more other Berkeley DB |
| 235 | environments. However, when used with the BDB SQL interface, |
| 236 | you can think of this as replicating between Berkeley DB |
| 237 | databases, because the BDB SQL interface results in a single |
| 238 | database file for each environment. |
| 239 | </p> |
| 240 | <div class="sect2" lang="en" xml:lang="en"> |
| 241 | <div class="titlepage"> |
| 242 | <div> |
| 243 | <div> |
| 244 | <h3 class="title"><a id="repmasters"></a>Replication Masters</h3> |
| 245 | </div> |
| 246 | </div> |
| 247 | </div> |
| 248 | <p> |
| 249 | Every replication group has one and only one master. |
| 250 | The master site is where you perform write operations. |
| 251 | These operations are then automatically replicated to |
| 252 | the other sites in the replication group. Because |
| 253 | the other replica sites in the replication group are |
| 254 | read-only, it is an error for you to attempt to perform |
| 255 | write operatons on them. |
| 256 | </p> |
| 257 | <p> |
| 258 | The replication master is usually automatically |
| 259 | selected by the replication group using elections. |
| 260 | Replication elections simply determine which |
| 261 | replication site has the most up-to-date copy of the |
| 262 | data, and so is in the best position to serve as the |
| 263 | master site. |
| 264 | </p> |
| 265 | <p> |
| 266 | Note that when you initially start up your BDB SQL |
| 267 | replicated application, you must explicitly designate a |
| 268 | specific site as the master. Over time, the master site |
| 269 | can move from one environment to the next. For example, |
| 270 | if the master site is shut down, becomes unavailable, |
| 271 | or a network partition causes it to lose contact with |
| 272 | the rest of the replication group, then the replication |
| 273 | group will elect a new master if it can successfully |
| 274 | hold an election. When the old master comes back |
| 275 | online, it rejoins the replication group as a read-only |
| 276 | replica site. |
| 277 | </p> |
| 278 | <p> |
| 279 | Also, if you are enabling replication for an existing |
| 280 | database, then that database must be designated as the |
| 281 | master. Doing this is required; otherwise the entire |
| 282 | contents of the existing database might be deleted |
| 283 | during the replication startup process. |
| 284 | </p> |
| 285 | </div> |
| 286 | <div class="sect2" lang="en" xml:lang="en"> |
| 287 | <div class="titlepage"> |
| 288 | <div> |
| 289 | <div> |
| 290 | <h3 class="title"><a id="repelect"></a>Elections</h3> |
| 291 | </div> |
| 292 | </div> |
| 293 | </div> |
| 294 | <p> |
| 295 | A replication group selects the master site by holding |
| 296 | an election. In simplistic terms, each participant in |
| 297 | the replication group votes on who it believes has the |
| 298 | most up-to-date version of the data that the |
| 299 | replication group is managing. The site that receives |
| 300 | the most number of votes becomes the master site, and |
| 301 | all data write activity must occur there. |
| 302 | </p> |
| 303 | <p> |
| 304 | In order to hold an election, the replication group |
| 305 | must have a quorum. In order to achieve a quorum, a |
| 306 | simple majority of the sites must be available to |
| 307 | select the master. That is, |
| 308 | <span class="emphasis"><em>n/2 + 1</em></span> sites must be available, where |
| 309 | <span class="emphasis"><em>n</em></span> is the total number of replication |
| 310 | group participants. By requiring a simple majority, the |
| 311 | replication group avoids the possibility of |
| 312 | simultaneously running with two master sites due to a |
| 313 | network partition. |
| 314 | </p> |
| 315 | <p> |
| 316 | If a replication group cannot select a master, then it |
| 317 | can only be used in read-only mode. |
| 318 | </p> |
| 319 | </div> |
| 320 | <div class="sect2" lang="en" xml:lang="en"> |
| 321 | <div class="titlepage"> |
| 322 | <div> |
| 323 | <div> |
| 324 | <h3 class="title"><a id="repdurability"></a>Durability Guarantees</h3> |
| 325 | </div> |
| 326 | </div> |
| 327 | </div> |
| 328 | <p> |
| 329 | Durability is a term that means data modifications have |
| 330 | met some pre-defined set of guarantees that the |
| 331 | modifications will remain persistent across application |
| 332 | run times. Usually, this means that there is some |
| 333 | assurance that the data modification has been written |
| 334 | to stable storage (that is, written to a hard drive). |
| 335 | </p> |
| 336 | <p> |
| 337 | For replicated BDB SQL applications, the durability |
| 338 | guarantee is extended because data modifications are |
| 339 | also replicated to those environments that are |
| 340 | participating in the replication group. This ensures |
| 341 | higher data durability than non-replicated applications |
| 342 | by placing data in multiple environments that usually |
| 343 | reside on separate physical machines. |
| 344 | </p> |
| 345 | </div> |
| 346 | <div class="sect2" lang="en" xml:lang="en"> |
| 347 | <div class="titlepage"> |
| 348 | <div> |
| 349 | <div> |
| 350 | <h3 class="title"><a id="twositerep"></a>Two-Site Replication Groups</h3> |
| 351 | </div> |
| 352 | </div> |
| 353 | </div> |
| 354 | <p> |
| 355 | In a replication group that consists of exactly two |
| 356 | sites, both sites must be available in order to achieve |
| 357 | a quorum. Without a quorum, a new master site cannot |
| 358 | be elected. This means that if the master site is |
| 359 | unable to participate in the replication group, then |
| 360 | the remaining read-only replica cannot become the |
| 361 | master site. |
| 362 | </p> |
| 363 | <p> |
| 364 | In other words, if you have a group that consists of |
| 365 | exactly two sites, if you lose your master site then |
| 366 | the replication group must exist in read-only mode until |
| 367 | the master site becomes available again. |
| 368 | </p> |
| 369 | </div> |
| 370 | </div> |
| 371 | </div> |
| 372 | <div class="navfooter"> |
| 373 | <hr /> |
| 374 | <table width="100%" summary="Navigation footer"> |
| 375 | <tr> |
| 376 | <td width="40%" align="left"><a accesskey="p" href="selectpage_size.html">Prev</a> </td> |
| 377 | <td width="20%" align="center"> </td> |
| 378 | <td width="40%" align="right"> <a accesskey="n" href="reppragma.html">Next</a></td> |
| 379 | </tr> |
| 380 | <tr> |
| 381 | <td width="40%" align="left" valign="top">Selecting the Page Size </td> |
| 382 | <td width="20%" align="center"> |
| 383 | <a accesskey="h" href="index.html">Home</a> |
| 384 | </td> |
| 385 | <td width="40%" align="right" valign="top"> Replication PRAGMAs</td> |
| 386 | </tr> |
| 387 | </table> |
| 388 | </div> |
| 389 | </body> |
| 390 | </html> |