pg_stat_replication docs incomplete for logical replication

Started by Ashutosh Sharma6 months ago6 messageshackers

Thread notes

1 note#docs
hackorum-bot#docs
hackorum-bot
2 days ago

@global #docs

#docs
Jump to latest
#1Ashutosh Sharma
ashu.coek88@gmail.com

Hi,

I noticed that the documentation for the pg_stat_replication view does
not adequately cover logical replication. The current text only
mentions standby servers, leaving the behaviour of the LSN columns
undefined and potentially misleading for users of logical replication.

Specifically:

1. The view description refers only to "connected standby servers",
omitting logical subscribers, which also appear as rows in the view.

2. The LSN columns (sent_lsn, write_lsn, flush_lsn, replay_lsn) have
fundamentally different semantics for logical replication compared to
physical replication, but this is not documented anywhere.

The distinction matters because:

- sent_lsn for logical replication reflects publisher-side decoding
and output progress, not how far data has been delivered to the
subscriber.
- write_lsn, flush_lsn, and replay_lsn reflect progress reported by
the subscriber through replication status messages, and do not
guarantee that committed changes have been received, durably stored,
or made visible on the subscriber.

This can lead users to incorrectly assume that LSN values in this view
confirm end-to-end delivery of changes in a logical replication setup.

Proposed correction:

- Update the view description to mention logical subscribers alongside standbys.
- Add a paragraph clarifying the differing semantics of the LSN
columns for physical vs logical replication.

I have a patch ready for review if the approach looks acceptable.
Please have a look and let me know your thoughts.

--
With Regards,
Ashutosh Sharma.

Attachments:

