1.1. Installing and Configuring PostgreSQL for BDR

To try out BDR you'll need to install the BDR extension and the modified PostgreSQL release that it requires to run. Then it's necessary to initdb new database install(s), edit their configuration files to load BDR, and start them up.

1.1.1. Installing the patched PostgreSQL binaries

Information about installing BDR from packages can be found in Installing from packages or installing from source can be found in Installing from source code.

If you just want to try BDR out quickly and you're on a Linux system (or have a Linux VM to play with), you can run a script that'll set up a temporary BDR install in your home directory. this installation method is only suitable for trying out BDR, not for production or for use on a system with valuable data on it. To install the latest stable release, run:

    $ curl -s "http://git.postgresql.org/gitweb/?p=2ndquadrant_bdr.git;a=blob_plain;f=scripts/bdr_quickstart.sh;hb=bdr-plugin/next" | bash
    

For the latest development version, instead try

    $ curl -s "http://git.postgresql.org/gitweb/?p=2ndquadrant_bdr.git;a=blob_plain;f=scripts/bdr_quickstart.sh;hb=bdr-plugin/next" | bash
    

In either case, when the install finishes, the script prints:

    ---------------------------
    BDR compiled and installed.

    Sources at /home/myuser/2ndquadrant_bdr/bdr-src
    Installed to /home/myuser/2ndquadrant_bdr/bdr

    Now add it to your PATH:
      export PATH=/home/myuser/2ndquadrant_bdr/bdr/bin:$PATH
    and carry on with the quickstart at https://wiki.postgresql.org/wiki/BDR_Quick_Start
     ---------------------------
    

To use these new binaries, set your path to point to them. If you used the quickstart script, it told you the command to use. If you installed from source, add the bin directory of your BDR install, e.g.:

    export PATH=$HOME/2ndquadrant_bdr/bdr/bin:$PATH
    

or, if you installed from RPMs, run:

    export PATH=/usr/pgsql-9.4/bin:$PATH
    

Note that this only affects the terminal you ran the install from and makes no permanent changes. If you wish you can change your path in your .bash_profile, or just run the export command in each terminal you open.

1.1.2. Creating BDR-enabled PostgreSQL nodes/instances

Since we're creating two new PostgreSQL node/instances for this example, run:

     mkdir -p $HOME/2ndquadrant_bdr
     initdb -D $HOME/2ndquadrant_bdr/bdr5598 -A trust -U postgres
     initdb -D $HOME/2ndquadrant_bdr/bdr5599 -A trust -U postgres
     

Adjust the data directory path (the path after -D) if you want to use a different location. The rest of these instructions will assume you ran exactly the commands given above.

These commands do not start BDR, or connect the two instances. They just create two independent PostgreSQL instances, ready to be configured and started.

1.1.3. Editing the configuration files to enable BDR

Edit the postgresql.conf file for both nodes/instances:

    shared_preload_libraries = 'bdr'
    wal_level = 'logical'
    track_commit_timestamp = on
    max_connections = 100
    max_wal_senders = 10
    max_replication_slots = 10
    # Make sure there are enough background worker slots for BDR to run
    max_worker_processes = 10

    # These aren't required, but are useful for diagnosing problems
    #log_error_verbosity = verbose
    #log_min_messages = debug1
    #log_line_prefix = 'd=%d p=%p a=%a%q '

    # Useful options for playing with conflicts
    #bdr.default_apply_delay=2000   # milliseconds
    #bdr.log_conflicts_to_table=on
    

Edit or uncomment authentication parameters to allow replication in the pg_hba.conf file for both nodes/instances:

    local   replication   postgres                  trust
    host    replication   postgres     127.0.0.1/32 trust
    host    replication   postgres     ::1/128      trust
    

1.1.4. Starting the BDR-enabled PostgreSQL nodes/instances

Start your nodes/instances from the command line of your operating system:

    pg_ctl -l $HOME/2ndquadrant_bdr/bdr5598.log -D $HOME/2ndquadrant_bdr/bdr5598 -o "-p 5598" -w start
    pg_ctl -l $HOME/2ndquadrant_bdr/bdr5599.log -D $HOME/2ndquadrant_bdr/bdr5599 -o "-p 5599" -w start
    

Each node/instance will start up and then will run in the background. You'll see the following:

     waiting for server to start.... done
     server started
     

If you see an issue with starting your nodes/instances:

     waiting for server to start........ stopped waiting
     pg_ctl: could not start server
     

... then take a look at the log files (bdr5598.log or bdr5599.log depending on which one failed to start.) Most likely you already have a PostgreSQL instance running on the target port. It is also possible that your $PATH is not set to point to BDR, so you're trying to use binaries from a different PostgreSQL release that won't have the bdr extension or understand some of the configuration parameters.

Note: Because they were started manually and don't have an init script, these nodes/instances won't start automatically on re-boot.