Bucardo: the replication system for PostgreSQL

- Andrés Cruz

En español
Bucardo: the replication system for PostgreSQL

As the title for this post specifies, Bucardo is a replication system that in other words allows "cloning" or "duplicating" records between Databases (sources-targets), also has support for managing multiple Databases with master relationships -slaves.

Although the source must be a PostgreSQL Database, the target can be PostgreSQL, MySQL, Redis, Oracle, MariaDB, SQLite, or MongoDB.

The steps to install Bucardo on Linux are very simple (as we will see in the next section) although Bucardo can be a bit difficult to install due to various configurations and dependencies required at the Operating System level, but in this post you will find a section where we talk about Errors that occurred to me while installing Bucardo.

This entry offers a quick but complete overview of Bucardo, beginning with its installation in a Linux environment, its configuration, some errors that may appear in the installation process, and the entry culminating with a small experiment with a simple Master-Master relationship with PostgreSQL Database.

Installing Bucardo in Ubuntu -part 1-

In this section we will give some tips on how to install Bucardo in its version 5.3.1 in Ubuntu, although the procedure is the same for other Linux distributions; First we download Bucardo.tar.gz from the download section.

We unpack the package and locate ourselves from the terminal in the folder; At the time this entry was written, the version is 5.3.1:

cd Bucardo-5.3.1/

We generate the Makefile:

perl Makefile.PL Generating a Unix-style Makefile Writing Makefile for Bucardo Writing MYMETA.yml and MYMETA.json

It is best to get your copy of bucardo from its GitHub repository at: git clone git://bucardo.org/bucardo.git

Finally we install Bucardo:

make make install

In Fedora there is another method to get a copy of Bucardo, and it consists of installing it through the repositories:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm yum -y install bucardo

Setting up the PostgreSQL environment for Bucardo

Once we install the first phase of Bucardo through the Makefiles, we go to PGAdmin or any other Administrator and create a Database and Role (with SuperUser) called "bucardo":

Esquema de Bucardo en PostgreSQL

Configuring Bucardo -part 2-

Now we will continue with the installation of Bucardo according to the configurations made in PostgreSQL; for this we must execute in a terminal:

bucardo install

or -depending on the installation source.-

bucardo_ctl install

We will see the following information:

Current connection settings: 1. Host:           <none> 2. Port:           5432 3. User:           postgres 4. Database:       bucardo 5. PID directory:  /var/run/bucardo

If the /var/run/bucardo directory does not exist, create it via: mkdir /var/run/bucardo

The Host, user and database created previously are specified:

Current connection settings: 1. Host:           localhost 2. Port:           5432 3. User:           bucardo 4. Database:       bucardo 5. PID directory:  /var/run/bucardo

Errors that occurred to me while installing Bucardo:

  • ERROR: language "plperlu" does not exist: We install the package with We install the package with sudo yum install postgresql-plperl, after the installation in the Bucardo Database we run: CREATE
  • EXTENSION plperl; CREATE LANGUAGE plperlu;
  • ERROR: permission denied for language plperlu Set user as SuperUser from pgAdmin interface
  • For any error concerning authentication; remember to put in the pg_hba.conf located in /etc/postgresql/X.X/main/p:
  • local bucardo bucardo md5
  • If when executing a Bucardo command the following error appears: DBI connect('dbname=bucardo','bucardo',...) failed: fe_sendauth: no password supplied at /usr/local/bin/bucardo line 308. You can solve
  • the error by modifying the file indicated in the error (/usr/local/bin/bucardo), look for the indicated line of code:
Archivo error, contraseña no especificada
  • And add the Bucardo password:
Archivo error, contraseña especificada

If everything goes well and no other error occurred, CONGRATULATIONS, you have just completed the Bucardo installation and now you can create all the relationships between Databases that you want.

Creating a Master-Master relationship with Bucardo

In this last section we will see how to create a simple master slave relationship with the Bucardo commands which I will briefly explain below:

  • First we create the Databases; if they are local, it is not necessary to specify the host: bucardo add database <name> dbname=<dbname> user=<dbuser> pass=<dbpassword>
    to add the tables and sequences to be synchronized: bucardo add table <table1> <table2> … relgroup=<relgroupname>
  • We create a database group to be able to easily synchronize them later: bucardo add dbgroup <dbgroupname> <dbname>:source <dbname>:source
  • Now we create the synchronization with: bucardo add <syncname> mysync relgroup=<relgroupname> dbs=<dbgroupname> autokick=0
  • And we activate the synchronization: bucardo update sync <sync name> autokick=1

You can find the official and complete documentation in the links at the end of this post.

Once the basic commands to create a replication system are understood, now we are going to create a Master-Master relationship where one of the Databases is local and the other is remote; to do this we use the following commands:

bucardo add database midblocal dbname=oo user=bucardo pass=bucardo bucardo add database midbremoto dbname=oo user=postgres pass=postgres host=<IPRemota> bucardo add table public.status db=midblocal relgroup=myrels bucardo add dbgroup mydbgroup midblocal:source midbremoto:source bucardo add sync mysync relgroup=myrels dbs=mydbgroup autokick=0 bucardo update sync mysync autokick=1 bucardo reload config

Finally we start Bucardo with:

bucardo start

And we verify its status with:

bucardo status

Now try inserting records into any of the Database tables that are in sync and should be replicated to stay in sync.

Some interesting links:

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.