Do not remove a primary while replicas remain. The remaining replicas will trigger automatic failover. Remove all replicas before the primary. Whole-cluster removal already handles this order.
Refresh services after instance removal. A removed replica remains in the load balancer configuration, but failed health checks prevent it from affecting services. Reload services at an appropriate time to keep the production environment consistent with the inventory.
pgsql-user.yml
Use pgsql-user.yml to add business users to an existing PostgreSQL cluster.
Generate user creation SQL at /pg/tmp/pg-user-{{ user.name }}.sql
Execute user creation/update SQL on the cluster primary
If pgbouncer_enabled: true, update /etc/pgbouncer/userlist.txt and useropts.txt
Reload pgbouncer to apply configuration
User Definition Example
pg_users:- name:dbuser_meta # Required, username is the only mandatory fieldpassword:DBUser.Meta # Optional, can be scram-sha-256 hash or plaintextlogin:true# Optional, can login, default: truesuperuser:false# Optional, is superuser, default: falsecreatedb:false# Optional, can create database, default: falsecreaterole:false# Optional, can create role, default: falseinherit:true# Optional, inherit privileges, default: truereplication:false# Optional, can replicate, default: falsebypassrls:false# Optional, bypass RLS, default: falsepgbouncer:true# Optional, add to pgbouncer userlist, default: falseconnlimit:-1# Optional, connection limit, -1 means unlimitedexpire_in:3650# Optional, expire in N days (overrides expire_at)expire_at:'2030-12-31'# Optional, specify expiration datecomment:pigsty admin user # Optional, user commentroles:[dbrole_admin] # Optional, roles to grantparameters:{}# Optional, role-level parameterspool_mode:transaction # Optional, pgbouncer user-level pool modepool_connlimit:100# Optional, user-level max connections; omitted values inherit global default 100
First, define pg_exporters in the infra group variables:
infra:hosts:10.10.10.10:pg_exporters:# List all remote instances, assign unique unused local ports20001:{pg_cluster:pg-foo, pg_seq:1, pg_host:10.10.10.10}20002:{pg_cluster:pg-foo, pg_seq:2, pg_host:10.10.10.11}
pgsql-migration.yml generates migration manuals and scripts for existing PostgreSQL clusters.
They use logical replication for migration without downtime.
The pgsql-pitr.yml playbook performs PostgreSQL Point-In-Time Recovery (PITR).
Basic Usage
# Recover to latest state (end of WAL archive stream)./pgsql-pitr.yml -l pg-meta -e '{"pg_pitr": {}}'# Recover to specific point in time./pgsql-pitr.yml -l pg-meta -e '{"pg_pitr": {"time": "2025-07-13 10:00:00+00"}}'# Recover to specific LSN./pgsql-pitr.yml -l pg-meta -e '{"pg_pitr": {"lsn": "0/4001C80"}}'# Recover to specific transaction ID./pgsql-pitr.yml -l pg-meta -e '{"pg_pitr": {"xid": "250000"}}'# Recover to named restore point./pgsql-pitr.yml -l pg-meta -e '{"pg_pitr": {"name": "some_restore_point"}}'# Recover from another cluster's backup./pgsql-pitr.yml -l pg-test -e '{"pg_pitr": {"cluster": "pg-meta"}}'
PITR Task Parameters
pg_pitr:# Define PITR taskcluster:"pg-meta"# Source cluster name (for restoring from another cluster's backup)type:default # Recovery target type: default, time, xid, name, lsn, immediatetime:"2025-01-01 10:00:00+00"# Recovery target: point in timename:"some_restore_point"# Recovery target: named restore pointxid:"100000"# Recovery target: transaction IDlsn:"0/3000000"# Recovery target: log sequence numberset:latest # Backup set to restore from, default: latesttimeline:latest # Target timeline, can be integer, default: latestexclusive:false# Exclude target point, default: falseaction:pause # Post-recovery action: pause, promote, shutdownarchive:true# Keep archive settings, default: true; set false for exploratory recoverybackup:false# Backup existing data to /pg/data-backup before restore? default: falsedb_include:[]# Include only these databasesdb_exclude:[]# Exclude these databaseslink_map:{}# Tablespace link mappingprocess:4# Parallel recovery processes, defaults to node_cpurepo:{}# Recovery source repo configurationdata:/pg/data # Recovery data directoryport:5432# Recovery instance listen port
Subtasks
This playbook contains the following subtasks:
# down : stop HA and shutdown patroni and postgres# - pause : pause patroni auto failover# - stop : stop patroni and postgres services# - stop_patroni : stop patroni service# - stop_postgres : stop postgres service## pitr : execute PITR recovery process# - config : generate pgbackrest config and recovery script# - backup : perform optional backup to original data# - restore : run pgbackrest restore command# - recovery : start postgres and complete recovery# - verify : verify recovered cluster control data## up : start postgres/patroni and restore HA# - etcd : clean etcd metadata before startup# - start : start patroni and postgres services# - start_postgres : start postgres service# - start_patroni : start patroni service# - resume : resume patroni auto failover
Recovery Target Types
Type
Description
Example
default
Recover to end of WAL archive stream (latest state)