Troubleshoot using Patroni
To be sure that the PostgreSQL cluster is up and running and replication is in sync, you can use PatroniOpens in a new tab, which runs inside every PostgreSQL instance deployed by the Cennso PostgreSQL Instance. Patroni has no user interface. You inspect the cluster with the patronictl utility inside a PostgreSQL pod.
To check the state of the PostgreSQL cluster, execute the following steps:
List the PostgreSQL pods in the cluster. The operator labels every pod with its current role, so you can see the primary and the replicas:
bashThe
ROLEcolumn showsprimaryfor the primary andreplicafor the replicas. Thepostgres-operator.crunchydata.com/instancelabel limits the list to the PostgreSQL pods.Run
patronictl listinside thedatabasecontainer of any PostgreSQL pod:bashThe output lists every member of the cluster with its role, state, timeline, and replication lag. For example, for a
PostgreSQLInstancenamedpg-instance:textA healthy cluster shows exactly one
Leaderin therunningstate and every replica in thestreamingstate with bothLagcolumns close to0. The firstLagcolumn shows how far the replica is behind in receiving the WAL from the primary, and the second one shows how far it is behind in replaying it. All members share the same timeline in theTLcolumn. A replica in thestoppedorstart failedstate, a growing lag, or a member on an older timeline points to a replication problem.If a member is unhealthy, read the Patroni and PostgreSQL logs of its pod:
bash
Switch the primary to another replica
Patroni promotes a replica automatically when the primary becomes unavailable, so no manual action is required. A manual switchover is useful when the primary is healthy, but you want to move it, for example before you drain the node that runs it for maintenance.
A switchover is a controlled role change. Patroni makes the chosen replica the new primary, and the old primary joins the cluster again as a replica. Client connections through PgBouncerOpens in a new tab are interrupted for a few seconds while the roles change.
To switch the primary to another replica, execute the following steps:
List the members of the cluster and note the names of the current primary and of the replica you want to promote:
bashChoose a replica in the
streamingstate with a lag of0, so that no committed transactions are lost during the switchover.Run the switchover from any PostgreSQL pod. The
--forceoption skips the interactive confirmation:bashReplace the following placeholders with the member names from step 1:
{CURRENT-PRIMARY-MEMBER}- the member shown asLeader{REPLICA-MEMBER}- the member you want to promote
To run the switchover at a later time, add
--scheduled {TIMESTAMP}with an ISO 8601 timestamp, for example2026-10-05T22:00:00+00:00.Check the result. The chosen replica is now the
Leader, the former primary is aReplicain thestreamingstate, and the timeline in theTLcolumn increased by one:bash
The operator updates the role labels of the pods and the primary Service after the switchover, so clients keep connecting through the same endpoints.