In this tutorial i will show you how to install bucardo for postgres replication. You can use bucardo for postgres replication on RDS instances. Let’s see what is bucardo and how we can we install it.
Bucardo is an asynchronous PostgreSQL replication system, allowing for both multi-master and multi-slave operations. It was developed at Backcountry.com by Jon Jensen and Greg Sabino Mullane of End Point Corporation and is now in use at many other organizations. Bucardo is free and open source software released under the BSD license.
1. There are some packages that we need to install before installing bucardoso lets get started.
apt-get install libdbi-perl libdbd-pg-perl libboolean-perl build-essential libreadline-dev zlib1g-dev autoconf bison libtool libgeos-c1v5 libproj-dev libgdal-dev libxml2-dev libxml2-utils libjson0-dev xsltproc docbook-xsl docbook-mathml libossp-uuid-dev libperl-dev libdbix-safe-perl postgresql-plperl-9.4
2. Postgres Server must be installed before on both servers starting replication.
3. All the replication database should have primary key otherwise it will not work.
You can install bucardo any source DB or destination DB or you can install it on separate management server also. So, i am installing bucardo on source database so let’s get started.
After downloading the bucardo extract the tarball.
tar -xvf Bucardo-5.4.1.tar.gz cd Bucardo-5.4.1 perl Makefile.PL make make test sudo make install
Create directories for bucardo
We need to create 2 directories for PID and logs:
mkdir -p /var/run/bucardo
mkdir -p /var/log/bucardo
Read Also: 10-mac-keyboard-shortcuts
Now we will install bucardo, installation include creation of bucardo user and database. The script will automatically create bucardo superuser and database:
root@40b2fd284111:~# bucardo install This will install the bucardo database into an existing Postgres cluster. Postgres must have been compiled with Perl support, and you must connect as a superuser Current connection settings: 1. Host: <none> 2. Port: 5432 3. User: postgres 4. Database: bucardo 5. PID directory: /var/run/bucardo Enter a number to change it, P to proceed, or Q to quit: 1 Change the host to: localhost Changed host to: localhost Current connection settings: 1. Host: localhost 2. Port: 5432 3. User: postgres 4. Database: bucardo 5. PID directory: /var/run/bucardo Enter a number to change it, P to proceed, or Q to quit: P Password for user postgres: Failed to connect to database 'bucardo', will try 'postgres' Current connection settings: 1. Host: localhost 2. Port: 5432 3. User: postgres 4. Database: postgres 5. PID directory: /var/run/bucardo Enter a number to change it, P to proceed, or Q to quit: P Password for user postgres: Postgres version is: 9.5 Password for user postgres: Creating superuser 'bucardo' Password for user postgres: Attempting to create and populate the bucardo database and schema Password for user postgres: Database creation is complete Updated configuration setting "piddir" Installation is now complete. If you see errors or need help, please email [email protected] You may want to check over the configuration variables next, by running: bucardo show all Change any setting by using: bucardo set foo=bar
Copy the dump to the destination database
pg_dump -C -h remotehost -U remoteuser dbname | psql -h localhost -U localuser dbname
Setting up bucardo
Now our databases are ready we can set up bucardo. We will add source_db ad dest_db in the following command:
bucardo add db source_db dbhost=<--Source-DB--> dbport=5432 dbname=<--your-db-name--> dbuser=<--your-db-name--> dbpass=<--db-pass-->
Read Also: AWS CLI: 10 useful S3 commands
Now we have added source_db now it’s turns to add destination db. Let’s get started.
bucardo add db dest_db dbhost=<--dest-db-host--> dbport=5432 dbname=<--your-db-name--> dbuser=<--your-db-name--> dbpass=<--db-pass-->
Now we have added both dbs now we will add tables to replicate.
bucardo add tables <--tables-name--> db=source_db
Now we will add herd.
bucardo add herd copying_herd<--tables-name-->
Now in the last we add the sync.
bucardo add sync installvirtual relgroup=copying_herd dbs=source_db:source,dest_db:target onetimecopy=2
Now we have setup bucardo with all the details so now it’s time to start it. So let’s start it.
Now check the status 0f bucardo
Read Also: How-to-install-minio-on-centos-7
If there is any problem installing bucardo please feel free to comment below.