Hi,

On Mon, Mar 16, 2026 at 4:40 PM Amit Kapila <[email protected]> wrote:
>
> On Mon, Mar 16, 2026 at 1:21 PM Ashutosh Sharma <[email protected]> wrote:
> >
> > 1) 
> > v20260316-0001-Report-downstream-sent-bytes-in-pg_stat_replication_.patch:
> >
> > This patch introduces sent_bytes to report the amount of data sent
> > downstream. It documents sent_bytes in a way that it clarifies how
> > sent_bytes differs from total_bytes, without modifying the existing
> > documentation for total_bytes or total_txns. The patch is purely
> > additive and does not alter any existing documentation.
> >
>
> *
> +        <structfield>sent_bytes</structfield><type>bigint</type>
> +       </para>
> +       <para>
> +        Amount of transaction changes sent downstream for this slot by the
> +        output plugin after applying output plugin filters, if any, and
> +        converting it into the output plugin format.
>
> BTW, this also contains changes from pgoutput_message() which could be
> non-transactional. So, saying transaction changes may not be
> appropriate.
>

I tried this based on my current understanding on this and observed
the follwoing:

\c postgres

CREATE PUBLICATION dbg_pub FOR ALL TABLES;

SELECT * FROM pg_create_logical_replication_slot('dbg_pgout', 'pgoutput');

pg_recvlogical -d postgres \
  --slot=dbg_pgout \
  --start \
  -f /tmp/dbg_pgout.bin \
  -o proto_version='1' \
  -o publication_names='dbg_pub' \
  -o messages='true'

SELECT pg_logical_emit_message(false, 'dbg', 'hello-non-tx');

SELECT slot_name, sent_txns, sent_bytes
FROM pg_stat_replication_slots
WHERE slot_name = 'dbg_pgout';

Observation: I do not see UpdateDecodingStats() being triggered for
this non-transactional message. However, if I pass the transactional
flag as true in pg_logical_emit_message(), UpdateDecodingStats() does
get called, which eventually updates the sent bytes. As a result,
querying pg_stat_replication_slots shows a non-zero value for
sent_bytes. This was verified by attaching the wal sender process for
this slot to the gdb.

Please correct me in case my understanding was wrong and I should have
checked for something else to verify this.

--
With Regards,
Ashutosh Sharma.


Reply via email to