Skip to content

[Feature]: Publish the primary's position on its lease and add the replica's "has all the data" decision #11884

Closed

Description

@leonardoce

Is there an existing issue already for this feature request/idea?

  • I have searched for an existing issue, and could not find anything. I believe this is a new feature request to be evaluated.

What problem is this feature going to solve? Why should it be added?

When a primary is shut down for a switchover, a replica may not yet have all the WAL the primary wrote. Today there is no way for the replica to tell, because the position of the old primary isn't available to it anywhere.

Describe the solution you'd like

The primary lease should carry a cnpg.io/position annotation holding the LSN, the timeline, the PostgreSQL state and the pod that wrote it, for example {"lsn":"0/7000028","timeline":3,"state":"in production","pod":"cluster-example-1"}.

While the primary runs, every write of the lease should refresh the annotation with the current WAL flush position.
When the primary shuts down, the lease should be released with the final position read from pg_controldata.

The state in the annotation should say whether PostgreSQL stopped cleanly or the position is only a lower bound.
If the position can't be determined, the annotation should say unknown instead of being removed.

We should then add a decision that compares the replica's own position with the one on the lease.

After a clean shutdown of the old primary, a replica that has all the data should promote.
After a clean shutdown of the old primary, a replica that is missing some data should wait for the WAL to arrive from the archive.
After a clean shutdown of the old primary, a replica on a later timeline than the old primary's last one should be blocked.

To keep the current behavior, after a failover, or when the position is unknown, the replica should promote and report the amount of WAL that may be missing.

Describe alternatives you've considered

N.A.

Additional context

No response

Backport?

No

Are you willing to actively contribute to this feature?

Yes

Code of Conduct

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

Activity

  1. added this to the 1.31.0 milestone on Nov 10, 2026
  2. added
    enhancement 🪄
    on Nov 10, 2026
  3. added
    do not backport
    on Nov 10, 2026
  4. moved this to Waiting for Second Review in CloudNativePG operator developmenton Nov 12, 2026
  5. moved this from Waiting for Second Review to Done in CloudNativePG operator developmenton Nov 16, 2026
  6. added a commit that references this issue on Nov 16, 2026
    bae6e46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

do not backportenhancement 🪄

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions