bgw_replstatus

Small PostgreSQL background worker to report whether a node is a replication master or standby

Overview

PackageVersionCategoryLicenseLanguage
bgw_replstatus1.0.8STATPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
6510bgw_replstatusNoYesYesNoNoNo-
Relatedpgautofailover pglogical pg_failover_slots pgpool_recovery pgsentinel pglogical_origin repmgr pg_jobmon

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.0.81817161514bgw_replstatus-
RPMPGDG1.0.81817161514bgw_replstatus_$v-
DEBPGDG1.0.81817161514postgresql-$v-bgw-replstatus-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
d12.aarch64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
d13.x86_64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
d13.aarch64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
u22.x86_64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
u22.aarch64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
u24.x86_64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
u24.aarch64
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8
PGDG 1.0.8

Install

You can install bgw_replstatus directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install bgw_replstatus;          # Install for current active PG version
pig ext install -y bgw_replstatus -v 18  # PG 18
pig ext install -y bgw_replstatus -v 17  # PG 17
pig ext install -y bgw_replstatus -v 16  # PG 16
pig ext install -y bgw_replstatus -v 15  # PG 15
pig ext install -y bgw_replstatus -v 14  # PG 14
dnf install -y bgw_replstatus_18       # PG 18
dnf install -y bgw_replstatus_17       # PG 17
dnf install -y bgw_replstatus_16       # PG 16
dnf install -y bgw_replstatus_15       # PG 15
dnf install -y bgw_replstatus_14       # PG 14
apt install -y postgresql-18-bgw-replstatus   # PG 18
apt install -y postgresql-17-bgw-replstatus   # PG 17
apt install -y postgresql-16-bgw-replstatus   # PG 16
apt install -y postgresql-15-bgw-replstatus   # PG 15
apt install -y postgresql-14-bgw-replstatus   # PG 14

Preload:

shared_preload_libraries = 'bgw_replstatus';

Usage

bgw_replstatus: lightweight replication status checker for load balancers

bgw_replstatus is a background worker that listens on a TCP port and immediately reports whether the node is a MASTER or STANDBY. Designed for load balancer health checks without requiring a full PostgreSQL connection.

How It Works

Any TCP connection to the configured port receives an immediate text response (MASTER or STANDBY) and the connection is closed. No request is needed.

Quick Test

nc localhost 5400
# Output: MASTER (or STANDBY)

HAProxy Configuration Example

frontend test
    bind 127.0.0.1:5999
    default_backend pgcluster

backend pgcluster
    mode tcp
    option tcp-check
    tcp-check expect string MASTER
    server s1 127.0.0.1:5500 check port 5400
    server s2 127.0.0.1:5501 check port 5401 backup
    server s3 127.0.0.1:5502 check port 5402 backup

Configuration

ParameterDefaultDescription
bgw_replstatus.port5400TCP port to listen on
bgw_replstatus.bind(wildcard)IP address to bind to

Security note: There is no source verification. Protect the port with a host firewall.


Last Modified 2026-03-12: add pg extension catalog (95749bf)