pgautofailover

pg_auto_failover

Overview

PackageVersionCategoryLicenseLanguage
pgautofailover2.2ADMINPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
5150pgautofailoverNoYesYesYesNoNo-
Relatedbtree_gist pglogical pglogical_origin pg_failover_slots pgpool_recovery repmgr pg_checksums pgpool_adm bgw_replstatus

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG2.21817161514pgautofailoverbtree_gist
RPMPGDG2.21817161514pg_auto_failover_$v-
DEBPGDG2.21817161514postgresql-$v-auto-failover-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PGDG MISS
el8.aarch64PGDG MISS
el9.x86_64PGDG MISS
el9.aarch64PGDG MISS
el10.x86_64PGDG MISS
el10.aarch64PGDG MISS
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Install

You can install pgautofailover 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 pgautofailover;          # Install for current active PG version
pig ext install -y pgautofailover -v 18  # PG 18
pig ext install -y pgautofailover -v 17  # PG 17
pig ext install -y pgautofailover -v 16  # PG 16
pig ext install -y pgautofailover -v 15  # PG 15
pig ext install -y pgautofailover -v 14  # PG 14
dnf install -y pg_auto_failover_18       # PG 18
dnf install -y pg_auto_failover_17       # PG 17
dnf install -y pg_auto_failover_16       # PG 16
dnf install -y pg_auto_failover_15       # PG 15
dnf install -y pg_auto_failover_14       # PG 14
apt install -y postgresql-18-auto-failover   # PG 18
apt install -y postgresql-17-auto-failover   # PG 17
apt install -y postgresql-16-auto-failover   # PG 16
apt install -y postgresql-15-auto-failover   # PG 15
apt install -y postgresql-14-auto-failover   # PG 14

Preload:

shared_preload_libraries = 'pgautofailover';

Create Extension:

CREATE EXTENSION pgautofailover CASCADE;  -- requires: btree_gist

Usage

pgautofailover: pg_auto_failover

pg_auto_failover is an extension and service for automated PostgreSQL failover. It consists of a monitor node (running the pgautofailover extension), and keeper processes on each data node managed by the pg_autoctl CLI.

Architecture

  • Monitor: a PostgreSQL instance with the pgautofailover extension that implements a state machine for failover decisions
  • Keeper (pg_autoctl run): runs on each data node, reports health to the monitor and executes state transitions
  • Supports 2+ node setups with synchronous replication by default
  • Supports Citus HA (since v2.0)

Key CLI Commands

# Create the monitor
pg_autoctl create monitor --pgdata /path/to/monitor --pgport 5000

# Create a data node (primary or secondary auto-assigned)
pg_autoctl create postgres --pgdata /path/to/data --pgport 5001 --monitor postgres://monitor:5000/pg_auto_failover

# Run the keeper (foreground)
pg_autoctl run --pgdata /path/to/data

# Check cluster state
pg_autoctl show state --pgdata /path/to/monitor

# Perform a manual switchover
pg_autoctl perform switchover --pgdata /path/to/monitor

# Perform a manual failover
pg_autoctl perform failover --pgdata /path/to/monitor

Failover Behavior

The monitor tracks node health. When a secondary becomes unavailable or its lag is too high, it is removed from synchronous_standby_names on the primary. Failover/switchover operations are blocked until the secondary is healthy again, preventing data loss.

Documentation

Full documentation: pg-auto-failover.readthedocs.io


Last Modified 2026-07-01: routine extension udpate (aed637d)