Replicating Berkeley DB SQL Databases

Preparing to use Replication with the Berkeley DB SQL API
Using Replication with the Berkeley DB SQL API

It is possible to replicate a Berkeley DB SQL database using the db_replicate utility. This section outlines the configuration steps required to enable replication, and provides an example of how to use the utility with a Berkeley DB SQL database.

Note

The following section assumes that you are familiar with Berkeley DB replication concepts. If not, you should read the Running Replication using the db_replicate Utility section in the Berkeley DB Programmer's Reference Guide.

Preparing to use Replication with the Berkeley DB SQL API

In order to use replication with a Berkeley DB SQL application, you must do a few things prior to creating a database.

  1. Add the following lines to the DB_CONFIG file:

    set_open_flags db_init_rep
    add_data_dir ../ 
    set_open_flags db_thread
    set_open_flags db_register

    This causes the Berkeley DB SQL engine to create a database that is compatible with replication.

    See The DB_CONFIG File for more information about that file.

  2. Tell Berkeley DB how to startup the local (current) site. Do this by adding a line to the DB_CONFIG file of the form:

    repmgr_set_local_site <address> <port>

    where <address> is the URL for the local machine and <port> is the port used on this machine for replication communications.

    For more information, on configuring the local site, see the DB_ENV->repmgr_set_local_site() method.

  3. Tell Berkeley DB about the other machines that are participating in your replication group. Do this by adding a line to the DB_CONFIG file of the form:

    repmgr_add_remote_site <address> <port>

    for each machine participating in your replication group, other than the local machine. Here, <address> is the URL for the remote machine that you are identifying, and <port> is the port used on that machine for replication communications.

    For more information, see the DB_ENV->repmgr_add_remote_site() method.

Using Replication with the Berkeley DB SQL API

Once you have performed the configuration steps described in the previous section, you can start using (and populating) your Berkeley DB SQL database as normal.

When you are ready to start replicating your Berkeley DB SQL database, do the following:

  1. Each site in the replication group needs to have a starting point. The best way to create that is to use a backup of the database that will be replicated. Install a copy of the backup at each of the sites in the replication group. For detailed instructions on creating a backup, see Backing Up Berkeley DB SQL Databases.

  2. Create or update the DB_CONFIG file at each site in the replication group as discussed in the previous section. Make sure that each site has the correct settings for DB_ENV->repmgr_set_local_site() and DB_ENV->repmgr_add_remote_site().

  3. On the site that you want to start as the master of the replication group, run the db_replicate utility in the following way:

    db_replicate -M -h <journal-path>

    where <journal-path> is the path to the journal directory of the database that you want to replicate.

  4. For each of the other sites in the group, run the db_replicate utility in the following way:

    db_replicate -h <journal-path>

    where <journal-path> is the path to the journal directory of the database that you want to replicate.

  5. Verify that replication has started successfully. You can do this by issuing an update operation on the site you selected as the master, and then running a query on a remote site to verify that the updated contents are visible on the remote site.