Bidirectional Replication

Disclaimer: This lesson uses the terms bidirectional and multi-primary instead of the terms master-master and multi-master, respectively. Please refer to the PostgreSQL documentation for more details.

In a bidirectional replication setup, multiple database servers act as primary databases and receive updates from client applications. Each database server can receive writes and updates, and replicate changes to all other nodes in the cluster. This type of replication is also known as multi-primary replication.

Bidirectional replication is a bidirectional replication in which changes made to the data on one server are automatically propagated to another server, and vice versa. This setup allows for load balancing, high availability, and increased data accessibility, as the data is replicated between multiple servers.

With bidirectional replication, there is no single primary server that controls the data, as both servers can be updated independently. This type of replication is often used in scenarios where multiple servers are spread across different locations and a single server outage would cause significant downtime.

Prerequisites

The prerequisites for this are as follows:

  1. Two PostgreSQL servers run the same version.

  2. Both servers should have access to the same network.

  3. The servers should have unique hostnames and IP addresses.

  4. There should be a superuser account on both servers to set up replication.

Installing PostgreSQL and setting up configuration files

This is done through the following steps:

  1. We install PostgreSQL on both servers by following the installation instructions for our operating system.

  2. After installation, we open the configuration file on both servers, postgresql.conf.

  3. We add the following configuration parameters on both servers:

Get hands-on with 1200+ tech skills courses.