Patroni Standby Replication Cluster Configuration
search cancel

Patroni Standby Replication Cluster Configuration

book

Article ID: 442562

calendar_today

Updated On:

Products

VMware Tanzu Data Services VMware Tanzu for Postgres

Issue/Introduction

The purpose of this KB is to provide a guide for configuring replication between a primary Patroni cluster and a standby Patroni cluster. The steps outlined below explain how to configure the standby cluster to connect to and receive replicated data from the primary cluster.

Environment

Postgres

Patroni 

Resolution

1. Verify the inactive slot on the primary cluster. Run the following command on the primary leader. 

SELECT 
    slot_name, 
    plugin, 
    slot_type, 
    active, 
    restart_lsn, 
    pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal_size
FROM pg_replication_slots;

NOTE: Look for the slot where active is false and retained_wal_size is massive.

 

2. Clear up disk space.

If you are at risk of running out of disk space on the primary, drop the orphaned slot using the following command on the primary leader. 

SELECT pg_drop_replication_slot('your_inactive_slot_name');

 

3. Force a checkpoint to initiate Postgres' internal cleanup process.

This will clean up the retained WAL and .done file. 

CHECKPOINT;

NOTE: Running checkpoint to clear up a large amount of files can cause I/0 spike. 

 

4. Correct the Patroni standby cluster configuration. 

You need to verify your Patroni DCS configuration to be sure the standby cluster establishes the connection using the correct slot. 

Run command patronictl edit-config on the Standby Cluster to check the Patroni configuration. Your standby_cluster block should look similar to this:

standby_cluster:
  host: <primary_leader_ip>
  port: 5432
  primary_slot_name: <desired_slot_name> # Ensure this matches the slot on the primary!
  create_replica_methods:
    - basebackup

Note: If primary_slot_name is missing or mismatched, Patroni will fall back to default behaviors, resulting in the disconnect that you reported. 

 

5. Confirm wal size is reduced to a healthy, minimal size. 

After you have corrected the configuration and restarted the Patroni service on the standby leader, run the query from Step 1 again on the Primary Leader.

 

SELECT 
    slot_name, 
    plugin, 
    slot_type, 
    active, 
    restart_lsn, 
    pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal_size
FROM pg_replication_slots;

Now, you should see the active column is set to true for your replication slot, and the retained_wal_size should be reduced to a healthy, minimal size.