Skip to content

Physical replication reports the server's WAL end as the write position #6697

Description

@Brar

In physical replication, Npgsql sends LastReceivedLsn as the write position of its standby status updates (ReplicationConnection.cs:626-630), and sets it to the WalEnd field of each XLogData message and of each keepalive (:481-484, 517-518). An XLogData message's WalEnd is how far the server's WAL extends, not the end of the data in the message (postgres walsender.c:3611-3612), while walreceiver reports the end of what it has written (postgres walreceiver.c:945-952, 1064, 1256-1263).

So pg_stat_replication.write_lsn shows WAL as written before it reached the client. With the client in synchronous_standby_names and synchronous_commit = remote_write, the primary can confirm a commit before its WAL arrived. Also, LastReceivedLsn is never reset when a new stream starts, so it keeps the highest position of earlier streams, which is wrong when the next one starts lower, e.g. on a restart from the last flushed position after a cancel (nothing resets it, and it only increases, :481-484, 517-518).

Logical XLogData messages aren't affected by the WalEnd problem: their WalEnd is their start position (postgres walsender.c:1642-1643). The missing reset affects logical streams too. The same code is on the 8.0, 9.0 and 10.0 hotfix branches.

Activity

  1. added this to the 11.0.0 milestone on Oct 25, 2026
  2. self-assigned this
    on Oct 25, 2026
  3. added theissue type on Oct 25, 2026
  4. modified the milestones: 11.0.0, 12.0.0 on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions