HA Drill: Handling 2-of-3 Node Failure
In a typical 3-node HA deployment, simultaneous failure of two nodes removes the majority. The system usually cannot complete automatic failover and needs manual intervention.
First, assess the two failed servers. If they can restart quickly, prioritize their recovery. Otherwise, use the Emergency Recovery Procedure.
The Emergency Recovery Procedure assumes that the administration node has failed and only one regular database node survives. In this case, the fastest recovery procedure is:
- Adjust HAProxy configuration to direct traffic to the primary.
- Stop Patroni and manually promote the PostgreSQL replica to primary.
Adjust HAProxy Configuration
If connections bypass HAProxy, skip this step. If connections use HAProxy, change its configuration to direct read/write traffic to the primary manually.
- Edit
/etc/haproxy/conf.d/<pg_cluster>-primary.cfg, where<pg_cluster>is your PostgreSQL cluster name, e.g.,pg-meta. - Comment out the health check configuration options to stop health checks.
- Comment out the other two failed machines in the server list, keeping only the current primary server.
After you change the configuration, wait until primary promotion before you run systemctl reload haproxy.
The new configuration disables HAProxy primary health checks, which use Patroni by default.
HAProxy then directs write traffic to the current primary.
Manually Promote Replica
Log in to the target server and switch to the dbsu user.
Run CHECKPOINT to flush data to disk.
Stop Patroni, restart PostgreSQL, then promote the replica:
If you changed the HAProxy configuration, now run systemctl reload haproxy.
This applies the configuration and directs traffic to the new primary.
Avoid Split Brain
After emergency recovery, the next priority is to Avoid Split Brain. Prevent the other two servers from returning online and becoming competing primaries. Such a split brain can cause data inconsistency.
Simple approaches:
- Power off/disconnect network the other two servers to ensure they don’t come online uncontrollably.
- Adjust the database connection string used by applications to point directly to the surviving server’s primary.
Then decide the next steps based on the specific situation:
- A: The two servers have temporary failures (e.g., network/power outage) and can be repaired in place to continue service.
- B: The two failed servers have permanent failures (e.g., hardware damage) and will be removed and decommissioned.
Recovery After Temporary Failure
If the other two servers have temporary failures and can return to service, use these repair and rebuild steps:
- Handle one failed server at a time, prioritize the admin node / INFRA node.
- Start the failed server and stop Patroni after startup.
When ETCD regains quorum, it resumes operation. Start Patroni on the surviving server, which is the current primary. Patroni takes control of the existing PostgreSQL instance and regains cluster leadership. Then enter maintenance mode:
On each of the other two instances, use the postgres account to run touch /pg/data/standby.signal.
The marker identifies the instance as a replica.
Then start Patroni:
After confirming Patroni cluster identity/roles are correct, exit maintenance mode:
Recovery After Permanent Failure
After permanent failure, first recover ~/pigsty on the administration node.
The essential files are pigsty.yml and files/pki/ca/ca.key.
If you cannot retrieve these two files or their backups, deploy a new Pigsty installation. Migrate the existing cluster through Backup Cluster.
Back up the
pigstydirectory regularly, for example with Git version control.
Configuration Repair
You can use the surviving node as the new administration node.
Copy ~/pigsty to it, then adjust the configuration.
For example, replace the original administration node 10.10.10.10 with the surviving node 10.10.10.12:
ETCD Repair
Then execute the following command to reset ETCD to a single-node cluster:
Follow the instructions in ETCD Reload Configuration to adjust ETCD Endpoint references.
INFRA Repair
If the surviving node does not have the INFRA module, configure and install it on that node. Run this command:
Repair monitoring on the current node:
PGSQL Repair
After you repair each module, use the standard expansion procedure to add nodes and restore cluster high availability.