Re: Report bytes and transactions actually sent downtream

From: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Report bytes and transactions actually sent downtream
Date: 2026-03-16 13:48:05
Message-ID: CAE9k0PmNLURfRzdAXDWZ9-fG6kUjxaa0NCQ3kE8PkATFAKUq4A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Mar 16, 2026 at 4:40 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> On Mon, Mar 16, 2026 at 1:21 PM Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com> 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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ajit Awekar 2026-03-16 13:57:17 Re: [OAuth2] Infrastructure for tracking token expiry time
Previous Message Antonin Houska 2026-03-16 13:46:02 Re: Adding REPACK [concurrently]