A PostgreSQL high-availability cluster is only as reliable as its failover procedure.
Having a primary server and replicas does not prove that the system can recover from a failure. You need to test what happens when the primary disappears, how quickly a replica becomes the new leader, whether applications reconnect correctly, and how the failed node is returned to the cluster.
Autobase 2.11 adds more lifecycle management to its PostgreSQL platform, including scaling, upgrades, backup, restore, and point-in-time recovery. Its underlying high-availability workflow uses PostgreSQL replication with Patroni and a distributed configuration store such as etcd.
That makes Autobase 2.11 a useful platform for building a repeatable failover and recovery test.
Understanding the Autobase HA Architecture
A typical Autobase PostgreSQL cluster contains several components:
+----------------+
| Application |
+-------+--------+
|
v
+---------------+
| HAProxy / VIP |
+-------+-------+
|
+-----------+-----------+
| |
v v
+---------------+ +---------------+
| PostgreSQL | | PostgreSQL |
| Primary | | Replica |
+-------+-------+ +-------+-------+
| |
+-----------+-----------+
|
v
+---------------+
| Patroni |
+-------+-------+
|
v
+---------------+
| etcd / DCS |
+---------------+
Patroni manages PostgreSQL roles and participates in leader election through the distributed configuration store.
The routing layer then needs to direct new client connections to the current primary.
This creates several separate failure domains.
A successful database failover does not automatically mean that the application has recovered.
Failover and Switchover Are Different
These operations should not be confused.
A switchover is planned.
For example, you may move the primary role before server maintenance:
Primary A
|
| planned switchover
v
Primary B
A failover is performed because the current leader is unavailable or cannot safely continue serving as primary.
Primary A
X
|
| failure
v
Replica B
|
v
New Primary
Autobase provides automation for both operations.
A normal maintenance test should use switchover first. It is easier to observe and gives the team a controlled way to validate that the cluster can change leadership.
A failure test should then simulate an actual primary outage.
Check the Cluster Before Testing
Never start a failover test without recording the initial state.
Check:
Node A: Primary
Node B: Replica
Node C: Replica
Replication:
Node B -> streaming
Node C -> streaming
DCS:
Healthy
Application:
Connected
The exact commands depend on the deployment, but Patroni provides cluster status information through its command-line tools.
A typical check looks like:
patronictl list
You want to know:
Which node is leader
Which nodes are replicas
Whether replicas are streaming
Whether any replica is lagging
Whether the DCS is healthy
Which node the application is currently using
Do not proceed if the cluster is already degraded. Otherwise, the test result becomes difficult to interpret.
Measure Replication Lag Before Failover
A replica that is several gigabytes behind the primary is not an equivalent failover target.
Autobase's Patroni configuration includes a maximum lag threshold for failover candidates.
A common configuration is:
maximum_lag_on_failover: 1048576
This value represents bytes.
In this example, a replica must be within the configured lag threshold to be considered eligible for automatic failover.
Before testing, check the actual replication state.
For example:
SELECT
application_name,
client_addr,
state,
sync_state,
write_lag,
flush_lag,
replay_lag
FROM pg_stat_replication;
The exact columns available and their behavior depend on the PostgreSQL version and replication configuration.
The important point is to record lag before introducing failure.
Test Planned Switchover First
A planned switchover is the safest first test.
Use the cluster management tooling to move the leader role to a healthy replica.
For example:
patronictl switchover <cluster-name>
After the operation:
patronictl list
Confirm that the expected replica became the new leader.
Then test the application.
Do not stop at the database layer.
Run a write operation:
INSERT INTO failover_test
(message, created_at)
VALUES
('switchover test', now());
Then read the value through the normal application connection path.
This confirms that the routing layer followed the new leader.
Simulate Primary Failure
After a successful switchover test, test an unexpected failure.
The safest approach is to perform this in an isolated test environment.
For example:
Before:
Node A = Primary
Node B = Replica
Node C = Replica
Failure:
Node A = Unavailable
Expected:
Node B or C = New Primary
Do not simply stop PostgreSQL if your objective is to test a complete infrastructure failure.
Different tests reveal different failure modes.
PostgreSQL Process Failure
Stop PostgreSQL on the primary.
This tests database-process recovery.
Patroni Failure
Stop Patroni while PostgreSQL remains available.
This tests the HA control plane.
Server Failure
Power off or isolate the primary node.
This is closer to an actual host failure.
Network Isolation
Block communication between the primary and other cluster members.
This is particularly important because network failures can create ambiguous states.
The test should verify that the system does not allow two nodes to operate as independent primaries.
What Should Happen During Failover?
A simplified sequence is:
Primary becomes unavailable
|
v
Patroni detects failure
|
v
DCS confirms leadership state
|
v
Eligible replica is promoted
|
v
Routing layer detects new primary
|
v
Application reconnects
The exact timing depends on Patroni configuration, database state, network conditions, and application connection behavior.
Autobase's default Patroni settings include values such as:
ttl: 30
loop_wait: 10
retry_timeout: 10
These settings influence failure detection and cluster coordination.
Do not turn them into a guaranteed failover time. Actual recovery time must be measured in the environment being tested.
Measure Recovery Time
A failover test should produce numbers.
At minimum, record:
T0 = Primary failure
T1 = Failure detected
T2 = New primary elected
T3 = Routing updated
T4 = Application reconnects
T5 = Successful write
Then calculate:
Detection time = T1 - T0
Promotion time = T2 - T1
Routing recovery = T3 - T2
Application recovery = T4 - T3
Total recovery = T5 - T0
This is much more useful than saying:
"Failover worked."
A cluster can successfully fail over while still causing unacceptable application downtime.
Test Client Connections
Database failover and application recovery are separate problems.
Suppose the application holds a connection to the old primary:
Application
|
v
Connection
|
v
Old Primary
X
That connection cannot magically become a connection to the new primary.
The application needs a connection path that can reconnect.
This is why the HAProxy, VIP, or other routing mechanism must be included in the test.
Test:
Existing connection during failure.
New connection after promotion.
Connection pooling behavior.
Retry behavior.
Transaction behavior during failure.
Join the conversation! Your thoughts help the community grow.