0001-doc-clarify-pg_stat_replication-view-for-logical-rep.patchapplication/octet-stream; name=0001-doc-clarify-pg_stat_replication-view-for-logical-rep.patchDownload+37-16
#2Peter Smith
smithpb2250@gmail.com
In reply to: Ashutosh Sharma (#1)
Re: pg_stat_replication docs incomplete for logical replication

Hi Ashutosh.

+1 to clarify documentation.

Some minor review comments.

======

doc/src/sgml/monitoring.sgml

(27.2.4. pg_stat_replication)

1.
+  <para>
+  For physical replication, the LSN columns in this view describe the
+  positions up to which WAL has been sent, written, flushed, and replayed
+  on the connected standby server.  For logical replication,
+  <structfield>sent_lsn</structfield> reflects the LSN up to which the
+  walsender has processed WAL records.  Such records may already have been
+  streamed to the subscriber, queued for streaming at transaction commit, or
+  skipped because they were not eligible for logical decoding.
+
+  <structfield>write_lsn</structfield>, <structfield>flush_lsn</structfield>,
+  and <structfield>replay_lsn</structfield> reflect progress reported by the
+  subscriber through replication status messages, and do not necessarily
+  mean that logical changes up to those LSNs have already been
+  received, durably stored, or made visible on the subscriber.
   </para>

1a.
I'm not sure of the purpose of that blank line; it doesn't affect the
rendering in HTML.

~

1b.
Consider splitting the text differently so there is 1 paragraph for
"Physical Replication" and 1 paragraph for "Logical Replication". So,
the same content just with different <para> markup.

SUGGESTION
<para>
For physical replication, ...
</para>
<para>
For logical replication, ...
</para>

~~~

2.
        <structfield>write_lsn</structfield> <type>pg_lsn</type>
       </para>
       <para>
-       Last write-ahead log location written to disk by this standby
-       server
+         For physical replication, the last write-ahead log location written
+        to disk by this standby server.  For logical replication, progress
+        reported by the subscriber through replication status messages.
       </para></entry>
      </row

For that 2nd sentence, do you mean /progress reported/progress is reported/

Or, here is some alternate wording:
For logical replication, progress is reported by replication status
messages received from the subscriber.

~~~

3.
        <structfield>flush_lsn</structfield> <type>pg_lsn</type>
       </para>
       <para>
-       Last write-ahead log location flushed to disk by this standby
-       server
+         For physical replication, the last write-ahead log location flushed
+        to disk by this standby server.  For logical replication, progress
+        reported by the subscriber through replication status messages.
       </para></entry>
      </row>

Ditto review comment #2

~~~

4.
        <structfield>replay_lsn</structfield> <type>pg_lsn</type>
       </para>
       <para>
-       Last write-ahead log location replayed into the database on this
-       standby server
+         For physical replication, the last write-ahead log location replayed
+        into the database on this standby server.  For logical replication,
+        progress reported by the subscriber through replication status
+        messages.
       </para></entry>

Ditto review comment #2

======
Kind Regards,
Peter Smith.
Fujitsu Australia

#3Ashutosh Sharma
ashu.coek88@gmail.com
In reply to: Peter Smith (#2)
Re: pg_stat_replication docs incomplete for logical replication

Hi Peter,

Thanks for reviewing the patch and sharing your feedback. Please find
my responses inline below:

On Tue, Jun 16, 2026 at 10:46 AM Peter Smith <smithpb2250@gmail.com> wrote:

Hi Ashutosh.

+1 to clarify documentation.

Some minor review comments.

======

doc/src/sgml/monitoring.sgml

(27.2.4. pg_stat_replication)

1.
+  <para>
+  For physical replication, the LSN columns in this view describe the
+  positions up to which WAL has been sent, written, flushed, and replayed
+  on the connected standby server.  For logical replication,
+  <structfield>sent_lsn</structfield> reflects the LSN up to which the
+  walsender has processed WAL records.  Such records may already have been
+  streamed to the subscriber, queued for streaming at transaction commit, or
+  skipped because they were not eligible for logical decoding.
+
+  <structfield>write_lsn</structfield>, <structfield>flush_lsn</structfield>,
+  and <structfield>replay_lsn</structfield> reflect progress reported by the
+  subscriber through replication status messages, and do not necessarily
+  mean that logical changes up to those LSNs have already been
+  received, durably stored, or made visible on the subscriber.
</para>

1a.
I'm not sure of the purpose of that blank line; it doesn't affect the
rendering in HTML.

Agreed - this had no impact on the final output and was only added for
readability purposes. I have removed it accordingly.

~

1b.
Consider splitting the text differently so there is 1 paragraph for
"Physical Replication" and 1 paragraph for "Logical Replication". So,
the same content just with different <para> markup.

SUGGESTION
<para>
For physical replication, ...
</para>
<para>
For logical replication, ...
</para>

Updated as suggested.

~~~

2.
<structfield>write_lsn</structfield> <type>pg_lsn</type>
</para>
<para>
-       Last write-ahead log location written to disk by this standby
-       server
+         For physical replication, the last write-ahead log location written
+        to disk by this standby server.  For logical replication, progress
+        reported by the subscriber through replication status messages.
</para></entry>
</row

For that 2nd sentence, do you mean /progress reported/progress is reported/

Or, here is some alternate wording:
For logical replication, progress is reported by replication status
messages received from the subscriber.

Updated as suggested. The same change has also been applied to
flush_lsn and replay_lsn where similar feedback applied.

Please find the updated patch attached and let me know for any further
comments, thanks.

--
With Regards,
Ashutosh Sharma.

Attachments:

0001-doc-clarify-pg_stat_replication-view-for-logical-rep.patchapplication/octet-stream; name=0001-doc-clarify-pg_stat_replication-view-for-logical-rep.patchDownload+38-16
#4Peter Smith
smithpb2250@gmail.com
In reply to: Ashutosh Sharma (#3)
Re: pg_stat_replication docs incomplete for logical replication

The latest patch LGTM regarding the content.

But, there were some trivial issues.

======

1.
The patch name did not change. The 2nd patch was still called 0001?

~~~

2.
+  <para>
+    The <structname>pg_stat_replication</structname> view will contain one row
+    per WAL sender process, showing statistics about replication to that
... etc.

Paragraph text is sometimes indented 1 space too many in the SGML file.
AFAIK, text normally is aligned with the "p" of <para>.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

#5Ashutosh Sharma
ashu.coek88@gmail.com
In reply to: Peter Smith (#4)
Re: pg_stat_replication docs incomplete for logical replication

Hi,

On Thu, Jun 18, 2026 at 4:52 AM Peter Smith <smithpb2250@gmail.com> wrote:

The latest patch LGTM regarding the content.

But, there were some trivial issues.

======

1.
The patch name did not change. The 2nd patch was still called 0001?

~~~

2.
+  <para>
+    The <structname>pg_stat_replication</structname> view will contain one row
+    per WAL sender process, showing statistics about replication to that
... etc.

Paragraph text is sometimes indented 1 space too many in the SGML file.
AFAIK, text normally is aligned with the "p" of <para>.

Thanks for your feedback. The attached patch addresses the alignment
issue and has been tagged as v3. The two preceding patches, though
untagged, can be considered v1 and v2 respectively.

Please have a look and let me know for any further changes.

--
With Regards,
Ashutosh Sharma.

Attachments:

t139931_5
v3-0001-doc-clarify-pg_stat_replication-view-for-logical-rep.patchapplication/octet-stream; name=v3-0001-doc-clarify-pg_stat_replication-view-for-logical-rep.patchDownload+36-14
#6Peter Smith
smithpb2250@gmail.com
In reply to: Ashutosh Sharma (#5)
Re: pg_stat_replication docs incomplete for logical replication

On Thu, Jun 18, 2026 at 4:26 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:

Hi,

On Thu, Jun 18, 2026 at 4:52 AM Peter Smith <smithpb2250@gmail.com> wrote:

The latest patch LGTM regarding the content.

But, there were some trivial issues.

======

1.
The patch name did not change. The 2nd patch was still called 0001?

~~~

2.
+  <para>
+    The <structname>pg_stat_replication</structname> view will contain one row
+    per WAL sender process, showing statistics about replication to that
... etc.

Paragraph text is sometimes indented 1 space too many in the SGML file.
AFAIK, text normally is aligned with the "p" of <para>.

Thanks for your feedback. The attached patch addresses the alignment
issue and has been tagged as v3. The two preceding patches, though
untagged, can be considered v1 and v2 respectively.

Please have a look and let me know for any further changes.

Patch v3 LGTM.

======
Kind Regards,
Peter Smith.
Fujitsu Australia