Asynchronous Master-Slave Replication of PostgreSQL Databases in One Click
Replicating your data has obvious benefits, but can be a bit tedious to setup. Take a look at how to easily set it up using PostgreSQL and Jelastic's cloud.
Join the DZone community and get the full member experience.
Join For Freeas a critical component for most applications, data has to be available for end users in a dynamically changing environment. storing data in one location is a subject to risk in case of a system failure. therefore, you need to come up with a strategy on how to ensure high availability — and one of the solutions is to maintain the data on multiple synchronized servers.
having your data replicated to another database can be very helpful for a variety of reasons, such as improving performance, running backup services, analyzing information, and by all means alleviating system failures.
among numerous database clustering solutions , jelastic provides the postgresql package with master-slave asynchronous replication that can be installed automatically and run with no additional configurations required.
now let’s take a quick look at the package specs and follow the step-by-step installation guide.
the presented postgresql replication solution for one-click installation is based on jelastic certified postgresql 9.5.5 template. by default, it deploys two database containers (one per role: master and slave) with asynchronous replication between them.
the primary (master) server runs active database which handles read-write operations, whilst the standby (slave) server operates with this db copy and handles read-only operations. therefore, if the primary database fails, the system will run data from the fail-over slave container.
within the package, each database container has a default vertical scaling from 1 reserved to 24 dynamic cloudlets (up to 3 gib of ram and 9.6 ghz of cpu) that are allocated dynamically based on the incoming load. subsequently, you can change the resource allocation limit by following the above-linked guide.
now, let’s proceed further to get the postgresql package up and running in the cloud.
deploying postgresql replication package
the package installation is a fairly simple process that you can perform in just a few clicks.
-
log into the jelastic platform with your credentials and click marketplace in the top pane.
within the apps section, use the search box to find the postgresql database replication package and click install .
tip: the postgresql replication package sources are available within jelastic jps collection alongside with other useful solutions, any of which can be integrated through importing amanifest.jps
file from the appropriate repository. -
in the installation window, type environment name and display name ( alias ), select a region (if several regions are available) and click install .
when the package installation is completed, you’ll see a confirmation message with the master node url and simultaneously receive an email notification with your administration data.
now, let’s put the master database into action to check that data is successfully replicated to the slave.
to ensure that data is replicated properly, we’ll create a new db instance in the master container and check its presence inside the slave.
create new pg database
-
click open in browser next to the postgresql master node to launch the phppgadmin web interface.
-
under servers , click postgresql and log in with credentials you’ve received via email after the package installation.
-
click create database , fill in the name box (e.g. jelastic ), and click create .
now, when the database is created in the master node, let’s check the replicated data within the slave container.
check the replication
to ensure that data replication from the master to the slave container works as intended, perform the following steps.
-
click open in browser next to the postgresql slave node to launch the phppgadmin web interface.
-
access the admin interface with the same username and password that you’ve received via email after the package installation.
once logged in, you can see and manage the database (jelastic, in our example) that was earlier created in the master container.
that’s it! the postgresql environment with master-slave asynchronous replication is up and ready for data processing.
as a next step, you can already connect these postgresql replicated databases to your project. the process depends on application specifics, so follow the instructions below for:
Published at DZone with permission of Tetiana Markova, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments