PostgreSQL High Availability Lab – Preparing Primary & Standby Servers for Streaming Replication


Introduction

Before implementing PostgreSQL Streaming Replication, the most critical step is preparing a stable infrastructure.

Many tutorials jump directly into pg_basebackup and replication commands. However, production environments require a properly configured operating system, networking, hostname resolution, and PostgreSQL validation before replication can be considered reliable.

In this lab, I prepared two virtual machines that will serve as the Primary and Standby servers for a PostgreSQL High Availability (HA) environment.


Lab Environment

Component

Primary

Standby

Operating System

RHEL 8.10

Rocky Linux 9.5

PostgreSQL

16.14

16.14

Role

Primary

Standby

Virtualization

Oracle VirtualBox

Oracle VirtualBox


Target Architecture

                    Client Applications

                           │

                           ▼

                +------------------------+

                |    PostgreSQL Primary  |

                |       pg-primary       |

                |       RHEL 8.10        |

                +------------------------+

                           │

                    Streaming Replication

                           │

                           ▼

                +------------------------+

                |   PostgreSQL Standby   |

                |      pg-standby        |

                |     Rocky Linux 9.5    |

                +------------------------+


Step 1 – Configure Meaningful Hostnames

Using meaningful hostnames makes administration, monitoring, troubleshooting, and documentation much easier.

Primary

hostnamectl set-hostname pg-primary

Verify

hostname

Output

pg-primary


Standby

hostnamectl set-hostname pg-standby

Verify

hostname

Output

pg-standby


Step 2 – Configure Network Interfaces

For a production-like lab, two network adapters were configured on each virtual machine.

Adapter

Purpose

Adapter 1

NAT (Internet Access)

Adapter 2

Host-Only (Replication Network)

This separation ensures that internet traffic and replication traffic remain isolated, similar to enterprise environments.


Step 3 – Configure Static IP Addresses

A dedicated private network was configured for PostgreSQL replication.

Server

Hostname

Static IP

Primary

pg-primary

192.168.56.101

Standby

pg-standby

192.168.56.102

Configuration was performed using NetworkManager.

Verify the assigned addresses:

ip addr

Expected Output

Primary


enp0s8

192.168.56.101

Standby


enp0s8

192.168.56.102


Step 4 – Verify Network Connectivity

Successful communication between both servers is mandatory before configuring streaming replication.

Ping Test

From Primary

ping 192.168.56.102

From Standby

ping 192.168.56.101

Successful replies confirm network connectivity.


Step 5 – Configure Hostname Resolution

To simplify administration, both hostnames were added to /etc/hosts.

Primary

192.168.56.101    pg-primary

192.168.56.102    pg-standby

Standby

192.168.56.101    pg-primary

192.168.56.102    pg-standby

Verify

ping pg-primary

ping pg-standby


Step 6 – Verify SSH Connectivity

Remote administration is essential for backup, maintenance, and replication activities.

Verify SSH service

systemctl status sshd

Verify listening port

ss -tlnp | grep 22


Step 7 – Verify PostgreSQL Installation

Confirm the PostgreSQL version.

psql --version

Output

psql (PostgreSQL) 16.14

Verify service

systemctl status postgresql-16


Step 8 – Validate PostgreSQL Configuration

Verify the data directory.

SHOW data_directory;

Locate the configuration file.

SHOW config_file;

Locate the authentication file.

SHOW hba_file;

These values are required during the replication configuration.


Step 9 – Verify PostgreSQL Listener

Confirm PostgreSQL is accepting TCP connections.

ss -tlnp | grep 5432

Expected Output

LISTEN


Why These Steps Matter

A successful PostgreSQL High Availability implementation depends on a stable foundation.

Skipping hostname configuration, network validation, or connectivity testing often leads to replication failures that are difficult to troubleshoot.

By completing these preparation tasks first, the environment is ready for configuring PostgreSQL Streaming Replication.


Lab Summary

✔ Configured meaningful hostnames

✔ Added dedicated replication network

✔ Assigned static IP addresses

✔ Configured NAT for internet access

✔ Verified SSH connectivity

✔ Validated PostgreSQL installation

✔ Confirmed PostgreSQL listener

✔ Verified hostname resolution

✔ Prepared infrastructure for Streaming Replication


What’s Next?

In the next part of this PostgreSQL High Availability series, I will configure:

  • PostgreSQL Streaming Replication
  • WAL Configuration
  • Replication User
  • Replication Slots
  • pg_basebackup
  • Standby Configuration
  • Replication Monitoring
  • Failover Testing


Conclusion

High Availability begins long before the first replication command is executed.

Proper hostname configuration, network planning, static IP assignment, and infrastructure validation provide the reliable foundation required for a resilient PostgreSQL cluster.

Building these fundamentals correctly minimizes troubleshooting, simplifies administration, and prepares the environment for production-grade streaming replication.

Comments