Back to articles
DevOps & Systems

Configuring PostgreSQL Active-Active Global Cluster with pgEdge on VPS

This guide walks through setting up a PostgreSQL Active-Active global cluster using pgEdge on two VPS instances across different continents. It covers installation, configuration,...

DPTCloud Engineering4 min read
Configuring PostgreSQL Active-Active Global Cluster with pgEdge on VPS

Transitioning from a single database system to a globally distributed PostgreSQL Active-Active cluster with pgEdge on VPS significantly improves availability, performance, and disaster recovery. This guide provides a step-by-step walkthrough to deploy, configure, and validate a two-way synchronized, distributed database cluster across two geographically separate locations using pgEdge—a PostgreSQL extension optimized for cloud and VPS environments. The process includes installation, network configuration, data replication, troubleshooting, and essential security measures to ensure stable and secure operations.

Overview of PostgreSQL Active-Active and pgEdge

PostgreSQL Active-Active clustering allows multiple servers to simultaneously process read and write operations, enabling load balancing and high fault tolerance. pgEdge, an open-source extension of PostgreSQL, simplifies the deployment of distributed clusters by offering built-in features such as automatic data sharding, real-time synchronization, and cluster management. It is specifically optimized for VPS environments where resource constraints require efficient, scalable solutions. With pgEdge, businesses can achieve low-latency data access across continents, making it ideal for global applications with high traffic or stringent recovery requirements.

Prerequisites and Environment Setup

To set up a PostgreSQL Active-Active global cluster with pgEdge on VPS, you need:

  • At least two VPS instances with sufficient resources (minimum 4GB RAM, 2 vCPU, 50GB SSD) located in different regions (e.g., Singapore and the USA).
  • Linux operating system (Ubuntu 20.04 or 22.04 recommended).
  • Static IP addresses for each VPS.
  • Root or sudo user access.
  • Stable network connection between VPS instances (minimum 100 Mbps).

You can deploy these VPS instances using NVMe Cloud VPS for Docker, Nginx & Databases for high performance and cost-effective scaling.

Configuration Steps

1. Install pgEdge on both VPS instances:

Run the following commands on each VPS:

sudo apt update
sudo apt install -y wget
wget -qO - https://download.postgrespro.ru/keys/pgedge.gpg | sudo apt-key add -
echo "deb [arch=amd64] https://download.postgrespro.ru/pgedge/ubuntu/20.04/ focal main" | sudo tee /etc/apt/sources.list.d/pgedge.list
sudo apt update
sudo apt install -y pgedge

2. Initialize the cluster:

On the first VPS (e.g., Singapore), run:

pgedge cluster init --name=global-cluster --primary

On the second VPS (e.g., USA), run:

pgedge cluster join --name=global-cluster --primary=false --join-address=

3. Configure data synchronization:

pgEdge automatically sets up Active-Active synchronization. Ensure the following:

  • Network ports (3000, 5432, 5433) are open on the firewall.
  • Cluster name is identical and correctly spelled on both nodes.
  • System time (NTP) is synchronized across both VPS instances.

4. Verify cluster status:

Run the following command on both VPS instances:

pgedge cluster status

Expected output:

Cluster: global-cluster
Status: Active-Active
Nodes:
  - Singapore: Online
  - USA: Online

Testing and Troubleshooting

1. Network connectivity test:

Ping between the two VPS instances to confirm stable connectivity:

ping 

2. Data synchronization test:

Insert data into a table on the Singapore VPS and verify it appears on the USA VPS:

psql -U postgres -h localhost -c "CREATE TABLE test (id SERIAL PRIMARY KEY, data TEXT);"
psql -U postgres -h localhost -c "INSERT INTO test (data) VALUES ('test data');"

On the USA VPS, verify:

psql -U postgres -h localhost -c "SELECT * FROM test;"

3. Handle synchronization errors:

If replication fails, check logs:

journalctl -u pgedge --no-pager -n 50

4. Security hardening:

Set strong passwords for PostgreSQL users and enable SSL for inter-node communication.

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478