12

PostgreSQL Auto-Clustering with Asynchronous Master-Slave Replication

 3 years ago
source link: https://jelastic.com/blog/postgresql-auto-clustering-master-slave-replication/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Rn2mAve.png!web

As 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 from one database to another allows to alleviate system failures, improve productivity, run backup services, and analyze data with no performance degrade.

Among numerous database clustering solutions , Jelastic provides PostgreSQL with master-slave asynchronous replication based on the certified templates. By default, it deploys two database containers (one per role - master and slave). 

The primary (master) server runs an active instance of the database and accepts read-write operations, whilst the standby (slave) server runs a copy of the active database and handles read-only operations. Therefore, if the primary database fails due to container failure or database corruption, the slave server (running in a separate container) has to be promoted to the master retaining the writes to ensure database availability.

MZBr2mb.png!web

Within the cluster topology, each database container has a defaultvertical scaling from 2 reserved to 32 dynamic cloudlets (up to 4 GiB of RAM and 12.8 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.

Database Cluster can be installed automatically:

  • As a Marketplace application
  • Via embedded Auto-Clustering feature at the Dashboard

Within this tutorial, we will cover both.

PostgreSQL Cluster Installation from Marketplace

PostgreSQL Master-Slave Clusterpackage can be easily found in the Marketplace. 

mAVFj2b.png!web

If required change database Version , Environment name and destinationRegion in the installation window.

zEZRRvm.png!web

PostgreSQL Auto-Clustering Mode

In Jelastic, auto-clustering is enabled by a specially designed switch that makes clustering easier than ever before. To do this just invoke thetopology wizard at the dashboard, pick the software stack(e.g. PostgreSQL 12.3) and slide the Auto-Clustering switch to the right.

mmIzUrF.png!web

Change the destination region if necessary. Here we chose Premium .

Tip:The PostgreSQL Replication package sources are available within Jelastic JPS Collection alongside with other useful solutions, any of which can be integrated throughimporting a manifest.yaml or manifest.jps file from the appropriate repository.

Cluster Topology

Database cluster topology obtained upon both deployments looks like as follows:

A3qIVja.png!web

When the database cluster installation is completed, you’ll see a confirmation message with master node URL and database access credentials. All this information is duplicated via email.

JvMFv26.png!web

Note:If the cluster was installed with auto-clustering functionality the credentials are sent via email only.

Now, let’s put the master database into action to check that data is successfully replicated to the slave.

Testing PostgreSQL Database Replication

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 a New Database

1. Click Open in Browser next to the PostgreSQL Master node to launch the phpPgAdmin web interface.

YBj6nmJ.png!web

2. Under Servers , click PostgreSQL and log in with credentials you’ve obtained upon cluster installation. 

VZN7RnR.png!web

3. Click Create database

uyq2mqQ.png!web

4. Fill in the Name box (e.g. Jelastic ), and click Create

26ZnYnb.png!web

Now, when the database is created in the master node, let’s check the replicated data within the slave one.

Check the Replication

To make sure that data replication from the master to the slave database node works as intended, perform the following steps.

1. Click Open in Browser next to the PostgreSQL Slave node to launch the phpPgAdmin web interface.

qaUziei.png!web

2. Access admin interface with the same username and password that you’ve used to access the master node.

3AvEv2b.png!web

Once logged in, you can see the replicated database ( Jelastic , in our example).

That’s it! The PostgreSQL environment with master-slave asynchronous replication is up and ready for data processing.

As a next step, you can connect this PostgreSQL replicated database to your project. The process depends on application specifics, so follow the instructions below for:

Try out by yourself how easy it can be to handle multiple copies of essential data within replicated PostgreSQL databases with no need to make manual configurations. Register at one of Jelastic cloud hosting providers and get a free account for testing.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK