HA clusters
The HA deployment spans two inventory groups and two example variable files:
| Group | File | Role |
|---|---|---|
[ha_etcd] |
group_vars/ha_etcd/main.yml |
Shared etcd DCS, one member per host |
[ha_cluster] |
group_vars/ha_cluster/main.yml |
Patroni members, per-namespace clusters, HAProxy |
The same hosts may appear in both groups (co-located layout). List the etcd bootstrap host first; the add-on play is serial.
etcd: group_vars/ha_etcd/main.yml.example
The file is group-name agnostic: set pg_etcd_group once and everything below
follows it.
_ha_etcd_client_endpoint is consumed by ha_cluster to build the Patroni DCS
endpoint list. Setting the entry’s state: absent destroys the group (remove
the Patroni clusters first).
Patroni: group_vars/ha_cluster/main.yml.example
The host default config gets a namespace, and extra namespaces are declared with their own directories and port ranges:
Which etcd group supplies the DCS, and the derived endpoint list:
Shared S3 backup repository (secret key lives in secrets.yaml):
One cluster entry per namespace:
| Field | Meaning |
|---|---|
namespace |
Namespace from pgcli_namespaces |
scope |
Patroni scope; the namespace suffix keeps clusters apart in DCS |
members |
One name per [ha_cluster] host, in inventory order |
host_port, restapi_port |
PostgreSQL and Patroni REST ports; disjoint per cluster |
dcs_endpoints |
etcd client endpoints |
state |
started (default), stopped, absent |
clean_data |
With absent: delete member data dirs |
autostart |
Enable boot autostart for the members |
extensions |
Extensions installed cluster-wide |
Port ranges, data dirs and backup dirs must not overlap between namespaces. The
same scope name in two namespaces is safe: pgcli bakes the namespace suffix
into the DCS scope and container names.
HAProxy
The proxy targets every [ha_cluster] member via --node; run it on a host
that carries the namespace config. Both instances share one host network, so
their ports must differ. autostart reconciles
pg autostart enable|disable --haproxy --name <name> per instance; it defaults
to false when unset.
Run it
Destroy order
The state switches are independent; destroy in dependency order:
- HAProxy: set
pg_ha_haproxy.clusters[].state: absent, run--tags haproxy. - Patroni clusters: set
pg_ha_clusters[].state: absent(addclean_data: trueto delete member data dirs), run--tags ha. - etcd: set
state: absenton the etcd entry ingroup_vars/ha_etcd, run--tags addon.
The HA plays clear the DCS scope on the first host and remove each host’s local
members serially; later hosts are a no-op for the scope. clean_data deletes
the member data dirs but leaves the empty addon/patroni/<scope> directory.
etcd removal always deletes its data dir. Backup containers, the pgBackRest
configuration and S3 backups are left intact by all of the above.