[Bug]: Replica cluster may fail over to the wrong instance

Author: leonardoceCreated Sep 16, 2026Updated Sep 18, 2026
Labelsbug :bug:

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

[email protected]

Version

1.30.0

What version of Kubernetes are you using?

1.37

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

In a replica cluster (https://cloudnative-pg.io/documentation/current/replica_cluster/), CloudNativePG determines which instance is the current/designated primary (and therefore the failover candidate) by sorting the list of instance statuses and picking the first entry.

Due to a bug in the comparison function used for this sort, the designated primary instance was not always guaranteed to end up first in the list.

Because the operator relies on the first item of the sorted status list as the current/promotion-candidate primary, an incorrect ordering could lead the operator reporting or acting on the wrong instance as the current primary of a replica cluster.

Note that all instances in a replica cluster are standbys replicating from an external source and none of them accept writes, so this did not put data at risk of being lost or diverged, the impact was limited to incorrect primary/failover bookkeeping within the replica cluster.

Cluster resource

bash

Relevant log output

bash

Code of Conduct

  • I agree to follow this project's Code of Conduct

Source: cloudnative-pg/cloudnative-pg