Skip to content

How to Set up PostgreSQL Replication on Debian 11

Netcloud24
Cloud Infrastructure Expert
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

 

Introduction

PostgreSQL is a powerful, open-source object-relational database system that offers advanced features for database management. Setting up replication is essential for ensuring high availability and load balancing. In this guide, we will walk you through the process of setting up PostgreSQL replication on Debian 11, which can be effectively utilized with for enhanced performance.

Prerequisites

  • Debian 11 installed on your server
  • PostgreSQL installed
  • Two servers for primary and secondary databases
  • Basic understanding of command-line operations

Step 1: Configure the Primary Server

Start by editing the PostgreSQL configuration file on the primary server. Open the postgresql.conf file using your preferred text editor:

sudo nano /etc/postgresql/13/main/postgresql.conf

Locate the following settings and modify them:

Visual overview of How to Set up PostgreSQL Replication on Debian 11
Visual overview: How to Set up PostgreSQL Replication on Debian 11
wal_level = replica
archive_mode = on
archive_command = 'test ! -f /var/lib/postgresql/wal_archive/%f && cp %p /var/lib/postgresql/wal_archive/%f'
max_wal_senders = 3

After saving your changes, restart PostgreSQL:

sudo systemctl restart postgresql

Step 2: Configure the Secondary Server

Next, set up the secondary server to replicate from the primary server. First, create a base backup using the following command:

pg_basebackup -h primary_server_ip -D /var/lib/postgresql/13/main -U replication_user -P --wal-method=stream

Replace primary_server_ip with the actual IP address of your primary server. Once the backup is complete, configure the secondary server by creating a recovery.conf file:

sudo nano /var/lib/postgresql/13/main/recovery.conf

In this file, add the following lines:

standby_mode = 'on'
primary_conninfo = 'host=primary_server_ip port=5432 user=replication_user password=your_password'
trigger_file = '/tmp/postgresql.trigger.5432'

Finally, restart the PostgreSQL service on the secondary server:

sudo systemctl restart postgresql

Step 3: Verify Replication

To verify that replication is working, you can check the replication status on the primary server:

Key topics covered in How to Set up PostgreSQL Replication on Debian 11
Key topics covered in this NetCloud24 guide.
SELECT * FROM pg_stat_replication;

You should see the status of the connected secondary server. If you’re using a , ensure that the necessary ports are open in your firewall settings.

Conclusion

Setting up PostgreSQL replication on Debian 11 is a straightforward process that enhances your database’s reliability and performance. This setup can be particularly beneficial for those using UK Windows VPS solutions. For more information on server hosting options, including Windows VPSVirtual Private Server Hosting, consider exploring various providers for your needs.

© 2024 PostgreSQL Tutorial. All rights reserved.

How to Set up PostgreSQL Replication on Debian 11
How to Set up PostgreSQL Replication on Debian 11
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.