pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedReport bytes and transactions actually sent downtream
123+ messages / 11 participants
[nested] [flat]
* Report bytes and transactions actually sent downtream
@ 2025-06-30 09:53 Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-06-30 09:53 UTC (permalink / raw)
To: pgsql-hackers
Hi All,
In a recent logical replication issue, there were multiple replication
slots involved, each using a different publication. Thus the amount of
data that was replicated through each slot was expected to be
different. However, total_bytes and total_txns were reported the same
for all the replication slots as expected. One of the slots started
lagging and we were trying to figure out whether its the WAL sender
slowing down or the consumer (in this case Debezium). The lagging
slot then showed total_txns and total_bytes lesser than other slots
giving an impression that the WAL sender is processing the data
slowly. Had pg_stat_replication_slot reported the amount of data
actually sent downstream, it would have been easier to compare it with
the amount of data received by the consumer and thus pinpoint the
bottleneck.
Here's a patch to do the same. It adds two columns
- sent_txns: The total number of transactions sent downstream.
- sent_bytes: The total number of bytes sent downstream in data messages
to pg_stat_replication_slots. sent_bytes includes only the bytes sent
as part of 'd' messages and does not include keep alive messages or
CopyDone messages for example. But those are very few and can be
ignored. If others feel that those are important to be included, we
can make that change.
Plugins may choose not to send an empty transaction downstream. It's
better to increment sent_txns counter in the plugin code when it
actually sends a BEGIN message, for example in pgoutput_send_begin()
and pg_output_begin(). This means that every plugin will need to be
modified to increment the counter for it to reported correctly.
I first thought of incrementing sent_bytes in OutputPluginWrite()
which is a central function for all logical replication message
writes. But that calls LogicalDecodingContext::write() which may
further add bytes to the message e.g. WalSndWriteData() and
LogicalOutputWrite(). So it's better to increment the counter in
implementations of LogicalDecodingContext::write(), so that we count
the exact number of bytes. These implementations are within core code
so they won't miss updating sent_bytes.
I think we should rename total_txns and total_bytes to reordered_txns
and reordered_bytes respectively, and also update the documentation
accordingly to make better sense of those numbers. But these patches
do not contain that change. If others feel the same way, I will
provide a patch with that change.
--
Best Wishes,
Ashutosh Bapat
Attachments:
0001-Report-data-sent-statistics-in-pg_stat_repl-20250630.patch (text/x-patch, 26.3K) download
From 1a385b30d6cb4ca111cbcc16ea14017c08f9a579 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH] Report data sent statistics in pg_stat_replication_slots
pg_stat_replication_slots reports the total number of transactions and bytes
added to the reorder buffer. This is the amount of WAL that is processed by the
WAL sender. This data undergoes filtering and logical decoding before sending to
the downstream. Hence the amount of WAL added to the reorder buffer does not
serve as a good metric for the amount of data sent downstream. Knowing the
amount data sent downstream is useful when debugging slowly moving logical
replication.
This patch adds two new columns to pg_stat_replication_slots:
- sent_txns: The total number of transactions sent downstream.
- sent_bytes: The total number of bytes sent downstream in data messages
Ashutosh Bapat
---
contrib/test_decoding/expected/stats.out | 54 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 12 +++--
contrib/test_decoding/t/001_repl_stats.pl | 14 ++---
contrib/test_decoding/test_decoding.c | 1 +
doc/src/sgml/monitoring.sgml | 27 ++++++++++
src/backend/catalog/system_views.sql | 2 +
src/backend/replication/logical/logical.c | 10 +++-
.../replication/logical/logicalfuncs.c | 2 +
.../replication/logical/reorderbuffer.c | 2 +
src/backend/replication/pgoutput/pgoutput.c | 1 +
src/backend/replication/walsender.c | 2 +
src/backend/utils/activity/pgstat_replslot.c | 2 +
src/backend/utils/adt/pgstatfuncs.c | 14 +++--
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 2 +
src/include/replication/reorderbuffer.h | 8 +++
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 4 +-
18 files changed, 126 insertions(+), 49 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..867a8506051 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,28 +37,34 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_txns, sent_bytes > 0 AS sent_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_txns | sent_bytes
+------------------------+------------+-------------+------------+-------------+-----------+------------
+ regression_slot_stats1 | t | t | t | t | 1 | t
+ regression_slot_stats2 | t | t | t | t | 1 | t
+ regression_slot_stats3 | t | t | t | t | 1 | t
(3 rows)
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 0 for the slot whose stats were reset since the background
+-- transactions are always skipped and not transaction, which would be sent
+-- downstream, has happened since the reset.
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
pg_stat_reset_replication_slot
--------------------------------
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_txns, sent_bytes > 0 AS sent_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_txns | sent_bytes
+------------------------+------------+-------------+------------+-------------+-----------+------------
+ regression_slot_stats1 | t | t | f | f | 0 | f
+ regression_slot_stats2 | t | t | t | t | 1 | t
+ regression_slot_stats3 | t | t | t | t | 1 | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +74,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_txns, sent_bytes > 0 AS sent_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_txns | sent_bytes
+------------------------+------------+-------------+------------+-------------+-----------+------------
+ regression_slot_stats1 | t | t | f | f | 0 | f
+ regression_slot_stats2 | t | t | f | f | 0 | f
+ regression_slot_stats3 | t | t | f | f | 0 | f
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | sent_txns | sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------+------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | sent_txns | sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------+------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..8581387d867 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_txns, sent_bytes > 0 AS sent_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 0 for the slot whose stats were reset since the background
+-- transactions are always skipped and not transaction, which would be sent
+-- downstream, has happened since the reset.
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_txns, sent_bytes > 0 AS sent_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_txns, sent_bytes > 0 AS sent_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..ba887d752eb 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,9 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ sent_txns > 0 AS sent_txn,
+ sent_bytes > 0 AS sent_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +82,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t
+regression_slot2|t|t|t|t
+regression_slot3|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +106,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t
+regression_slot2|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index bb495563200..4a7e918efbe 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -310,6 +310,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->reorder->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 4265a22d4de..e5af284df90 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1644,6 +1644,33 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for
+ this slot. This counts top-level transactions only, and is not incremented
+ for subtransactions. These transactions are subset of transctions
+ sent to the decoding plugin. Hence this count is expected to be lesser than or equal to <structfield>total_txns</structfield>.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of decoded transaction changes sent downstream for this slot. The
+ amount of WAL corresponding to the changes sent downstream is subset of
+ the total WAL sent to the decoding plugin. But the amount of data sent
+ downstream for a given decoded WAL record may not match the size of the
+ WAL record. Thus values in this column do not have strong correlation
+ with the values in <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 08f780a2e63..bcc210dd754 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,6 +1053,8 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_bytes,
s.total_txns,
s.total_bytes,
+ s.sent_txns,
+ s.sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index f1eb798f3e9..14615fa70d7 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1958,7 +1958,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1967,9 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->sentTxns,
+ rb->sentBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1977,6 +1979,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.sent_txns = rb->sentTxns;
+ repSlotStat.sent_bytes = rb->sentBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +1992,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->sentTxns = 0;
+ rb->sentBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index ca53caac2f2..f85e21b1a50 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,8 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ ctx->reorder->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index c4299c76fb1..fa4c61192e8 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -392,6 +392,8 @@ ReorderBufferAllocate(void)
buffer->streamBytes = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentTxns = 0;
+ buffer->sentBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 082b4d9d327..daafac7049c 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -589,6 +589,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->reorder->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index f2c33250e8b..f097aa92c64 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1569,6 +1569,8 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);
+ ctx->reorder->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..583ac090cdd 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,8 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(sent_txns);
+ REPLSLOT_ACC(sent_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 1c12ddbae49..4ed405c6ad5 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 12
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2129,7 +2129,11 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2154,11 +2158,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->total_txns);
values[8] = Int64GetDatum(slotent->total_bytes);
+ values[9] = Int64GetDatum(slotent->sent_txns);
+ values[10] = Int64GetDatum(slotent->sent_bytes);
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[11] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[11] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index fb4f7f50350..49990bfe42e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5675,9 +5675,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,sent_txns,sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 378f2f2c2ba..814c6024ba1 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -395,6 +395,8 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_bytes;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter sent_txns;
+ PgStat_Counter sent_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index fa0745552f8..b22e046a9ad 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -696,6 +696,14 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+
+ /*
+ * Statistics about the transactions decoded by the output plugin and sent
+ * downstream.
+ */
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..03b688f54eb 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, sent_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and sent_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 6cf828ca8d0..9fcf73152cd 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2131,9 +2131,11 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_bytes,
s.total_txns,
s.total_bytes,
+ s.sent_txns,
+ s.sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, sent_txns, sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
base-commit: 3431e3e4aa3a33e8411f15e76c284cdd4c54ca28
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-07-01 10:52 ` Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2025-07-01 10:52 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: pgsql-hackers
On Mon, Jun 30, 2025 at 3:24 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> Hi All,
> In a recent logical replication issue, there were multiple replication
> slots involved, each using a different publication. Thus the amount of
> data that was replicated through each slot was expected to be
> different. However, total_bytes and total_txns were reported the same
> for all the replication slots as expected. One of the slots started
> lagging and we were trying to figure out whether its the WAL sender
> slowing down or the consumer (in this case Debezium). The lagging
> slot then showed total_txns and total_bytes lesser than other slots
> giving an impression that the WAL sender is processing the data
> slowly. Had pg_stat_replication_slot reported the amount of data
> actually sent downstream, it would have been easier to compare it with
> the amount of data received by the consumer and thus pinpoint the
> bottleneck.
>
> Here's a patch to do the same. It adds two columns
> - sent_txns: The total number of transactions sent downstream.
> - sent_bytes: The total number of bytes sent downstream in data messages
> to pg_stat_replication_slots. sent_bytes includes only the bytes sent
> as part of 'd' messages and does not include keep alive messages or
> CopyDone messages for example. But those are very few and can be
> ignored. If others feel that those are important to be included, we
> can make that change.
>
> Plugins may choose not to send an empty transaction downstream. It's
> better to increment sent_txns counter in the plugin code when it
> actually sends a BEGIN message, for example in pgoutput_send_begin()
> and pg_output_begin(). This means that every plugin will need to be
> modified to increment the counter for it to reported correctly.
>
What if some plugin didn't implemented it or does it incorrectly?
Users will then complain that PG view is showing incorrect value.
Shouldn't the plugin specific stats be shown differently, for example,
one may be interested in how much plugin has filtered the data because
it was not published or because something like row_filter caused it
skip sending such data?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2025-07-01 14:05 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-07-01 14:05 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: pgsql-hackers
On Tue, Jul 1, 2025 at 4:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Jun 30, 2025 at 3:24 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > Hi All,
> > In a recent logical replication issue, there were multiple replication
> > slots involved, each using a different publication. Thus the amount of
> > data that was replicated through each slot was expected to be
> > different. However, total_bytes and total_txns were reported the same
> > for all the replication slots as expected. One of the slots started
> > lagging and we were trying to figure out whether its the WAL sender
> > slowing down or the consumer (in this case Debezium). The lagging
> > slot then showed total_txns and total_bytes lesser than other slots
> > giving an impression that the WAL sender is processing the data
> > slowly. Had pg_stat_replication_slot reported the amount of data
> > actually sent downstream, it would have been easier to compare it with
> > the amount of data received by the consumer and thus pinpoint the
> > bottleneck.
> >
> > Here's a patch to do the same. It adds two columns
> > - sent_txns: The total number of transactions sent downstream.
> > - sent_bytes: The total number of bytes sent downstream in data messages
> > to pg_stat_replication_slots. sent_bytes includes only the bytes sent
> > as part of 'd' messages and does not include keep alive messages or
> > CopyDone messages for example. But those are very few and can be
> > ignored. If others feel that those are important to be included, we
> > can make that change.
> >
> > Plugins may choose not to send an empty transaction downstream. It's
> > better to increment sent_txns counter in the plugin code when it
> > actually sends a BEGIN message, for example in pgoutput_send_begin()
> > and pg_output_begin(). This means that every plugin will need to be
> > modified to increment the counter for it to reported correctly.
> >
>
> What if some plugin didn't implemented it or does it incorrectly?
> Users will then complain that PG view is showing incorrect value.
That is right.
To fix the problem of plugins not implementing the counter increment
logic we could use logic similar to how we track whether
OutputPluginPrepareWrite() has been called or not. In
ReorderBufferTxn, we add a new member sent_status which would be an
enum with 3 values UNKNOWN, SENT, NOT_SENT. Initially the sent_status
= UNKNOWN. We provide a function called
plugin_sent_txn(ReorderBufferTxn txn, sent bool) which will set
sent_status = SENT when sent = true and sent_status = NOT_SENT when
sent = false. In all the end transaction callback wrappers like
commit_cb_wrapper(), prepare_cb_wrapper(), stream_abort_cb_wrapper(),
stream_commit_cb_wrapper() and stream_prepare_cb_wrapper(), if
tsent_status = UNKNOWN, we throw an error. If sent_status = SENT, we
increment sent_txns. That will catch any plugin which does not call
plugin_set_txn(). The plugin may still call plugin_sent_txn() with
sent = true when it should have called it with sent = false or vice
versa, but that's hard to monitor and control.
Additionally, we should highlight in the document that sent_txns is as
per report from the output plugin so that users know where to look
for in case they see a wrong/dubious value. I see this similar to what
we do with pg_stat_replication::reply_time which may be wrong if a
non-PG standby reports the wrong value. Documentation says "Send time
of last reply message received from standby server", so the users know
where to look for incase they spot the error.
Does that look good?
I am open to other suggestions.
> Shouldn't the plugin specific stats be shown differently, for example,
> one may be interested in how much plugin has filtered the data because
> it was not published or because something like row_filter caused it
> skip sending such data?
>
That looks useful, we could track the ReorderBufferChange's that were
not sent downstream and add their sizes to another counter
ReorderBuffer::filtered_bytes and report it in
pg_stat_replication_slots. I think we will need to devise a mechanism
similar to above by which the plugin tells core whether a change has
been filtered or not. However, that will not be a replacement for
sent_bytes, since filtered_bytes or total_bytes - filtered_bytes won't
tell us how much data was sent downstream, which is crucial to the
purpose stated in my earlier email.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-07-13 11:04 ` Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2025-07-13 11:04 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: pgsql-hackers
On Tue, Jul 1, 2025 at 7:35 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Tue, Jul 1, 2025 at 4:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Mon, Jun 30, 2025 at 3:24 PM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > > Hi All,
> > > In a recent logical replication issue, there were multiple replication
> > > slots involved, each using a different publication. Thus the amount of
> > > data that was replicated through each slot was expected to be
> > > different. However, total_bytes and total_txns were reported the same
> > > for all the replication slots as expected. One of the slots started
> > > lagging and we were trying to figure out whether its the WAL sender
> > > slowing down or the consumer (in this case Debezium). The lagging
> > > slot then showed total_txns and total_bytes lesser than other slots
> > > giving an impression that the WAL sender is processing the data
> > > slowly. Had pg_stat_replication_slot reported the amount of data
> > > actually sent downstream, it would have been easier to compare it with
> > > the amount of data received by the consumer and thus pinpoint the
> > > bottleneck.
> > >
> > > Here's a patch to do the same. It adds two columns
> > > - sent_txns: The total number of transactions sent downstream.
> > > - sent_bytes: The total number of bytes sent downstream in data messages
> > > to pg_stat_replication_slots. sent_bytes includes only the bytes sent
> > > as part of 'd' messages and does not include keep alive messages or
> > > CopyDone messages for example. But those are very few and can be
> > > ignored. If others feel that those are important to be included, we
> > > can make that change.
> > >
> > > Plugins may choose not to send an empty transaction downstream. It's
> > > better to increment sent_txns counter in the plugin code when it
> > > actually sends a BEGIN message, for example in pgoutput_send_begin()
> > > and pg_output_begin(). This means that every plugin will need to be
> > > modified to increment the counter for it to reported correctly.
> > >
> >
> > What if some plugin didn't implemented it or does it incorrectly?
> > Users will then complain that PG view is showing incorrect value.
>
> That is right.
>
> To fix the problem of plugins not implementing the counter increment
> logic we could use logic similar to how we track whether
> OutputPluginPrepareWrite() has been called or not. In
> ReorderBufferTxn, we add a new member sent_status which would be an
> enum with 3 values UNKNOWN, SENT, NOT_SENT. Initially the sent_status
> = UNKNOWN. We provide a function called
> plugin_sent_txn(ReorderBufferTxn txn, sent bool) which will set
> sent_status = SENT when sent = true and sent_status = NOT_SENT when
> sent = false. In all the end transaction callback wrappers like
> commit_cb_wrapper(), prepare_cb_wrapper(), stream_abort_cb_wrapper(),
> stream_commit_cb_wrapper() and stream_prepare_cb_wrapper(), if
> tsent_status = UNKNOWN, we throw an error.
>
I think we don't want to make it mandatory for plugins to implement
these stats, so instead of throwing ERROR, the view should show that
the plugin doesn't provide stats. How about having OutputPluginStats
similar to OutputPluginCallbacks and OutputPluginOptions members in
LogicalDecodingContext? It will have members like stats_available,
txns_sent or txns_skipped, txns_filtered, etc. I am thinking it will
be better to provide this information in a separate view like
pg_stat_plugin_stats or something like that, here we can report
slot_name, plugin_name, then the other stats we want to implement part
of OutputPluginStats.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2025-07-14 05:24 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-07-14 05:24 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: pgsql-hackers
On Sun, Jul 13, 2025 at 4:34 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Jul 1, 2025 at 7:35 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Tue, Jul 1, 2025 at 4:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > > On Mon, Jun 30, 2025 at 3:24 PM Ashutosh Bapat
> > > <ashutosh.bapat.oss@gmail.com> wrote:
> > > >
> > > > Hi All,
> > > > In a recent logical replication issue, there were multiple replication
> > > > slots involved, each using a different publication. Thus the amount of
> > > > data that was replicated through each slot was expected to be
> > > > different. However, total_bytes and total_txns were reported the same
> > > > for all the replication slots as expected. One of the slots started
> > > > lagging and we were trying to figure out whether its the WAL sender
> > > > slowing down or the consumer (in this case Debezium). The lagging
> > > > slot then showed total_txns and total_bytes lesser than other slots
> > > > giving an impression that the WAL sender is processing the data
> > > > slowly. Had pg_stat_replication_slot reported the amount of data
> > > > actually sent downstream, it would have been easier to compare it with
> > > > the amount of data received by the consumer and thus pinpoint the
> > > > bottleneck.
> > > >
> > > > Here's a patch to do the same. It adds two columns
> > > > - sent_txns: The total number of transactions sent downstream.
> > > > - sent_bytes: The total number of bytes sent downstream in data messages
> > > > to pg_stat_replication_slots. sent_bytes includes only the bytes sent
> > > > as part of 'd' messages and does not include keep alive messages or
> > > > CopyDone messages for example. But those are very few and can be
> > > > ignored. If others feel that those are important to be included, we
> > > > can make that change.
> > > >
> > > > Plugins may choose not to send an empty transaction downstream. It's
> > > > better to increment sent_txns counter in the plugin code when it
> > > > actually sends a BEGIN message, for example in pgoutput_send_begin()
> > > > and pg_output_begin(). This means that every plugin will need to be
> > > > modified to increment the counter for it to reported correctly.
> > > >
> > >
> > > What if some plugin didn't implemented it or does it incorrectly?
> > > Users will then complain that PG view is showing incorrect value.
> >
> > That is right.
> >
> > To fix the problem of plugins not implementing the counter increment
> > logic we could use logic similar to how we track whether
> > OutputPluginPrepareWrite() has been called or not. In
> > ReorderBufferTxn, we add a new member sent_status which would be an
> > enum with 3 values UNKNOWN, SENT, NOT_SENT. Initially the sent_status
> > = UNKNOWN. We provide a function called
> > plugin_sent_txn(ReorderBufferTxn txn, sent bool) which will set
> > sent_status = SENT when sent = true and sent_status = NOT_SENT when
> > sent = false. In all the end transaction callback wrappers like
> > commit_cb_wrapper(), prepare_cb_wrapper(), stream_abort_cb_wrapper(),
> > stream_commit_cb_wrapper() and stream_prepare_cb_wrapper(), if
> > tsent_status = UNKNOWN, we throw an error.
> >
>
> I think we don't want to make it mandatory for plugins to implement
> these stats, so instead of throwing ERROR, the view should show that
> the plugin doesn't provide stats. How about having OutputPluginStats
> similar to OutputPluginCallbacks and OutputPluginOptions members in
> LogicalDecodingContext? It will have members like stats_available,
> txns_sent or txns_skipped, txns_filtered, etc.
Not making mandatory looks useful. I can try your suggestion. Rather
than having stats_available as a member of OutputPluginStats, it's
better to have a NULL value for the corresponding member in
LogicalDecodingContext. We don't want an output plugin to reset
stats_available once set. Will that work?
> I am thinking it will
> be better to provide this information in a separate view like
> pg_stat_plugin_stats or something like that, here we can report
> slot_name, plugin_name, then the other stats we want to implement part
> of OutputPluginStats.
As you have previously pointed out, the view should make it explicit
that the new stats are maintained by the plugin and not core. I agree
with that intention. However, already have three views
pg_replication_slots (which has slot name and plugin name), then
pg_replication_stats which is about stats maintained by a WAL sender
or running replication and then pg_stat_replication_slots, which is
about accumulated statistics for a replication through a given
replication slot. It's already a bit hard to keep track of who's who
when debugging an issue. Adding one more view will add to confusion.
Instead of adding a new view how about
a. name the columns as plugin_sent_txns, plugin_sent_bytes,
plugin_filtered_change_bytes to make it clear that these columns are
maintained by plugin
b. report these NULL if stats_available = false OR OutputPluginStats
is not set in LogicalDecodingContext
c. Document that NULL value for these columns indicates that the
plugin is not maintaining/reporting these stats
d. adding plugin name to pg_stat_replication_slots, that will make it
easy for users to know which plugin they should look at in case of
dubious or unavailable stats
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-07-14 10:00 ` Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2025-07-14 10:00 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: pgsql-hackers
On Mon, Jul 14, 2025 at 10:55 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Sun, Jul 13, 2025 at 4:34 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> >
> > I think we don't want to make it mandatory for plugins to implement
> > these stats, so instead of throwing ERROR, the view should show that
> > the plugin doesn't provide stats. How about having OutputPluginStats
> > similar to OutputPluginCallbacks and OutputPluginOptions members in
> > LogicalDecodingContext? It will have members like stats_available,
> > txns_sent or txns_skipped, txns_filtered, etc.
>
> Not making mandatory looks useful. I can try your suggestion. Rather
> than having stats_available as a member of OutputPluginStats, it's
> better to have a NULL value for the corresponding member in
> LogicalDecodingContext. We don't want an output plugin to reset
> stats_available once set. Will that work?
>
We can try that.
> > I am thinking it will
> > be better to provide this information in a separate view like
> > pg_stat_plugin_stats or something like that, here we can report
> > slot_name, plugin_name, then the other stats we want to implement part
> > of OutputPluginStats.
>
> As you have previously pointed out, the view should make it explicit
> that the new stats are maintained by the plugin and not core. I agree
> with that intention. However, already have three views
> pg_replication_slots (which has slot name and plugin name), then
> pg_replication_stats which is about stats maintained by a WAL sender
> or running replication and then pg_stat_replication_slots, which is
> about accumulated statistics for a replication through a given
> replication slot. It's already a bit hard to keep track of who's who
> when debugging an issue. Adding one more view will add to confusion.
>
> Instead of adding a new view how about
> a. name the columns as plugin_sent_txns, plugin_sent_bytes,
> plugin_filtered_change_bytes to make it clear that these columns are
> maintained by plugin
> b. report these NULL if stats_available = false OR OutputPluginStats
> is not set in LogicalDecodingContext
> c. Document that NULL value for these columns indicates that the
> plugin is not maintaining/reporting these stats
> d. adding plugin name to pg_stat_replication_slots, that will make it
> easy for users to know which plugin they should look at in case of
> dubious or unavailable stats
>
Sounds reasonable.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2025-07-24 06:54 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-07-24 06:54 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: pgsql-hackers
Hi Amit,
On Mon, Jul 14, 2025 at 3:31 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Jul 14, 2025 at 10:55 AM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Sun, Jul 13, 2025 at 4:34 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > >
> > > I think we don't want to make it mandatory for plugins to implement
> > > these stats, so instead of throwing ERROR, the view should show that
> > > the plugin doesn't provide stats. How about having OutputPluginStats
> > > similar to OutputPluginCallbacks and OutputPluginOptions members in
> > > LogicalDecodingContext? It will have members like stats_available,
> > > txns_sent or txns_skipped, txns_filtered, etc.
> >
> > Not making mandatory looks useful. I can try your suggestion. Rather
> > than having stats_available as a member of OutputPluginStats, it's
> > better to have a NULL value for the corresponding member in
> > LogicalDecodingContext. We don't want an output plugin to reset
> > stats_available once set. Will that work?
> >
>
> We can try that.
>
> > > I am thinking it will
> > > be better to provide this information in a separate view like
> > > pg_stat_plugin_stats or something like that, here we can report
> > > slot_name, plugin_name, then the other stats we want to implement part
> > > of OutputPluginStats.
> >
> > As you have previously pointed out, the view should make it explicit
> > that the new stats are maintained by the plugin and not core. I agree
> > with that intention. However, already have three views
> > pg_replication_slots (which has slot name and plugin name), then
> > pg_replication_stats which is about stats maintained by a WAL sender
> > or running replication and then pg_stat_replication_slots, which is
> > about accumulated statistics for a replication through a given
> > replication slot. It's already a bit hard to keep track of who's who
> > when debugging an issue. Adding one more view will add to confusion.
> >
> > Instead of adding a new view how about
> > a. name the columns as plugin_sent_txns, plugin_sent_bytes,
> > plugin_filtered_change_bytes to make it clear that these columns are
> > maintained by plugin
> > b. report these NULL if stats_available = false OR OutputPluginStats
> > is not set in LogicalDecodingContext
> > c. Document that NULL value for these columns indicates that the
> > plugin is not maintaining/reporting these stats
> > d. adding plugin name to pg_stat_replication_slots, that will make it
> > easy for users to know which plugin they should look at in case of
> > dubious or unavailable stats
> >
>
> Sounds reasonable.
Here's the next patch which considers all the discussion so far. It
adds four fields to pg_stat_replication_slots.
- plugin - name of the output plugin
- plugin_filtered_bytes - reports the amount of changes filtered
out by the output plugin
- plugin_sent_txns - the amount of transactions sent downstream by
the output plugin
- plugin_sent_bytes - the amount of data sent downstream by the
outputplugin.
There are some points up for a discussion:
1. pg_stat_reset_replication_slot() zeroes out the statistics entry by
calling pgstat_reset() or pgstat_reset_of_kind() which don't know
about the contents of the entry. So
PgStat_StatReplSlotEntry::plugin_has_stats is set to false and plugin
stats are reported as NULL, instead of zero, immediately after reset.
This is the same case when the stats is queried immediately after the
statistics is initialized and before any stats are reported. We could
instead make it report
zero, if we save the plugin_has_stats and restore it after reset. But
doing that in pgstat_reset_of_kind() seems like an extra overhead + we
will need to write a function to find all replication slot entries.
Resetting the stats would be a rare event in practice. Trying to
report 0 instead of NULL in that rare case doesn't seem to be worth
the efforts and code. Given that the core code doesn't know whether a
given plugin reports stats or not, I think this behaviour is
appropriate as long as we document it. Please let me know if the
documentation in the patch is clear enough.
2. There's also a bit of asymmetry in the way sent_bytes is handled.
The code which actually sends the logical changes to the downstream is
part of the core code
but the format of the change and hence the number of bytes sent is
decided by the plugin. It's a stat related to plugin but maintained by
the core code. The patch implements it as a plugin stat (so the
corresponding column has "plugin" prefix and is also reported as NULL
upon reset etc.), but we may want to reconsider how to report and
maintain it.
3. The names of new columns have the prefix "plugin_" but the internal
variables tracking those don't for the sake of brevity. If you prefer
to have the same prefix for the internal variables, I can change that.
I think I have covered all the cases where filteredbytes should be
incremented, but please let me know if I have missed any.
--
Best Wishes,
Ashutosh Bapat
Attachments:
0001-Report-output-plugin-statistics-in-pg_stat_-20250724.patch (text/x-patch, 39.8K) download
From 0bdaca3d1bb95cb834d45137eddaaa58fe1646b9 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH] Report output plugin statistics in pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 15 ++--
contrib/test_decoding/t/001_repl_stats.pl | 18 +++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 27 +++++++
doc/src/sgml/monitoring.sgml | 58 ++++++++++++++
src/backend/catalog/system_views.sql | 4 +
src/backend/replication/logical/logical.c | 24 +++++-
.../replication/logical/logicalfuncs.c | 7 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 7 ++
src/backend/utils/adt/pgstatfuncs.c | 26 ++++++-
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 4 +
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
src/test/regress/expected/rules.out | 6 +-
src/tools/pgindent/typedefs.list | 1 +
22 files changed, 275 insertions(+), 65 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..d19fe6a1c61 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Filtered
+-- bytes would be set only when there's a change that was passed to the plugin
+-- but was filtered out. Depending upon the background transactions, filtered
+-- bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+------------+-------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+------------+-------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+------------+-------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..1077cea5855 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,21 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Filtered
+-- bytes would be set only when there's a change that was passed to the plugin
+-- but was filtered out. Depending upon the background transactions, filtered
+-- bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +51,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..76dd86fc420 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index bb495563200..a77309ce438 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index 593f784b69d..a84c2f00195 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -774,6 +774,33 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data
+ sent downstream by the output plugin.
+ <function>OutputPluginWrite</function> is expected to update this counter
+ if <literal>ctx->stats</literal> is initialized by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes in bytes that are
+ filtered out by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 823afe1b30b..d8efae0cfd2 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1545,6 +1545,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1644,6 +1655,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is handed over to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transctions sent to
+ the decoding plugin. Hence this count is expected to be lesser than or
+ equal to <structfield>total_txns</structfield>. The count is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The count is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index f6eca09ee15..930e6309d71 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,6 +1053,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1061,6 +1062,9 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_bytes,
s.total_txns,
s.total_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 7e363a7c05b..9d77e57af65 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,13 +1952,14 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1968,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1977,6 +1982,15 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.sent_txns = stats->sentTxns;
+ repSlotStat.sent_bytes = stats->sentBytes;
+ repSlotStat.filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +2002,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index ca53caac2f2..00a53d1857e 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 5febd154b6b..9edaece0282 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4421,7 +4420,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index f4c977262c5..4ffcce0eb23 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -450,6 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
ALLOCSET_SMALL_SIZES);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -591,6 +592,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1469,7 +1471,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1487,15 +1492,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1505,6 +1519,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1560,7 +1575,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1688,6 +1706,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index ee911394a23..59dda2c2bb7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1572,6 +1572,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..ed055324a99 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,13 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(sent_txns);
+ REPLSLOT_ACC(sent_bytes);
+ REPLSLOT_ACC(filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 1c12ddbae49..2add51e8f3a 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2129,7 +2129,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2154,11 +2160,23 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->total_txns);
values[8] = Int64GetDatum(slotent->total_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[9] = Int64GetDatum(slotent->filtered_bytes);
+ values[10] = Int64GetDatum(slotent->sent_txns);
+ values[11] = Int64GetDatum(slotent->sent_bytes);
+ }
+ else
+ {
+ nulls[9] = true;
+ nulls[10] = true;
+ nulls[11] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[12] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 3ee8fed7e53..267406ae906 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5675,9 +5675,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 202bd2d5ace..9779e5dc5a8 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -395,6 +395,10 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_bytes;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter sent_txns;
+ PgStat_Counter sent_bytes;
+ PgStat_Counter filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index fa0745552f8..3ea2d9885b6 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -715,6 +715,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..b04a0d9f8db 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index dce8c672b40..acf3c4e4294 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2127,6 +2127,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2135,9 +2136,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_bytes,
s.total_txns,
s.total_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index a8656419cb6..45da79caead 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1830,6 +1830,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: df335618ed87eecdef44a95e453e345a55a14ad8
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-08-27 13:43 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-08-27 13:43 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Thu, Jul 24, 2025 at 12:24:26PM +0530, Ashutosh Bapat wrote:
> Here's the next patch which considers all the discussion so far. It
> adds four fields to pg_stat_replication_slots.
> - plugin - name of the output plugin
Is this one needed? (we could get it with a join on pg_replication_slots)
> - plugin_filtered_bytes - reports the amount of changes filtered
> out by the output plugin
> - plugin_sent_txns - the amount of transactions sent downstream by
> the output plugin
> - plugin_sent_bytes - the amount of data sent downstream by the
> outputplugin.
>
> There are some points up for a discussion:
> 1. pg_stat_reset_replication_slot() zeroes out the statistics entry by
> calling pgstat_reset() or pgstat_reset_of_kind() which don't know
> about the contents of the entry. So
> PgStat_StatReplSlotEntry::plugin_has_stats is set to false and plugin
> stats are reported as NULL, instead of zero, immediately after reset.
> This is the same case when the stats is queried immediately after the
> statistics is initialized and before any stats are reported. We could
> instead make it report
> zero, if we save the plugin_has_stats and restore it after reset. But
> doing that in pgstat_reset_of_kind() seems like an extra overhead + we
> will need to write a function to find all replication slot entries.
Could we store plugin_has_stats in ReplicationSlotPersistentData instead? That
way it would not be reset. We would need to access ReplicationSlotPersistentData
in pg_stat_get_replication_slot though.
Also would that make sense to expose plugin_has_stats in pg_replication_slots?
> 2. There's also a bit of asymmetry in the way sent_bytes is handled.
> The code which actually sends the logical changes to the downstream is
> part of the core code
> but the format of the change and hence the number of bytes sent is
> decided by the plugin. It's a stat related to plugin but maintained by
> the core code. The patch implements it as a plugin stat (so the
> corresponding column has "plugin" prefix
The way it is done makes sense to me.
> 3. The names of new columns have the prefix "plugin_" but the internal
> variables tracking those don't for the sake of brevity. If you prefer
> to have the same prefix for the internal variables, I can change that.
Just my taste: I do prefer when they match.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-18 05:21 ` shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-09-18 05:21 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
On Wed, Aug 27, 2025 at 7:14 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Thu, Jul 24, 2025 at 12:24:26PM +0530, Ashutosh Bapat wrote:
> > Here's the next patch which considers all the discussion so far. It
> > adds four fields to pg_stat_replication_slots.
> > - plugin - name of the output plugin
>
> Is this one needed? (we could get it with a join on pg_replication_slots)
>
In my opinion, when there are other plugin_* fields present, including
the plugin name directly here seems like a better approach. So, +1 for
the plugin field.
> > - plugin_filtered_bytes - reports the amount of changes filtered
> > out by the output plugin
> > - plugin_sent_txns - the amount of transactions sent downstream by
> > the output plugin
> > - plugin_sent_bytes - the amount of data sent downstream by the
> > outputplugin.
> >
> > There are some points up for a discussion:
> > 1. pg_stat_reset_replication_slot() zeroes out the statistics entry by
> > calling pgstat_reset() or pgstat_reset_of_kind() which don't know
> > about the contents of the entry. So
> > PgStat_StatReplSlotEntry::plugin_has_stats is set to false and plugin
> > stats are reported as NULL, instead of zero, immediately after reset.
> > This is the same case when the stats is queried immediately after the
> > statistics is initialized and before any stats are reported. We could
> > instead make it report
> > zero, if we save the plugin_has_stats and restore it after reset. But
> > doing that in pgstat_reset_of_kind() seems like an extra overhead + we
> > will need to write a function to find all replication slot entries.
I tried to think of an approach where we can differentiate between the
cases 'not initialized' and 'reset' ones with the values. Say instead
of plugin_has_stats, if we have plugin_stats_status, then we can
maintain status like -1(not initialized), 0(reset). But this too will
complicate the code further. Personally, I’m okay with NULL values
appearing even after a reset, especially since the documentation
explains this clearly.
>
> > 2. There's also a bit of asymmetry in the way sent_bytes is handled.
> > The code which actually sends the logical changes to the downstream is
> > part of the core code
> > but the format of the change and hence the number of bytes sent is
> > decided by the plugin. It's a stat related to plugin but maintained by
> > the core code. The patch implements it as a plugin stat (so the
> > corresponding column has "plugin" prefix
>
> The way it is done makes sense to me.
>
> > 3. The names of new columns have the prefix "plugin_" but the internal
> > variables tracking those don't for the sake of brevity. If you prefer
> > to have the same prefix for the internal variables, I can change that.
>
I am okay either way.
Few comments:
1)
postgres=# select slot_name,
total_bytes,plugin_filtered_bytes,plugin_sent_bytes from
pg_stat_replication_slots order by slot_name;
slot_name | total_bytes | plugin_filtered_bytes | plugin_sent_bytes
-----------+-------------+-----------------------+-------------------
slot1 | 800636 | 793188 | 211
sub1 | 401496 | 132712 | 84041
sub2 | 401496 | 396184 | 674
sub3 | 401496 | 145912 | 79959
(4 rows)
Currently it looks quite confusing. 'total_bytes' gives a sense that
it has to be a sum of filtered and sent. But they are no way like
that. In the thread earlier there was a proposal to change the name to
reordered_txns, reordered_bytes. That looks better to me. It will give
clarity without even someone digging into docs.
2)
Tried to verify all filtered data tests, seems to work well. Also I
tried tracking the usage of OutputPluginWrite() to see if there is any
other place where data needs to be considered as filtered-data.
Encountered this:
send_relation_and_attrs has:
if (!logicalrep_should_publish_column(att, columns,
include_gencols_type))
continue;
if (att->atttypid < FirstGenbkiObjectId)
continue;
But I don't think it needs to be considered as filtered data. This is
mostly schema related info. But I wanted to confirm once. Thoughts?
3)
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Filtered
+-- bytes would be set only when there's a change that was passed to the plugin
+-- but was filtered out. Depending upon the background transactions, filtered
+-- bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS
spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS
total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes,
plugin_filtered_bytes >= 0 AS filtered_bytes FROM
pg_stat_replication_slots ORDER BY slot_name;
In comment either we can say plugin_sent_txns instead of sent_txns or
in the query we can fetch plugin_sent_txns AS sent_txns, so that we
can relate comment and query.
4)
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data
+ sent downstream by the output plugin.
+ <function>OutputPluginWrite</function> is expected to update this counter
+ if <literal>ctx->stats</literal> is initialized by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes in bytes that are
+ filtered out by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find
the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
Either we can mention units as 'bytes' for both filteredBytes and
sentBytes or for none. Currently filteredBytes says 'in bytes' while
sentBytes does not.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-09-18 10:24 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-18 10:24 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
Hi Shveta, Bertrand,
Replying to both of your review comments together.
On Thu, Sep 18, 2025 at 10:52 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Wed, Aug 27, 2025 at 7:14 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > Hi,
> >
> > On Thu, Jul 24, 2025 at 12:24:26PM +0530, Ashutosh Bapat wrote:
> > > Here's the next patch which considers all the discussion so far. It
> > > adds four fields to pg_stat_replication_slots.
> > > - plugin - name of the output plugin
> >
> > Is this one needed? (we could get it with a join on pg_replication_slots)
> >
>
> In my opinion, when there are other plugin_* fields present, including
> the plugin name directly here seems like a better approach. So, +1 for
> the plugin field.
Yeah. I think so too.
>
> > > - plugin_filtered_bytes - reports the amount of changes filtered
> > > out by the output plugin
> > > - plugin_sent_txns - the amount of transactions sent downstream by
> > > the output plugin
> > > - plugin_sent_bytes - the amount of data sent downstream by the
> > > outputplugin.
> > >
> > > There are some points up for a discussion:
> > > 1. pg_stat_reset_replication_slot() zeroes out the statistics entry by
> > > calling pgstat_reset() or pgstat_reset_of_kind() which don't know
> > > about the contents of the entry. So
> > > PgStat_StatReplSlotEntry::plugin_has_stats is set to false and plugin
> > > stats are reported as NULL, instead of zero, immediately after reset.
> > > This is the same case when the stats is queried immediately after the
> > > statistics is initialized and before any stats are reported. We could
> > > instead make it report
> > > zero, if we save the plugin_has_stats and restore it after reset. But
> > > doing that in pgstat_reset_of_kind() seems like an extra overhead + we
> > > will need to write a function to find all replication slot entries.
>
> I tried to think of an approach where we can differentiate between the
> cases 'not initialized' and 'reset' ones with the values. Say instead
> of plugin_has_stats, if we have plugin_stats_status, then we can
> maintain status like -1(not initialized), 0(reset). But this too will
> complicate the code further. Personally, I’m okay with NULL values
> appearing even after a reset, especially since the documentation
> explains this clearly.
Ok. Great.
>
> > Could we store plugin_has_stats in ReplicationSlotPersistentData instead? That
> > way it would not be reset. We would need to access ReplicationSlotPersistentData
> > in pg_stat_get_replication_slot though.
>
> > Also would that make sense to expose plugin_has_stats in pg_replication_slots?
>
A plugin may change its decision to support the stats across versions,
we won't be able to tell when it changes that decision and thus
reflect it accurately in ReplicationSlotPersistentData. Doing it in
startup gives the opportunity to the plugin to change it as often as
it wants OR even based on some plugin specific configurations. Further
ReplicationSlotPersistentData is maintained by the core. It will not
be a good place to store something plugin specific.
> >
> > > 2. There's also a bit of asymmetry in the way sent_bytes is handled.
> > > The code which actually sends the logical changes to the downstream is
> > > part of the core code
> > > but the format of the change and hence the number of bytes sent is
> > > decided by the plugin. It's a stat related to plugin but maintained by
> > > the core code. The patch implements it as a plugin stat (so the
> > > corresponding column has "plugin" prefix
> >
> > The way it is done makes sense to me.
Great.
> >
> > > 3. The names of new columns have the prefix "plugin_" but the internal
> > > variables tracking those don't for the sake of brevity. If you prefer
> > > to have the same prefix for the internal variables, I can change that.
> >
>
> I am okay either way.
>
> > Just my taste: I do prefer when they match.
I don't see a strong preference to change what's there in the patch.
Let's wait for more reviews.
>
> Few comments:
>
> 1)
> postgres=# select slot_name,
> total_bytes,plugin_filtered_bytes,plugin_sent_bytes from
> pg_stat_replication_slots order by slot_name;
> slot_name | total_bytes | plugin_filtered_bytes | plugin_sent_bytes
> -----------+-------------+-----------------------+-------------------
> slot1 | 800636 | 793188 | 211
> sub1 | 401496 | 132712 | 84041
> sub2 | 401496 | 396184 | 674
> sub3 | 401496 | 145912 | 79959
> (4 rows)
>
> Currently it looks quite confusing. 'total_bytes' gives a sense that
> it has to be a sum of filtered and sent. But they are no way like
> that. In the thread earlier there was a proposal to change the name to
> reordered_txns, reordered_bytes. That looks better to me. It will give
> clarity without even someone digging into docs.
I also agree with that. But that will break backward compatibility. Do
you think other columns like spill_* and stream_* should also be
renamed with the prefix "reordered"?
>
> 2)
> Tried to verify all filtered data tests, seems to work well. Also I
> tried tracking the usage of OutputPluginWrite() to see if there is any
> other place where data needs to be considered as filtered-data.
> Encountered this:
>
> send_relation_and_attrs has:
> if (!logicalrep_should_publish_column(att, columns,
>
> include_gencols_type))
> continue;
> if (att->atttypid < FirstGenbkiObjectId)
> continue;
>
> But I don't think it needs to be considered as filtered data. This is
> mostly schema related info. But I wanted to confirm once. Thoughts?
Yeah. It's part of metadata which in turn is sent only when needed.
It's not part of, say, transaction changes. So it can't be considered
as filtering.
>
> 3)
> +-- total_txns may vary based on the background activity but sent_txns should
> +-- always be 1 since the background transactions are always skipped. Filtered
> +-- bytes would be set only when there's a change that was passed to the plugin
> +-- but was filtered out. Depending upon the background transactions, filtered
> +-- bytes may or may not be zero.
> +SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS
> spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS
> total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes,
> plugin_filtered_bytes >= 0 AS filtered_bytes FROM
> pg_stat_replication_slots ORDER BY slot_name;
>
> In comment either we can say plugin_sent_txns instead of sent_txns or
> in the query we can fetch plugin_sent_txns AS sent_txns, so that we
> can relate comment and query.
>
Used plugin_sent_txns in the comment as well as query.
>
> 4)
> + <literal>sentTxns</literal> is the number of transactions sent downstream
> + by the output plugin. <literal>sentBytes</literal> is the amount of data
> + sent downstream by the output plugin.
> + <function>OutputPluginWrite</function> is expected to update this counter
> + if <literal>ctx->stats</literal> is initialized by the output plugin.
> + <literal>filteredBytes</literal> is the size of changes in bytes that are
> + filtered out by the output plugin. Function
> + <literal>ReorderBufferChangeSize</literal> may be used to find
> the size of
> + filtered <literal>ReorderBufferChange</literal>.
> + </para>
>
> Either we can mention units as 'bytes' for both filteredBytes and
> sentBytes or for none. Currently filteredBytes says 'in bytes' while
> sentBytes does not.
Used 'in bytes' in both the places.
Thanks for your review. I will include these changes in the next set of patches.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-19 06:18 ` shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-09-19 06:18 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>; shveta malik <shveta.malik@gmail.com>
On Thu, Sep 18, 2025 at 3:54 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
>
> >
> > Few comments:
> >
> > 1)
> > postgres=# select slot_name,
> > total_bytes,plugin_filtered_bytes,plugin_sent_bytes from
> > pg_stat_replication_slots order by slot_name;
> > slot_name | total_bytes | plugin_filtered_bytes | plugin_sent_bytes
> > -----------+-------------+-----------------------+-------------------
> > slot1 | 800636 | 793188 | 211
> > sub1 | 401496 | 132712 | 84041
> > sub2 | 401496 | 396184 | 674
> > sub3 | 401496 | 145912 | 79959
> > (4 rows)
> >
> > Currently it looks quite confusing. 'total_bytes' gives a sense that
> > it has to be a sum of filtered and sent. But they are no way like
> > that. In the thread earlier there was a proposal to change the name to
> > reordered_txns, reordered_bytes. That looks better to me. It will give
> > clarity without even someone digging into docs.
>
> I also agree with that. But that will break backward compatibility.
Yes, that it will do.
> Do
> you think other columns like spill_* and stream_* should also be
> renamed with the prefix "reordered"?
>
Okay, I see that all fields in pg_stat_replication_slots are related
to the ReorderBuffer. On reconsideration, I’m unsure whether it's
appropriate to prefix all of them with reorderd_. For example,
renaming spill_bytes and stream_bytes to reordered_spill_bytes and
reordered_stream_bytes. These names start to feel overly long, and I
also noticed that ReorderBuffer isn’t clearly defined anywhere in the
documentation (or at least I couldn’t find it), even though the term
'reorder buffer' does appear in a few places.
As an example, see ReorderBufferRead, ReorderBufferWrite wait-types
at [1]. Also in plugin-doc [2], we use 'ReorderBufferTXN'. And now, we
are adding: ReorderBufferChangeSize, ReorderBufferChange
This gives me a feeling, will it be better to let
pg_stat_replication_slots as is and add a brief ReorderBuffer section
under Logical Decoding concepts [3] just before Output Plugins. And
then, pg_stat_replication_slots can refer to that section, clarifying
that the bytes, counts, and txn fields pertain to ReorderBuffer
(without changing any of the fields).
And then to define plugin related data, we can have a new view, say
pg_stat_plugin_stats (as Amit suggested earlier) or
pg_stat_replication_plugins. I understand that adding a new view might
not be desirable, but it provides better clarity without requiring
changes to the existing fields in pg_stat_replication_slots. I also
strongly feel that to properly tie all this information together, a
brief definition of the ReorderBuffer is needed. Other pages that
reference this term can then point to that section. Thoughts?
[1]: https://www.postgresql.org/docs/17/monitoring-stats.html#WAIT-EVENT-IO-TABLE
[2]: https://www.postgresql.org/docs/17/logicaldecoding-output-plugin.html
[3]: https://www.postgresql.org/docs/17/logicaldecoding-explanation.html#LOGICALDECODING-EXPLANATION
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-09-19 14:41 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-22 05:14 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 3 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-19 14:41 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
On Fri, Sep 19, 2025 at 11:48 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Thu, Sep 18, 2025 at 3:54 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> >
> > >
> > > Few comments:
> > >
> > > 1)
> > > postgres=# select slot_name,
> > > total_bytes,plugin_filtered_bytes,plugin_sent_bytes from
> > > pg_stat_replication_slots order by slot_name;
> > > slot_name | total_bytes | plugin_filtered_bytes | plugin_sent_bytes
> > > -----------+-------------+-----------------------+-------------------
> > > slot1 | 800636 | 793188 | 211
> > > sub1 | 401496 | 132712 | 84041
> > > sub2 | 401496 | 396184 | 674
> > > sub3 | 401496 | 145912 | 79959
> > > (4 rows)
> > >
> > > Currently it looks quite confusing. 'total_bytes' gives a sense that
> > > it has to be a sum of filtered and sent. But they are no way like
> > > that. In the thread earlier there was a proposal to change the name to
> > > reordered_txns, reordered_bytes. That looks better to me. It will give
> > > clarity without even someone digging into docs.
> >
> > I also agree with that. But that will break backward compatibility.
>
> Yes, that it will do.
>
> > Do
> > you think other columns like spill_* and stream_* should also be
> > renamed with the prefix "reordered"?
> >
>
> Okay, I see that all fields in pg_stat_replication_slots are related
> to the ReorderBuffer. On reconsideration, I’m unsure whether it's
> appropriate to prefix all of them with reorderd_. For example,
> renaming spill_bytes and stream_bytes to reordered_spill_bytes and
> reordered_stream_bytes. These names start to feel overly long, and I
> also noticed that ReorderBuffer isn’t clearly defined anywhere in the
> documentation (or at least I couldn’t find it), even though the term
> 'reorder buffer' does appear in a few places.
>
> As an example, see ReorderBufferRead, ReorderBufferWrite wait-types
> at [1]. Also in plugin-doc [2], we use 'ReorderBufferTXN'. And now, we
> are adding: ReorderBufferChangeSize, ReorderBufferChange
>
> This gives me a feeling, will it be better to let
> pg_stat_replication_slots as is and add a brief ReorderBuffer section
> under Logical Decoding concepts [3] just before Output Plugins. And
> then, pg_stat_replication_slots can refer to that section, clarifying
> that the bytes, counts, and txn fields pertain to ReorderBuffer
> (without changing any of the fields).
>
> And then to define plugin related data, we can have a new view, say
> pg_stat_plugin_stats (as Amit suggested earlier) or
> pg_stat_replication_plugins. I understand that adding a new view might
> not be desirable, but it provides better clarity without requiring
> changes to the existing fields in pg_stat_replication_slots. I also
> strongly feel that to properly tie all this information together, a
> brief definition of the ReorderBuffer is needed. Other pages that
> reference this term can then point to that section. Thoughts?
Even if we keep two views, when they are joined, users will still get
confused by total_* names. So it's not solving the underlying problem.
Andres had raised the point about renaming total_* fields with me
off-list earlier. He suggested names total_wal_bytes, and
total_wal_txns in an off list discussion today. I think those convey
the true meaning - that these are txns and bytes that come from WAL.
Used those in the attached patches. Prefix reordered would give away
lower level details, so I didn't use it.
I agree that it would be good to mention ReorderBuffer in the logical
decoding concepts section since it mentions structures ReorderBuffer*.
But that would be a separate patch since we aren't using "reordered"
in the names of the fields.
0001 is the previous patch
0002 changes addressing your and Bertrand's comments.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
0001-Report-output-plugin-statistics-in-pg_stat_-20250919.patch (text/x-patch, 39.8K) download
From 9d80a42c1932acff63357148a830df7ada8dfaca Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH 1/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 15 ++--
contrib/test_decoding/t/001_repl_stats.pl | 18 +++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 27 +++++++
doc/src/sgml/monitoring.sgml | 58 ++++++++++++++
src/backend/catalog/system_views.sql | 4 +
src/backend/replication/logical/logical.c | 24 +++++-
.../replication/logical/logicalfuncs.c | 7 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 7 ++
src/backend/utils/adt/pgstatfuncs.c | 26 ++++++-
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 4 +
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
src/test/regress/expected/rules.out | 6 +-
src/tools/pgindent/typedefs.list | 1 +
22 files changed, 275 insertions(+), 65 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..d19fe6a1c61 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Filtered
+-- bytes would be set only when there's a change that was passed to the plugin
+-- but was filtered out. Depending upon the background transactions, filtered
+-- bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+------------+-------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+------------+-------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+------------+-------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..1077cea5855 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,21 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Filtered
+-- bytes would be set only when there's a change that was passed to the plugin
+-- but was filtered out. Depending upon the background transactions, filtered
+-- bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +51,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..76dd86fc420 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index f671a7d4b31..ea5c527644b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..8ac10cda90c 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,33 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data
+ sent downstream by the output plugin.
+ <function>OutputPluginWrite</function> is expected to update this counter
+ if <literal>ctx->stats</literal> is initialized by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes in bytes that are
+ filtered out by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 3f4a27a736e..e121f55c9c2 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1545,6 +1545,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1644,6 +1655,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is handed over to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transctions sent to
+ the decoding plugin. Hence this count is expected to be lesser than or
+ equal to <structfield>total_txns</structfield>. The count is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The count is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index c77fa0234bb..d38c21150b0 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,6 +1053,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1061,6 +1062,9 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_bytes,
s.total_txns,
s.total_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index c68c0481f42..b26ac29e32f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,13 +1952,14 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1968,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1977,6 +1982,15 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.sent_txns = stats->sentTxns;
+ repSlotStat.sent_bytes = stats->sentBytes;
+ repSlotStat.filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +2002,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..788967e2ab1 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 4736f993c37..12579dff2c1 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4436,7 +4435,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 80540c017bd..339babbeb56 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -450,6 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
ALLOCSET_SMALL_SIZES);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -591,6 +592,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1469,7 +1471,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1487,15 +1492,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1505,6 +1519,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1560,7 +1575,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1688,6 +1706,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 59822f22b8d..d9217ce49aa 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..ed055324a99 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,13 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(sent_txns);
+ REPLSLOT_ACC(sent_bytes);
+ REPLSLOT_ACC(filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index c756c2bebaa..796dacddcfb 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2129,7 +2129,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2154,11 +2160,23 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->total_txns);
values[8] = Int64GetDatum(slotent->total_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[9] = Int64GetDatum(slotent->filtered_bytes);
+ values[10] = Int64GetDatum(slotent->sent_txns);
+ values[11] = Int64GetDatum(slotent->sent_bytes);
+ }
+ else
+ {
+ nulls[9] = true;
+ nulls[10] = true;
+ nulls[11] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[12] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 01eba3b5a19..7519941bcf3 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5687,9 +5687,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index f402b17295c..87afeaed8a5 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -395,6 +395,10 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_bytes;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter sent_txns;
+ PgStat_Counter sent_bytes;
+ PgStat_Counter filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index fa0745552f8..3ea2d9885b6 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -715,6 +715,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..b04a0d9f8db 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 35e8aad7701..2a048af3569 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2132,6 +2132,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2140,9 +2141,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_bytes,
s.total_txns,
s.total_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e90af5b2ad3..8f6af48b04a 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1830,6 +1830,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 18cdf5932a279a2c035d44460e1e0cbb659471f2
--
2.34.1
0002-Address-review-comments-20250919.patch (text/x-patch, 22.5K) download
From e2500f1c610d2f73b53e353b98856a90db4cc452 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Thu, 18 Sep 2025 15:55:01 +0530
Subject: [PATCH 2/2] Address review comments
Among others rename total_txns and total_bytes to total_wal_txns and
total_wal_bytes respectively.
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
---
contrib/test_decoding/expected/stats.out | 58 +++++++++++------------
contrib/test_decoding/sql/stats.sql | 17 +++----
contrib/test_decoding/t/001_repl_stats.pl | 6 +--
doc/src/sgml/logicaldecoding.sgml | 6 +--
doc/src/sgml/monitoring.sgml | 18 +++----
src/backend/catalog/system_views.sql | 4 +-
src/backend/utils/adt/pgstatfuncs.c | 4 +-
src/include/catalog/pg_proc.dat | 2 +-
src/test/regress/expected/rules.out | 6 +--
9 files changed, 61 insertions(+), 60 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index d19fe6a1c61..4834b3460a6 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,17 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
--- total_txns may vary based on the background activity but sent_txns should
--- always be 1 since the background transactions are always skipped. Filtered
--- bytes would be set only when there's a change that was passed to the plugin
--- but was filtered out. Depending upon the background transactions, filtered
--- bytes may or may not be zero.
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
-------------------------+------------+-------------+------------+-------------+------------------+------------+----------------
- regression_slot_stats1 | t | t | t | t | 1 | t | t
- regression_slot_stats2 | t | t | t | t | 1 | t | t
- regression_slot_stats3 | t | t | t | t | 1 | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -58,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
-------------------------+------------+-------------+------------+-------------+------------------+------------+----------------
- regression_slot_stats1 | t | t | f | f | | |
- regression_slot_stats2 | t | t | t | t | 1 | t | t
- regression_slot_stats3 | t | t | t | t | 1 | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -73,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
-------------------------+------------+-------------+------------+-------------+------------------+-------------------+-----------------------
- regression_slot_stats1 | t | t | f | f | | |
- regression_slot_stats2 | t | t | f | f | | |
- regression_slot_stats3 | t | t | f | f | | |
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------------------+------------------+-------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-----------------------+------------------+-------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 1077cea5855..99f513902d3 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,21 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
--- total_txns may vary based on the background activity but sent_txns should
--- always be 1 since the background transactions are always skipped. Filtered
--- bytes would be set only when there's a change that was passed to the plugin
--- but was filtered out. Depending upon the background transactions, filtered
--- bytes may or may not be zero.
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 76dd86fc420..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -28,8 +28,8 @@ sub test_slot_stats
# guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes,
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
plugin_sent_txns > 0 AS sent_txn,
plugin_sent_bytes > 0 AS sent_bytes,
plugin_filtered_bytes >= 0 AS filtered_bytes
@@ -71,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index 8ac10cda90c..3952f68e806 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -956,11 +956,11 @@ typedef struct OutputPluginStats
} OutputPluginStats;
</programlisting>
<literal>sentTxns</literal> is the number of transactions sent downstream
- by the output plugin. <literal>sentBytes</literal> is the amount of data
+ by the output plugin. <literal>sentBytes</literal> is the amount of data, in bytes,
sent downstream by the output plugin.
- <function>OutputPluginWrite</function> is expected to update this counter
+ <function>OutputPluginWrite</function> will update this counter
if <literal>ctx->stats</literal> is initialized by the output plugin.
- <literal>filteredBytes</literal> is the size of changes in bytes that are
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that are
filtered out by the output plugin. Function
<literal>ReorderBufferChangeSize</literal> may be used to find the size of
filtered <literal>ReorderBufferChange</literal>.
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index e121f55c9c2..fbe03ffd670 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1633,19 +1633,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1660,9 +1660,9 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
</para>
<para>
- Amount of changes, from <structfield>total_bytes</structfield>, filtered
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
out by the output plugin and not sent downstream. Please note that it
- does not include the changes filtered before a change is handed over to
+ does not include the changes filtered before a change is sent to
the output plugin, e.g. the changes filtered by origin. The count is
maintained by the output plugin mentioned in
<structfield>plugin</structfield>. It is NULL when statistics is not
@@ -1680,7 +1680,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
counts top-level transactions only, and is not incremented for
subtransactions. These transactions are subset of transctions sent to
the decoding plugin. Hence this count is expected to be lesser than or
- equal to <structfield>total_txns</structfield>. The count is maintained
+ equal to <structfield>total_wal_txns</structfield>. The count is maintained
by the output plugin mentioned in <structfield>plugin</structfield>. It
is NULL when statistics is not initialized or immediately after a reset or
when not maintained by the output plugin.
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index d38c21150b0..9e8e32b5849 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1060,8 +1060,8 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
s.plugin_filtered_bytes,
s.plugin_sent_txns,
s.plugin_sent_bytes,
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 796dacddcfb..15bafe63b24 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2125,9 +2125,9 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_bytes",
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
INT8OID, -1, 0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 7519941bcf3..9e4f6620214 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5689,7 +5689,7 @@
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 2a048af3569..2a401552a7a 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2139,14 +2139,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
s.plugin_filtered_bytes,
s.plugin_sent_txns,
s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-22 05:14 ` shveta malik <shveta.malik@gmail.com>
2025-09-23 10:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-09-22 05:14 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>; shveta malik <shveta.malik@gmail.com>
On Fri, Sep 19, 2025 at 8:11 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Fri, Sep 19, 2025 at 11:48 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > On Thu, Sep 18, 2025 at 3:54 PM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > >
> > > >
> > > > Few comments:
> > > >
> > > > 1)
> > > > postgres=# select slot_name,
> > > > total_bytes,plugin_filtered_bytes,plugin_sent_bytes from
> > > > pg_stat_replication_slots order by slot_name;
> > > > slot_name | total_bytes | plugin_filtered_bytes | plugin_sent_bytes
> > > > -----------+-------------+-----------------------+-------------------
> > > > slot1 | 800636 | 793188 | 211
> > > > sub1 | 401496 | 132712 | 84041
> > > > sub2 | 401496 | 396184 | 674
> > > > sub3 | 401496 | 145912 | 79959
> > > > (4 rows)
> > > >
> > > > Currently it looks quite confusing. 'total_bytes' gives a sense that
> > > > it has to be a sum of filtered and sent. But they are no way like
> > > > that. In the thread earlier there was a proposal to change the name to
> > > > reordered_txns, reordered_bytes. That looks better to me. It will give
> > > > clarity without even someone digging into docs.
> > >
> > > I also agree with that. But that will break backward compatibility.
> >
> > Yes, that it will do.
> >
> > > Do
> > > you think other columns like spill_* and stream_* should also be
> > > renamed with the prefix "reordered"?
> > >
> >
> > Okay, I see that all fields in pg_stat_replication_slots are related
> > to the ReorderBuffer. On reconsideration, I’m unsure whether it's
> > appropriate to prefix all of them with reorderd_. For example,
> > renaming spill_bytes and stream_bytes to reordered_spill_bytes and
> > reordered_stream_bytes. These names start to feel overly long, and I
> > also noticed that ReorderBuffer isn’t clearly defined anywhere in the
> > documentation (or at least I couldn’t find it), even though the term
> > 'reorder buffer' does appear in a few places.
> >
> > As an example, see ReorderBufferRead, ReorderBufferWrite wait-types
> > at [1]. Also in plugin-doc [2], we use 'ReorderBufferTXN'. And now, we
> > are adding: ReorderBufferChangeSize, ReorderBufferChange
> >
> > This gives me a feeling, will it be better to let
> > pg_stat_replication_slots as is and add a brief ReorderBuffer section
> > under Logical Decoding concepts [3] just before Output Plugins. And
> > then, pg_stat_replication_slots can refer to that section, clarifying
> > that the bytes, counts, and txn fields pertain to ReorderBuffer
> > (without changing any of the fields).
> >
> > And then to define plugin related data, we can have a new view, say
> > pg_stat_plugin_stats (as Amit suggested earlier) or
> > pg_stat_replication_plugins. I understand that adding a new view might
> > not be desirable, but it provides better clarity without requiring
> > changes to the existing fields in pg_stat_replication_slots. I also
> > strongly feel that to properly tie all this information together, a
> > brief definition of the ReorderBuffer is needed. Other pages that
> > reference this term can then point to that section. Thoughts?
>
> Even if we keep two views, when they are joined, users will still get
> confused by total_* names. So it's not solving the underlying problem.
Okay, I see your point.
> Andres had raised the point about renaming total_* fields with me
> off-list earlier. He suggested names total_wal_bytes, and
> total_wal_txns in an off list discussion today. I think those convey
> the true meaning - that these are txns and bytes that come from WAL.
I agree.
> Used those in the attached patches. Prefix reordered would give away
> lower level details, so I didn't use it.
>
> I agree that it would be good to mention ReorderBuffer in the logical
> decoding concepts section since it mentions structures ReorderBuffer*.
> But that would be a separate patch since we aren't using "reordered"
> in the names of the fields.
Okay.
> 0001 is the previous patch
> 0002 changes addressing your and Bertrand's comments.
>
Few trivial comments:
1)
Currently the doc says:
sentTxns is the number of transactions sent downstream by the output
plugin. sentBytes is the amount of data, in bytes, sent downstream by
the output plugin. OutputPluginWrite will update this counter if
ctx->stats is initialized by the output plugin. filteredBytes is the
size of changes, in bytes, that are filtered out by the output plugin.
Function ReorderBufferChangeSize may be used to find the size of
filtered ReorderBufferChange.
Shall we rearrange it to:
sentTxns is the number of transactions sent downstream by the output
plugin. sentBytes is the amount of data, in bytes, sent downstream by
the output plugin. filteredBytes is the size of changes, in bytes,
that are filtered out by the output plugin. OutputPluginWrite will
update these counters if ctx->stats is initialized by the output
plugin.
The function ReorderBufferChangeSize can be used to compute the size
of a filtered ReorderBufferChange, i.e., the filteredBytes.
2)
My preference will be to rename the fields 'total_txns' and
'total_bytes' in PgStat_StatReplSlotEntry to 'total_wal_txns' and
'total_wal_bytes' for better clarity. Additionally, upon rethinking,
it seems better to me that plugin-related fields are also named as
plugin_* to clearly indicate their association. OTOH, in
OutputPluginStats, the field names are fine as is, since the structure
name itself clearly indicates these are plugin-related fields.
PgStat_StatReplSlotEntry lacks such context and thus using full
descriptive names there would improve clarity.
3)
LogicalOutputWrite:
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) +
sizeof(TransactionId);
p->returned_rows++;
A blank line after the new change will increase readability.
~~
In my testing, the patch works as expected. Thanks!
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-22 05:14 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-09-23 10:36 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 04:42 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-23 10:36 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
On Mon, Sep 22, 2025 at 10:44 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> Few trivial comments:
>
> 1)
> Currently the doc says:
>
> sentTxns is the number of transactions sent downstream by the output
> plugin. sentBytes is the amount of data, in bytes, sent downstream by
> the output plugin. OutputPluginWrite will update this counter if
> ctx->stats is initialized by the output plugin. filteredBytes is the
> size of changes, in bytes, that are filtered out by the output plugin.
> Function ReorderBufferChangeSize may be used to find the size of
> filtered ReorderBufferChange.
>
> Shall we rearrange it to:
>
> sentTxns is the number of transactions sent downstream by the output
> plugin. sentBytes is the amount of data, in bytes, sent downstream by
> the output plugin. filteredBytes is the size of changes, in bytes,
> that are filtered out by the output plugin. OutputPluginWrite will
> update these counters if ctx->stats is initialized by the output
> plugin.
> The function ReorderBufferChangeSize can be used to compute the size
> of a filtered ReorderBufferChange, i.e., the filteredBytes.
>
Only sentBytes is incremented by OutputPluginWrite(), so saying that
it will update counters is not correct. But I think you intend to keep
description of all the fields together followed by any additional
information. How about the following
<literal>sentTxns</literal> is the number of transactions sent downstream
by the output plugin. <literal>sentBytes</literal> is the amount of data,
in bytes, sent downstream by the output plugin.
<literal>filteredBytes</literal> is the size of changes, in bytes, that
are filtered out by the output plugin.
<function>OutputPluginWrite</function> will update
<literal>sentBytes</literal> if <literal>ctx->stats</literal> is
initialized by the output plugin. Function
<literal>ReorderBufferChangeSize</literal> may be used to find the size of
filtered <literal>ReorderBufferChange</literal>.
> 2)
> My preference will be to rename the fields 'total_txns' and
> 'total_bytes' in PgStat_StatReplSlotEntry to 'total_wal_txns' and
> 'total_wal_bytes' for better clarity. Additionally, upon rethinking,
> it seems better to me that plugin-related fields are also named as
> plugin_* to clearly indicate their association. OTOH, in
> OutputPluginStats, the field names are fine as is, since the structure
> name itself clearly indicates these are plugin-related fields.
> PgStat_StatReplSlotEntry lacks such context and thus using full
> descriptive names there would improve clarity.
Ok. Done.
>
> 3)
> LogicalOutputWrite:
> + if (ctx->stats)
> + ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) +
> sizeof(TransactionId);
> p->returned_rows++;
>
> A blank line after the new change will increase readability.
>
Ok.
> ~~
>
> In my testing, the patch works as expected. Thanks!
Thanks for testing. Can we include any of your tests in the patch? Are
the tests in patch enough?
Applied those suggestions in my repository. Do you have any further
review comments?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-22 05:14 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-23 10:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 04:42 ` shveta malik <shveta.malik@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: shveta malik @ 2025-09-24 04:42 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>; shveta malik <shveta.malik@gmail.com>
On Tue, Sep 23, 2025 at 4:06 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Mon, Sep 22, 2025 at 10:44 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > Few trivial comments:
> >
> > 1)
> > Currently the doc says:
> >
> > sentTxns is the number of transactions sent downstream by the output
> > plugin. sentBytes is the amount of data, in bytes, sent downstream by
> > the output plugin. OutputPluginWrite will update this counter if
> > ctx->stats is initialized by the output plugin. filteredBytes is the
> > size of changes, in bytes, that are filtered out by the output plugin.
> > Function ReorderBufferChangeSize may be used to find the size of
> > filtered ReorderBufferChange.
> >
> > Shall we rearrange it to:
> >
> > sentTxns is the number of transactions sent downstream by the output
> > plugin. sentBytes is the amount of data, in bytes, sent downstream by
> > the output plugin. filteredBytes is the size of changes, in bytes,
> > that are filtered out by the output plugin. OutputPluginWrite will
> > update these counters if ctx->stats is initialized by the output
> > plugin.
> > The function ReorderBufferChangeSize can be used to compute the size
> > of a filtered ReorderBufferChange, i.e., the filteredBytes.
> >
>
> Only sentBytes is incremented by OutputPluginWrite(), so saying that
> it will update counters is not correct. But I think you intend to keep
> description of all the fields together followed by any additional
> information. How about the following
> <literal>sentTxns</literal> is the number of transactions sent downstream
> by the output plugin. <literal>sentBytes</literal> is the amount of data,
> in bytes, sent downstream by the output plugin.
> <literal>filteredBytes</literal> is the size of changes, in bytes, that
> are filtered out by the output plugin.
> <function>OutputPluginWrite</function> will update
> <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
> initialized by the output plugin. Function
> <literal>ReorderBufferChangeSize</literal> may be used to find the size of
> filtered <literal>ReorderBufferChange</literal>.
Yes, this looks good.
>
> > 2)
> > My preference will be to rename the fields 'total_txns' and
> > 'total_bytes' in PgStat_StatReplSlotEntry to 'total_wal_txns' and
> > 'total_wal_bytes' for better clarity. Additionally, upon rethinking,
> > it seems better to me that plugin-related fields are also named as
> > plugin_* to clearly indicate their association. OTOH, in
> > OutputPluginStats, the field names are fine as is, since the structure
> > name itself clearly indicates these are plugin-related fields.
> > PgStat_StatReplSlotEntry lacks such context and thus using full
> > descriptive names there would improve clarity.
>
> Ok. Done.
>
> >
> > 3)
> > LogicalOutputWrite:
> > + if (ctx->stats)
> > + ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) +
> > sizeof(TransactionId);
> > p->returned_rows++;
> >
> > A blank line after the new change will increase readability.
> >
>
> Ok.
>
> > ~~
> >
> > In my testing, the patch works as expected. Thanks!
>
> Thanks for testing. Can we include any of your tests in the patch? Are
> the tests in patch enough?
I tested the flows with
a) logical replication slot and get-changes.
b) filtered data flows: pub-sub creation with row_filters, 'publish'
options. I tried to verify plugin fields as compared to total_wal*
fields.
c) reset flow.
While tests for a and c are present already. I don't see tests for b
anywhere when it comes to stats. Do you think we shall add a test for
filtered data using row-filter somewhere?
>
> Applied those suggestions in my repository. Do you have any further
> review comments?
>
No, I think that is all.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-23 06:44 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-23 06:44 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Fri, Sep 19, 2025 at 08:11:23PM +0530, Ashutosh Bapat wrote:
> On Fri, Sep 19, 2025 at 11:48 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
> 0001 is the previous patch
> 0002 changes addressing your and Bertrand's comments.
Thanks for the new patch version!
I did not look closely to the code yet but did some testing and I've one remark
regarding plugin_filtered_bytes: It looks ok when a publication is doing rows
filtering but when I:
- create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '0')
then I see plugin_sent_bytes increasing (which makes sense).
- create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '1')
then I don't see plugin_sent_bytes increasing (which makes sense) but I also don't
see plugin_filtered_bytes increasing. I think that would make sense to also increase
plugin_filtered_bytes in this case (and for the other options that would skip
sending data). Thoughts?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-23 10:45 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-23 10:45 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Tue, Sep 23, 2025 at 12:14 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Fri, Sep 19, 2025 at 08:11:23PM +0530, Ashutosh Bapat wrote:
> > On Fri, Sep 19, 2025 at 11:48 AM shveta malik <shveta.malik@gmail.com> wrote:
> > >
> > 0001 is the previous patch
> > 0002 changes addressing your and Bertrand's comments.
>
> Thanks for the new patch version!
>
> I did not look closely to the code yet but did some testing and I've one remark
> regarding plugin_filtered_bytes: It looks ok when a publication is doing rows
> filtering but when I:
>
> - create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '0')
> then I see plugin_sent_bytes increasing (which makes sense).
>
> - create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '1')
> then I don't see plugin_sent_bytes increasing (which makes sense) but I also don't
> see plugin_filtered_bytes increasing. I think that would make sense to also increase
> plugin_filtered_bytes in this case (and for the other options that would skip
> sending data). Thoughts?
Thanks for bringing this up. I don't think we discussed this
explicitly in the thread. The changes which are filtered out by the
core itself e.g. changes to the catalogs or changes to other databases
or changes from undesired origins are not added to the reorder buffer.
They are not counted in total_bytes. The transactions containing only
such changes are not added to reorder buffer, so even total_txns does
not count such empty transactions. If we count these changes and
transactions in plugin_filtered_bytes, and plugin_filtered_txns, that
would create an anomaly - filtered counts being higher than total
counts. Further since core does not add these changes and transactions
to the reorder buffer, there is no way for a plugin to know about
their existence and hence count them. Does that make sense?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 07:02 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:21 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-24 07:02 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Tue, Sep 23, 2025 at 04:15:14PM +0530, Ashutosh Bapat wrote:
> On Tue, Sep 23, 2025 at 12:14 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > - create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '1')
> > then I don't see plugin_sent_bytes increasing (which makes sense) but I also don't
> > see plugin_filtered_bytes increasing. I think that would make sense to also increase
> > plugin_filtered_bytes in this case (and for the other options that would skip
> > sending data). Thoughts?
>
> Thanks for bringing this up. I don't think we discussed this
> explicitly in the thread. The changes which are filtered out by the
> core itself e.g. changes to the catalogs or changes to other databases
> or changes from undesired origins are not added to the reorder buffer.
> They are not counted in total_bytes. The transactions containing only
> such changes are not added to reorder buffer, so even total_txns does
> not count such empty transactions. If we count these changes and
> transactions in plugin_filtered_bytes, and plugin_filtered_txns, that
> would create an anomaly - filtered counts being higher than total
> counts. Further since core does not add these changes and transactions
> to the reorder buffer, there is no way for a plugin to know about
> their existence and hence count them. Does that make sense?
Yes. Do you think that the doc in the patch is clear enough regarding this point?
I mean the doc looks correct (mentioning the output plugin) but would that make
sense to insist that core filtering is not taken into account?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-24 07:21 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 08:25 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-24 07:21 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Sep 24, 2025 at 12:32 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Tue, Sep 23, 2025 at 04:15:14PM +0530, Ashutosh Bapat wrote:
> > On Tue, Sep 23, 2025 at 12:14 PM Bertrand Drouvot
> > <bertranddrouvot.pg@gmail.com> wrote:
> > >
> > > - create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '1')
> > > then I don't see plugin_sent_bytes increasing (which makes sense) but I also don't
> > > see plugin_filtered_bytes increasing. I think that would make sense to also increase
> > > plugin_filtered_bytes in this case (and for the other options that would skip
> > > sending data). Thoughts?
> >
> > Thanks for bringing this up. I don't think we discussed this
> > explicitly in the thread. The changes which are filtered out by the
> > core itself e.g. changes to the catalogs or changes to other databases
> > or changes from undesired origins are not added to the reorder buffer.
> > They are not counted in total_bytes. The transactions containing only
> > such changes are not added to reorder buffer, so even total_txns does
> > not count such empty transactions. If we count these changes and
> > transactions in plugin_filtered_bytes, and plugin_filtered_txns, that
> > would create an anomaly - filtered counts being higher than total
> > counts. Further since core does not add these changes and transactions
> > to the reorder buffer, there is no way for a plugin to know about
> > their existence and hence count them. Does that make sense?
>
> Yes. Do you think that the doc in the patch is clear enough regarding this point?
> I mean the doc looks correct (mentioning the output plugin) but would that make
> sense to insist that core filtering is not taken into account?
Do you mean, should we mention in the docs that core filtering is not
taken into account? I would question whether that's called filtering
at all, in the context of logical decoding. The view should be read in
the context of logical decoding. For example, we aren't mentioning
that total_bytes does not include changes from other database.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:21 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 08:25 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 10:07 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-24 08:25 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Wed, Sep 24, 2025 at 12:51:29PM +0530, Ashutosh Bapat wrote:
> On Wed, Sep 24, 2025 at 12:32 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> > > > - create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '1')
> > > > then I don't see plugin_sent_bytes increasing (which makes sense) but I also don't
> > > > see plugin_filtered_bytes increasing. I think that would make sense to also increase
> > > > plugin_filtered_bytes in this case (and for the other options that would skip
> > > > sending data). Thoughts?
> > >
> > > Thanks for bringing this up. I don't think we discussed this
> > > explicitly in the thread. The changes which are filtered out by the
> > > core itself e.g. changes to the catalogs or changes to other databases
> > > or changes from undesired origins are not added to the reorder buffer.
> > > They are not counted in total_bytes. The transactions containing only
> > > such changes are not added to reorder buffer, so even total_txns does
> > > not count such empty transactions. If we count these changes and
> > > transactions in plugin_filtered_bytes, and plugin_filtered_txns, that
> > > would create an anomaly - filtered counts being higher than total
> > > counts. Further since core does not add these changes and transactions
> > > to the reorder buffer, there is no way for a plugin to know about
> > > their existence and hence count them. Does that make sense?
> >
> > Yes. Do you think that the doc in the patch is clear enough regarding this point?
> > I mean the doc looks correct (mentioning the output plugin) but would that make
> > sense to insist that core filtering is not taken into account?
>
> Do you mean, should we mention in the docs that core filtering is not
> taken into account?
> I would question whether that's called filtering
> at all, in the context of logical decoding. The view should be read in
> the context of logical decoding. For example, we aren't mentioning
> that total_bytes does not include changes from other database.
Right. But, in the example above, do you consider "skip-empty-xacts" as "core"
or "plugin" filtering?
It's an option part of the "test_decoding" plugin, so it's the plugin choice to
not display empty xacts (should the option be set accordingly). Then should it
be reported in plugin_filtered_bytes? (one could write a plugin, decide to
skip/filter empty xacts or whatever in the plugin callbacks: should that be
reported as plugin_filtered_bytes?)
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:21 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 08:25 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-24 10:07 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 13:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-24 10:07 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Sep 24, 2025 at 1:55 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Wed, Sep 24, 2025 at 12:51:29PM +0530, Ashutosh Bapat wrote:
> > On Wed, Sep 24, 2025 at 12:32 PM Bertrand Drouvot
> > <bertranddrouvot.pg@gmail.com> wrote:
> > > > > - create a table and use pg_logical_slot_get_changes with ('skip-empty-xacts', '1')
> > > > > then I don't see plugin_sent_bytes increasing (which makes sense) but I also don't
> > > > > see plugin_filtered_bytes increasing. I think that would make sense to also increase
> > > > > plugin_filtered_bytes in this case (and for the other options that would skip
> > > > > sending data). Thoughts?
> > > >
> > > > Thanks for bringing this up. I don't think we discussed this
> > > > explicitly in the thread. The changes which are filtered out by the
> > > > core itself e.g. changes to the catalogs or changes to other databases
> > > > or changes from undesired origins are not added to the reorder buffer.
> > > > They are not counted in total_bytes. The transactions containing only
> > > > such changes are not added to reorder buffer, so even total_txns does
> > > > not count such empty transactions. If we count these changes and
> > > > transactions in plugin_filtered_bytes, and plugin_filtered_txns, that
> > > > would create an anomaly - filtered counts being higher than total
> > > > counts. Further since core does not add these changes and transactions
> > > > to the reorder buffer, there is no way for a plugin to know about
> > > > their existence and hence count them. Does that make sense?
> > >
> > > Yes. Do you think that the doc in the patch is clear enough regarding this point?
> > > I mean the doc looks correct (mentioning the output plugin) but would that make
> > > sense to insist that core filtering is not taken into account?
> >
> > Do you mean, should we mention in the docs that core filtering is not
> > taken into account?
> > I would question whether that's called filtering
> > at all, in the context of logical decoding. The view should be read in
> > the context of logical decoding. For example, we aren't mentioning
> > that total_bytes does not include changes from other database.
>
> Right. But, in the example above, do you consider "skip-empty-xacts" as "core"
> or "plugin" filtering?
>
> It's an option part of the "test_decoding" plugin, so it's the plugin choice to
> not display empty xacts (should the option be set accordingly). Then should it
> be reported in plugin_filtered_bytes? (one could write a plugin, decide to
> skip/filter empty xacts or whatever in the plugin callbacks: should that be
> reported as plugin_filtered_bytes?)
If a transaction becomes empty because the plugin filtered all the
changes then plugin_filtered_bytes will be incremented by the amount
of filtered changes. If the transaction was empty because core didn't
send any of the changes to the output plugin, there was nothing
filtered by the output plugin so plugin_filtered_bytes will not be
affected.
skip_empty_xacts controls whether BEGIN and COMMIT are sent for an
empty transaction or not. It does not filter "changes". It affects
"sent_bytes".
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:21 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 08:25 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 10:07 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 13:13 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-24 13:13 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Wed, Sep 24, 2025 at 03:37:07PM +0530, Ashutosh Bapat wrote:
> On Wed, Sep 24, 2025 at 1:55 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> > Right. But, in the example above, do you consider "skip-empty-xacts" as "core"
> > or "plugin" filtering?
> >
> > It's an option part of the "test_decoding" plugin, so it's the plugin choice to
> > not display empty xacts (should the option be set accordingly). Then should it
> > be reported in plugin_filtered_bytes? (one could write a plugin, decide to
> > skip/filter empty xacts or whatever in the plugin callbacks: should that be
> > reported as plugin_filtered_bytes?)
>
> If a transaction becomes empty because the plugin filtered all the
> changes then plugin_filtered_bytes will be incremented by the amount
> of filtered changes. If the transaction was empty because core didn't
> send any of the changes to the output plugin, there was nothing
> filtered by the output plugin so plugin_filtered_bytes will not be
> affected.
>
> skip_empty_xacts controls whether BEGIN and COMMIT are sent for an
> empty transaction or not. It does not filter "changes". It affects
> "sent_bytes".
skip_empty_xacts was just an example. I mean a plugin could decide to filter all
the inserts for example (not saying it makes sense). But I think we'are saying the
same: say a plugin wants to filter the inserts then it's its responsability to
increment ctx->stats->filteredBytes in its "change_cb" callback for the
REORDER_BUFFER_CHANGE_INSERT action, right? If so, I wonder if it would make
sense to provide an example in the test_decoding plugin (I can see it's done
for pgoutput but that might sound more natural to look in contrib if one is
searching for an example).
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 06:44 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:21 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 08:25 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 10:07 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 13:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-25 04:23 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-25 04:23 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Sep 24, 2025 at 6:43 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Wed, Sep 24, 2025 at 03:37:07PM +0530, Ashutosh Bapat wrote:
> > On Wed, Sep 24, 2025 at 1:55 PM Bertrand Drouvot
> > <bertranddrouvot.pg@gmail.com> wrote:
> > > Right. But, in the example above, do you consider "skip-empty-xacts" as "core"
> > > or "plugin" filtering?
> > >
> > > It's an option part of the "test_decoding" plugin, so it's the plugin choice to
> > > not display empty xacts (should the option be set accordingly). Then should it
> > > be reported in plugin_filtered_bytes? (one could write a plugin, decide to
> > > skip/filter empty xacts or whatever in the plugin callbacks: should that be
> > > reported as plugin_filtered_bytes?)
> >
> > If a transaction becomes empty because the plugin filtered all the
> > changes then plugin_filtered_bytes will be incremented by the amount
> > of filtered changes. If the transaction was empty because core didn't
> > send any of the changes to the output plugin, there was nothing
> > filtered by the output plugin so plugin_filtered_bytes will not be
> > affected.
> >
> > skip_empty_xacts controls whether BEGIN and COMMIT are sent for an
> > empty transaction or not. It does not filter "changes". It affects
> > "sent_bytes".
>
> skip_empty_xacts was just an example. I mean a plugin could decide to filter all
> the inserts for example (not saying it makes sense). But I think we'are saying the
> same: say a plugin wants to filter the inserts then it's its responsability to
> increment ctx->stats->filteredBytes in its "change_cb" callback for the
> REORDER_BUFFER_CHANGE_INSERT action, right?
Right.
> If so, I wonder if it would make
> sense to provide an example in the test_decoding plugin (I can see it's done
> for pgoutput but that might sound more natural to look in contrib if one is
> searching for an example).
test_decoding does not make use of publication at all. Publication
controls filtering and so test_decoding does not have any examples of
filtering code. Doesn't make sense to add code to manipulate
filteredBytes there.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-23 12:58 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2025-09-23 12:58 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
> 0001 is the previous patch
> 0002 changes addressing your and Bertrand's comments.
>
@@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx,
XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
Just a small observation: I think it’s actually pq_flush_if_writable()
that writes the buffered data to the socket, not pq_putmessage_noblock
(which is actually gathering data in the buffer and not sending). So
it might make more sense to increment the sent pointer after the call
to pq_flush_if_writable().
Should we also consider - pg_hton32((uint32) (len + 4)); -- the
additional 4 bytes of data added to the send buffer.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2025-09-24 05:38 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-24 05:38 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; shveta malik <shveta.malik@gmail.com>; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Tue, Sep 23, 2025 at 6:28 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> > 0001 is the previous patch
> > 0002 changes addressing your and Bertrand's comments.
> >
>
> @@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx,
> XLogRecPtr lsn, TransactionId xid,
> /* output previously gathered data in a CopyData packet */
> pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
>
> + /*
> + * If output plugin maintains statistics, update the amount of data sent
> + * downstream.
> + */
> + if (ctx->stats)
> + ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
> +
>
> Just a small observation: I think it’s actually pq_flush_if_writable()
> that writes the buffered data to the socket, not pq_putmessage_noblock
> (which is actually gathering data in the buffer and not sending). So
> it might make more sense to increment the sent pointer after the call
> to pq_flush_if_writable().
That's a good point. I placed it after pq_putmessage_noblock() so that
it's easy to link the increment to sentBytes and the actual bytes
being sent. You are right that the bytes won't be sent unless
pq_flush_if_writable() is called but it will be called for sure before
the next UpdateDecodingStats(). So the reported bytes are never wrong.
I would prefer readability over seeming accuracy.
>
> Should we also consider - pg_hton32((uint32) (len + 4)); -- the
> additional 4 bytes of data added to the send buffer.
>
In WalSndWriteData() we can't rely on what happens in a low level API
like socket_putmessage(). And we are counting the number of bytes in
the logically decoded message. So, I actually wonder whether we should
count 1 byte of 'd' in sentBytes. Shveta, Bertand, what do you think?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 06:08 ` shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-09-24 06:08 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Wed, Sep 24, 2025 at 11:08 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Tue, Sep 23, 2025 at 6:28 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> >
> > > 0001 is the previous patch
> > > 0002 changes addressing your and Bertrand's comments.
> > >
> >
> > @@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx,
> > XLogRecPtr lsn, TransactionId xid,
> > /* output previously gathered data in a CopyData packet */
> > pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
> >
> > + /*
> > + * If output plugin maintains statistics, update the amount of data sent
> > + * downstream.
> > + */
> > + if (ctx->stats)
> > + ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
> > +
> >
> > Just a small observation: I think it’s actually pq_flush_if_writable()
> > that writes the buffered data to the socket, not pq_putmessage_noblock
> > (which is actually gathering data in the buffer and not sending). So
> > it might make more sense to increment the sent pointer after the call
> > to pq_flush_if_writable().
>
> That's a good point. I placed it after pq_putmessage_noblock() so that
> it's easy to link the increment to sentBytes and the actual bytes
> being sent. You are right that the bytes won't be sent unless
> pq_flush_if_writable() is called but it will be called for sure before
> the next UpdateDecodingStats(). So the reported bytes are never wrong.
> I would prefer readability over seeming accuracy.
>
> >
> > Should we also consider - pg_hton32((uint32) (len + 4)); -- the
> > additional 4 bytes of data added to the send buffer.
> >
>
> In WalSndWriteData() we can't rely on what happens in a low level API
> like socket_putmessage(). And we are counting the number of bytes in
> the logically decoded message. So, I actually wonder whether we should
> count 1 byte of 'd' in sentBytes. Shveta, Bertand, what do you think?
>
If we are not counting all such metadata bytes ((or can't reliably do
so), then IMO, we shall skip counting msgtype as well.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-09-24 06:42 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-24 06:42 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Wed, Sep 24, 2025 at 11:38:30AM +0530, shveta malik wrote:
> On Wed, Sep 24, 2025 at 11:08 AM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > In WalSndWriteData() we can't rely on what happens in a low level API
> > like socket_putmessage(). And we are counting the number of bytes in
> > the logically decoded message. So, I actually wonder whether we should
> > count 1 byte of 'd' in sentBytes. Shveta, Bertand, what do you think?
> >
>
> If we are not counting all such metadata bytes ((or can't reliably do
> so), then IMO, we shall skip counting msgtype as well.
Agree. Maybe mention in the doc that metadata (including msgtype) bytes are not
taken into account?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-24 07:17 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-24 07:17 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Sep 24, 2025 at 10:12 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> I tested the flows with
> a) logical replication slot and get-changes.
> b) filtered data flows: pub-sub creation with row_filters, 'publish'
> options. I tried to verify plugin fields as compared to total_wal*
> fields.
> c) reset flow.
>
> While tests for a and c are present already. I don't see tests for b
> anywhere when it comes to stats. Do you think we shall add a test for
> filtered data using row-filter somewhere?
Added a test in 028_row_filter. Please find it in the attached
patchset. I didn't find tests which test table level filtering or
operation level filtering. Can you please point me to such tests. I
will add similar test to other places. Once you review the test in
028_row_filter, I will replicate it to other places you point out.
On Wed, Sep 24, 2025 at 12:12 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Wed, Sep 24, 2025 at 11:38:30AM +0530, shveta malik wrote:
> > On Wed, Sep 24, 2025 at 11:08 AM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > > In WalSndWriteData() we can't rely on what happens in a low level API
> > > like socket_putmessage(). And we are counting the number of bytes in
> > > the logically decoded message. So, I actually wonder whether we should
> > > count 1 byte of 'd' in sentBytes. Shveta, Bertand, what do you think?
> > >
> >
> > If we are not counting all such metadata bytes ((or can't reliably do
> > so), then IMO, we shall skip counting msgtype as well.
>
> Agree. Maybe mention in the doc that metadata (including msgtype) bytes are not
> taken into account?
We are counting the sentBytes in central places through which all the
logically decoded messages flow. So we are not missing on any metadata
bytes. Given that these bytes are part of the logically decoded
message itself, I think we should count them in the sentBytes. Now the
question remains is whether to count 4 bytes for length in the message
itself? The logical decoding code can not control that and thus should
not account for it. So I am leaving bytes counted for
pg_hton32((uint32) (len + 4)) out of sentBytes calculation.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
0001-Report-output-plugin-statistics-in-pg_stat_-20250924.patch (text/x-patch, 42.6K) download
From a27c83fdf1f49a43844c1c4bcd763439e225f82d Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH 1/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 27 +++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 24 +++++-
.../replication/logical/logicalfuncs.c | 7 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 7 ++
src/backend/utils/adt/pgstatfuncs.c | 30 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 4 +
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
src/test/regress/expected/rules.out | 10 ++-
src/tools/pgindent/typedefs.list | 1 +
22 files changed, 290 insertions(+), 79 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..4834b3460a6 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..99f513902d3 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index f671a7d4b31..ea5c527644b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..3952f68e806 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,33 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data, in bytes,
+ sent downstream by the output plugin.
+ <function>OutputPluginWrite</function> will update this counter
+ if <literal>ctx->stats</literal> is initialized by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that are
+ filtered out by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 3f4a27a736e..fbe03ffd670 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1545,6 +1545,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1622,19 +1633,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1644,6 +1655,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transctions sent to
+ the decoding plugin. Hence this count is expected to be lesser than or
+ equal to <structfield>total_wal_txns</structfield>. The count is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The count is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index c77fa0234bb..9e8e32b5849 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,14 +1053,18 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index c68c0481f42..b26ac29e32f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,13 +1952,14 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1968,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1977,6 +1982,15 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.sent_txns = stats->sentTxns;
+ repSlotStat.sent_bytes = stats->sentBytes;
+ repSlotStat.filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +2002,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..788967e2ab1 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 4736f993c37..12579dff2c1 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4436,7 +4435,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 80540c017bd..339babbeb56 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -450,6 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
ALLOCSET_SMALL_SIZES);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -591,6 +592,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1469,7 +1471,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1487,15 +1492,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1505,6 +1519,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1560,7 +1575,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1688,6 +1706,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 59822f22b8d..d9217ce49aa 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..ed055324a99 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,13 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(sent_txns);
+ REPLSLOT_ACC(sent_bytes);
+ REPLSLOT_ACC(filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index c756c2bebaa..15bafe63b24 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2125,11 +2125,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2154,11 +2160,23 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->total_txns);
values[8] = Int64GetDatum(slotent->total_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[9] = Int64GetDatum(slotent->filtered_bytes);
+ values[10] = Int64GetDatum(slotent->sent_txns);
+ values[11] = Int64GetDatum(slotent->sent_bytes);
+ }
+ else
+ {
+ nulls[9] = true;
+ nulls[10] = true;
+ nulls[11] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[12] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 01eba3b5a19..9e4f6620214 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5687,9 +5687,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index f402b17295c..87afeaed8a5 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -395,6 +395,10 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_bytes;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter sent_txns;
+ PgStat_Counter sent_bytes;
+ PgStat_Counter filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index fa0745552f8..3ea2d9885b6 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -715,6 +715,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..b04a0d9f8db 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 35e8aad7701..2a401552a7a 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2132,17 +2132,21 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 3c80d49b67e..b97915c1697 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1830,6 +1830,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 5334620eef8f7b429594e6cf9dc97331eda2a8bd
--
2.34.1
0002-Address-second-round-of-comments-from-Shvet-20250924.patch (text/x-patch, 10.9K) download
From 3db9ce87b46783f20e8c34958f7cc2903bddd7da Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Tue, 23 Sep 2025 16:43:33 +0530
Subject: [PATCH 2/2] Address second round of comments from Shveta Malik
Add a test for plugin_filtered_bytes in logical replication case. We can
not test exact number of bytes filtered because of the unavoidable
background transaction activity which will be counted in the filtered
bytes.
---
doc/src/sgml/logicaldecoding.sgml | 13 +++++++------
src/backend/replication/logical/logical.c | 10 +++++-----
src/backend/replication/logical/logicalfuncs.c | 1 +
src/backend/utils/activity/pgstat_replslot.c | 10 +++++-----
src/backend/utils/adt/pgstatfuncs.c | 10 +++++-----
src/include/pgstat.h | 10 +++++-----
src/test/recovery/t/006_logical_decoding.pl | 6 +++---
.../recovery/t/035_standby_logical_decoding.pl | 4 ++--
src/test/subscription/t/028_row_filter.pl | 14 ++++++++++++++
9 files changed, 47 insertions(+), 31 deletions(-)
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index 3952f68e806..c02d4a88d57 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -956,12 +956,13 @@ typedef struct OutputPluginStats
} OutputPluginStats;
</programlisting>
<literal>sentTxns</literal> is the number of transactions sent downstream
- by the output plugin. <literal>sentBytes</literal> is the amount of data, in bytes,
- sent downstream by the output plugin.
- <function>OutputPluginWrite</function> will update this counter
- if <literal>ctx->stats</literal> is initialized by the output plugin.
- <literal>filteredBytes</literal> is the size of changes, in bytes, that are
- filtered out by the output plugin. Function
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
<literal>ReorderBufferChangeSize</literal> may be used to find the size of
filtered <literal>ReorderBufferChange</literal>.
</para>
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index b26ac29e32f..1435873101f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1980,14 +1980,14 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_txns = rb->streamTxns;
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
if (stats)
{
repSlotStat.plugin_has_stats = true;
- repSlotStat.sent_txns = stats->sentTxns;
- repSlotStat.sent_bytes = stats->sentBytes;
- repSlotStat.filtered_bytes = stats->filteredBytes;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
}
else
repSlotStat.plugin_has_stats = false;
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 788967e2ab1..d2ab41de438 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -96,6 +96,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
*/
if (ctx->stats)
ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+
p->returned_rows++;
}
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ed055324a99..895940f4eb9 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -94,14 +94,14 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_txns);
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
statent->plugin_has_stats = repSlotStat->plugin_has_stats;
if (repSlotStat->plugin_has_stats)
{
- REPLSLOT_ACC(sent_txns);
- REPLSLOT_ACC(sent_bytes);
- REPLSLOT_ACC(filtered_bytes);
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
}
#undef REPLSLOT_ACC
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 15bafe63b24..588b49059b2 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2158,13 +2158,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[4] = Int64GetDatum(slotent->stream_txns);
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->total_txns);
- values[8] = Int64GetDatum(slotent->total_bytes);
+ values[7] = Int64GetDatum(slotent->total_wal_txns);
+ values[8] = Int64GetDatum(slotent->total_wal_bytes);
if (slotent->plugin_has_stats)
{
- values[9] = Int64GetDatum(slotent->filtered_bytes);
- values[10] = Int64GetDatum(slotent->sent_txns);
- values[11] = Int64GetDatum(slotent->sent_bytes);
+ values[9] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[10] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[11] = Int64GetDatum(slotent->plugin_sent_bytes);
}
else
{
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 87afeaed8a5..33a031c79b4 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -393,12 +393,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_txns;
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
bool plugin_has_stats;
- PgStat_Counter sent_txns;
- PgStat_Counter sent_bytes;
- PgStat_Counter filtered_bytes;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index b04a0d9f8db..92e42bec6a9 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,7 +212,7 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
qq(t|t|t),
qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
qq(t|t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index c9c182892cf..c8577794eec 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -575,7 +575,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -603,7 +603,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..798364c62e6 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,11 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+#
+# Get initial plugin statistics before any filtering occurs
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +617,15 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# Check final plugin statistics and verify filtering occurred.
+# plugin_filtered_bytes includes the amount of changes from background
+# transactions, which may or may not happen. Hence testing exact amount of
+# filtered data is not possible.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 09:07 ` shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-09-24 09:07 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Wed, Sep 24, 2025 at 12:47 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Wed, Sep 24, 2025 at 10:12 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > I tested the flows with
> > a) logical replication slot and get-changes.
> > b) filtered data flows: pub-sub creation with row_filters, 'publish'
> > options. I tried to verify plugin fields as compared to total_wal*
> > fields.
> > c) reset flow.
> >
> > While tests for a and c are present already. I don't see tests for b
> > anywhere when it comes to stats. Do you think we shall add a test for
> > filtered data using row-filter somewhere?
>
> Added a test in 028_row_filter. Please find it in the attached
> patchset.
Test looks good.
> I didn't find tests which test table level filtering or
> operation level filtering. Can you please point me to such tests. I
> will add similar test to other places. Once you review the test in
> 028_row_filter, I will replicate it to other places you point out.
>
I can see a few tests of operation level filtering present in
'subscription/t/001_rep_changes.pl' and
'subscription/t/010_truncate.pl'
> On Wed, Sep 24, 2025 at 12:12 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > Hi,
> >
> > On Wed, Sep 24, 2025 at 11:38:30AM +0530, shveta malik wrote:
> > > On Wed, Sep 24, 2025 at 11:08 AM Ashutosh Bapat
> > > <ashutosh.bapat.oss@gmail.com> wrote:
> > > >
> > > > In WalSndWriteData() we can't rely on what happens in a low level API
> > > > like socket_putmessage(). And we are counting the number of bytes in
> > > > the logically decoded message. So, I actually wonder whether we should
> > > > count 1 byte of 'd' in sentBytes. Shveta, Bertand, what do you think?
> > > >
> > >
> > > If we are not counting all such metadata bytes ((or can't reliably do
> > > so), then IMO, we shall skip counting msgtype as well.
> >
> > Agree. Maybe mention in the doc that metadata (including msgtype) bytes are not
> > taken into account?
>
> We are counting the sentBytes in central places through which all the
> logically decoded messages flow. So we are not missing on any metadata
> bytes. Given that these bytes are part of the logically decoded
> message itself, I think we should count them in the sentBytes. Now the
> question remains is whether to count 4 bytes for length in the message
> itself? The logical decoding code can not control that and thus should
> not account for it. So I am leaving bytes counted for
> pg_hton32((uint32) (len + 4)) out of sentBytes calculation.
> --
Okay.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-09-24 11:58 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 03:59 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-24 11:58 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Sep 24, 2025 at 2:38 PM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Wed, Sep 24, 2025 at 12:47 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Wed, Sep 24, 2025 at 10:12 AM shveta malik <shveta.malik@gmail.com> wrote:
> > >
> > > I tested the flows with
> > > a) logical replication slot and get-changes.
> > > b) filtered data flows: pub-sub creation with row_filters, 'publish'
> > > options. I tried to verify plugin fields as compared to total_wal*
> > > fields.
> > > c) reset flow.
> > >
> > > While tests for a and c are present already. I don't see tests for b
> > > anywhere when it comes to stats. Do you think we shall add a test for
> > > filtered data using row-filter somewhere?
> >
> > Added a test in 028_row_filter. Please find it in the attached
> > patchset.
>
> Test looks good.
Thanks. Added to three more files. I think we have covered all the
cases where filtering can occur.
PFA patches.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
0001-Report-output-plugin-statistics-in-pg_stat_-20250924.patch (text/x-patch, 42.6K) download
From a27c83fdf1f49a43844c1c4bcd763439e225f82d Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH 1/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 27 +++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 24 +++++-
.../replication/logical/logicalfuncs.c | 7 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 7 ++
src/backend/utils/adt/pgstatfuncs.c | 30 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 4 +
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
src/test/regress/expected/rules.out | 10 ++-
src/tools/pgindent/typedefs.list | 1 +
22 files changed, 290 insertions(+), 79 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..4834b3460a6 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..99f513902d3 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index f671a7d4b31..ea5c527644b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..3952f68e806 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,33 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data, in bytes,
+ sent downstream by the output plugin.
+ <function>OutputPluginWrite</function> will update this counter
+ if <literal>ctx->stats</literal> is initialized by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that are
+ filtered out by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 3f4a27a736e..fbe03ffd670 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1545,6 +1545,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1622,19 +1633,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1644,6 +1655,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transctions sent to
+ the decoding plugin. Hence this count is expected to be lesser than or
+ equal to <structfield>total_wal_txns</structfield>. The count is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The count is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index c77fa0234bb..9e8e32b5849 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,14 +1053,18 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index c68c0481f42..b26ac29e32f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,13 +1952,14 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1968,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1977,6 +1982,15 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.sent_txns = stats->sentTxns;
+ repSlotStat.sent_bytes = stats->sentBytes;
+ repSlotStat.filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +2002,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..788967e2ab1 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 4736f993c37..12579dff2c1 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4436,7 +4435,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 80540c017bd..339babbeb56 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -450,6 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
ALLOCSET_SMALL_SIZES);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -591,6 +592,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1469,7 +1471,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1487,15 +1492,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1505,6 +1519,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1560,7 +1575,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1688,6 +1706,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 59822f22b8d..d9217ce49aa 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..ed055324a99 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,13 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(sent_txns);
+ REPLSLOT_ACC(sent_bytes);
+ REPLSLOT_ACC(filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index c756c2bebaa..15bafe63b24 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2125,11 +2125,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2154,11 +2160,23 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->total_txns);
values[8] = Int64GetDatum(slotent->total_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[9] = Int64GetDatum(slotent->filtered_bytes);
+ values[10] = Int64GetDatum(slotent->sent_txns);
+ values[11] = Int64GetDatum(slotent->sent_bytes);
+ }
+ else
+ {
+ nulls[9] = true;
+ nulls[10] = true;
+ nulls[11] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[12] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 01eba3b5a19..9e4f6620214 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5687,9 +5687,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index f402b17295c..87afeaed8a5 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -395,6 +395,10 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_bytes;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter sent_txns;
+ PgStat_Counter sent_bytes;
+ PgStat_Counter filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index fa0745552f8..3ea2d9885b6 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -715,6 +715,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..b04a0d9f8db 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 35e8aad7701..2a401552a7a 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2132,17 +2132,21 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 3c80d49b67e..b97915c1697 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1830,6 +1830,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 5334620eef8f7b429594e6cf9dc97331eda2a8bd
--
2.34.1
0002-Address-second-round-of-comments-from-Shvet-20250924.patch (text/x-patch, 14.6K) download
From 95ddb15af81bca46e9d0739b96351167cad06e6c Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Tue, 23 Sep 2025 16:43:33 +0530
Subject: [PATCH 2/2] Address second round of comments from Shveta Malik
Add a test for plugin_filtered_bytes in logical replication case. We can
not test exact number of bytes filtered because of the unavoidable
background transaction activity which will be counted in the filtered
bytes.
---
doc/src/sgml/logicaldecoding.sgml | 13 ++++++------
src/backend/replication/logical/logical.c | 10 +++++-----
.../replication/logical/logicalfuncs.c | 1 +
src/backend/utils/activity/pgstat_replslot.c | 10 +++++-----
src/backend/utils/adt/pgstatfuncs.c | 10 +++++-----
src/include/pgstat.h | 10 +++++-----
src/test/recovery/t/006_logical_decoding.pl | 6 +++---
.../t/035_standby_logical_decoding.pl | 4 ++--
src/test/subscription/t/001_rep_changes.pl | 11 ++++++++++
src/test/subscription/t/010_truncate.pl | 20 +++++++++++++++++++
src/test/subscription/t/028_row_filter.pl | 11 ++++++++++
11 files changed, 75 insertions(+), 31 deletions(-)
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index 3952f68e806..c02d4a88d57 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -956,12 +956,13 @@ typedef struct OutputPluginStats
} OutputPluginStats;
</programlisting>
<literal>sentTxns</literal> is the number of transactions sent downstream
- by the output plugin. <literal>sentBytes</literal> is the amount of data, in bytes,
- sent downstream by the output plugin.
- <function>OutputPluginWrite</function> will update this counter
- if <literal>ctx->stats</literal> is initialized by the output plugin.
- <literal>filteredBytes</literal> is the size of changes, in bytes, that are
- filtered out by the output plugin. Function
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
<literal>ReorderBufferChangeSize</literal> may be used to find the size of
filtered <literal>ReorderBufferChange</literal>.
</para>
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index b26ac29e32f..1435873101f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1980,14 +1980,14 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_txns = rb->streamTxns;
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
if (stats)
{
repSlotStat.plugin_has_stats = true;
- repSlotStat.sent_txns = stats->sentTxns;
- repSlotStat.sent_bytes = stats->sentBytes;
- repSlotStat.filtered_bytes = stats->filteredBytes;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
}
else
repSlotStat.plugin_has_stats = false;
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 788967e2ab1..d2ab41de438 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -96,6 +96,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
*/
if (ctx->stats)
ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+
p->returned_rows++;
}
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ed055324a99..895940f4eb9 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -94,14 +94,14 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_txns);
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
statent->plugin_has_stats = repSlotStat->plugin_has_stats;
if (repSlotStat->plugin_has_stats)
{
- REPLSLOT_ACC(sent_txns);
- REPLSLOT_ACC(sent_bytes);
- REPLSLOT_ACC(filtered_bytes);
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
}
#undef REPLSLOT_ACC
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 15bafe63b24..588b49059b2 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2158,13 +2158,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[4] = Int64GetDatum(slotent->stream_txns);
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->total_txns);
- values[8] = Int64GetDatum(slotent->total_bytes);
+ values[7] = Int64GetDatum(slotent->total_wal_txns);
+ values[8] = Int64GetDatum(slotent->total_wal_bytes);
if (slotent->plugin_has_stats)
{
- values[9] = Int64GetDatum(slotent->filtered_bytes);
- values[10] = Int64GetDatum(slotent->sent_txns);
- values[11] = Int64GetDatum(slotent->sent_bytes);
+ values[9] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[10] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[11] = Int64GetDatum(slotent->plugin_sent_bytes);
}
else
{
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 87afeaed8a5..33a031c79b4 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -393,12 +393,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_txns;
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
bool plugin_has_stats;
- PgStat_Counter sent_txns;
- PgStat_Counter sent_bytes;
- PgStat_Counter filtered_bytes;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index b04a0d9f8db..92e42bec6a9 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,7 +212,7 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
qq(t|t|t),
qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
qq(t|t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index c9c182892cf..c8577794eec 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -575,7 +575,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -603,7 +603,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index ca55d8df50d..a7bee7fe5e4 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that plugin_filtered_bytes increases due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..c41ad317221 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. plugin_filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# plugin_filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the plugin_filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..039bf5ff5a0 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the plugin_filtered_bytes reflects that. We can not test the exact value of
+# plugin_filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-24 14:41 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-24 14:41 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Wed, Sep 24, 2025 at 05:28:44PM +0530, Ashutosh Bapat wrote:
> On Wed, Sep 24, 2025 at 2:38 PM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > On Wed, Sep 24, 2025 at 12:47 PM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > > On Wed, Sep 24, 2025 at 10:12 AM shveta malik <shveta.malik@gmail.com> wrote:
> > > >
> > > > I tested the flows with
> > > > a) logical replication slot and get-changes.
> > > > b) filtered data flows: pub-sub creation with row_filters, 'publish'
> > > > options. I tried to verify plugin fields as compared to total_wal*
> > > > fields.
> > > > c) reset flow.
> > > >
> > > > While tests for a and c are present already. I don't see tests for b
> > > > anywhere when it comes to stats. Do you think we shall add a test for
> > > > filtered data using row-filter somewhere?
> > >
> > > Added a test in 028_row_filter. Please find it in the attached
> > > patchset.
> >
> > Test looks good.
>
> Thanks. Added to three more files. I think we have covered all the
> cases where filtering can occur.
>
> PFA patches.
Thanks for the new version!
A few random comments:
=== 1
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>.
I found "The count" somehow ambiguous. What about "This statistic" instead?
=== 2
+ subtransactions. These transactions are subset of transctions sent to
s/transctions/transactions
=== 3
+ the decoding plugin. Hence this count is expected to be lesser than or
s/be lesser/be less/? (not 100% sure)
=== 4
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
Another approach could be to pass the change's size as an argument to the
callbacks? That would avoid to expose ReorderBufferChangeSize publicly.
=== 5
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
I was wondering if we need to free this in pg_decode_shutdown, but it looks
like it's done through FreeDecodingContext() anyway.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-25 04:46 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-25 04:46 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Sep 24, 2025 at 8:11 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Wed, Sep 24, 2025 at 05:28:44PM +0530, Ashutosh Bapat wrote:
> > On Wed, Sep 24, 2025 at 2:38 PM shveta malik <shveta.malik@gmail.com> wrote:
> > >
> > > On Wed, Sep 24, 2025 at 12:47 PM Ashutosh Bapat
> > > <ashutosh.bapat.oss@gmail.com> wrote:
> > > >
> > > > On Wed, Sep 24, 2025 at 10:12 AM shveta malik <shveta.malik@gmail.com> wrote:
> > > > >
> > > > > I tested the flows with
> > > > > a) logical replication slot and get-changes.
> > > > > b) filtered data flows: pub-sub creation with row_filters, 'publish'
> > > > > options. I tried to verify plugin fields as compared to total_wal*
> > > > > fields.
> > > > > c) reset flow.
> > > > >
> > > > > While tests for a and c are present already. I don't see tests for b
> > > > > anywhere when it comes to stats. Do you think we shall add a test for
> > > > > filtered data using row-filter somewhere?
> > > >
> > > > Added a test in 028_row_filter. Please find it in the attached
> > > > patchset.
> > >
> > > Test looks good.
> >
> > Thanks. Added to three more files. I think we have covered all the
> > cases where filtering can occur.
> >
> > PFA patches.
>
> Thanks for the new version!
>
> A few random comments:
>
> === 1
>
> + <row>
> + <entry role="catalog_table_entry"><para role="column_definition">
> + <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
> + </para>
> + <para>
> + Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
> + out by the output plugin and not sent downstream. Please note that it
> + does not include the changes filtered before a change is sent to
> + the output plugin, e.g. the changes filtered by origin. The count is
> + maintained by the output plugin mentioned in
> + <structfield>plugin</structfield>.
>
> I found "The count" somehow ambiguous. What about "This statistic" instead?
Existing fields use term "The counter". Changed "The count" to "The counter".
>
> === 2
>
> + subtransactions. These transactions are subset of transctions sent to
>
> s/transctions/transactions
Done.
>
> === 3
>
> + the decoding plugin. Hence this count is expected to be lesser than or
>
> s/be lesser/be less/? (not 100% sure)
Less than is correct. Fixed.
>
> === 4
>
> +extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
>
> Another approach could be to pass the change's size as an argument to the
> callbacks? That would avoid to expose ReorderBufferChangeSize publicly.
Do you see any problem in exposing ReorderBufferChangeSize(). It's a
pretty small function and may be quite handy to output plugins
otherwise as well. And we expose many ReorderBuffer related functions;
so this isn't the first.
If we were to do as you say, it will change other external facing APIs
like change_cb(). Output plugins will need to change their code
accordingly even when they don't want to support plugin statistics.
Given that we have made maintaining plugin statistics optional,
forcing API change does not make sense. For example, test_decoding
which does not filter anything would unnecessarily have to change its
code.
I considered adding a field size to ReorderBufferChange itself. But
that means we increase the amount of memory used in the reorder
buffer, which seems to have become prime estate these days. So
rejected that idea as well.
Advantage of this change is that the minimal cost of calculating the
size and maintaining the code change is incurred only when filtering
happens, by the plugins which want to filter and maintain statistics.
>
> === 5
>
> ctx->output_plugin_private = data;
> + ctx->stats = palloc0(sizeof(OutputPluginStats));
>
> I was wondering if we need to free this in pg_decode_shutdown, but it looks
> like it's done through FreeDecodingContext() anyway.
That's correct. Even output_plugin_private is freed when the decoding
memory context is freed.
Thanks for the review comments. I have addressed the comments in my
repository and the changes will be included in the next set of
patches.
Do you have any further review comments?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-25 13:01 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-25 13:01 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Thu, Sep 25, 2025 at 10:16:35AM +0530, Ashutosh Bapat wrote:
> On Wed, Sep 24, 2025 at 8:11 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > === 4
> >
> > +extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
> >
> > Another approach could be to pass the change's size as an argument to the
> > callbacks? That would avoid to expose ReorderBufferChangeSize publicly.
>
> Do you see any problem in exposing ReorderBufferChangeSize(). It's a
> pretty small function and may be quite handy to output plugins
> otherwise as well. And we expose many ReorderBuffer related functions;
> so this isn't the first.
Right. I don't see a problem per say, just thinking that the less we expose
publicly to be used by extensions/plugins, the better.
> If we were to do as you say, it will change other external facing APIs
> like change_cb(). Output plugins will need to change their code
> accordingly even when they don't want to support plugin statistics.
Correct.
> Given that we have made maintaining plugin statistics optional,
> forcing API change does not make sense. For example, test_decoding
> which does not filter anything would unnecessarily have to change its
> code.
That's right.
> I considered adding a field size to ReorderBufferChange itself. But
> that means we increase the amount of memory used in the reorder
> buffer, which seems to have become prime estate these days. So
> rejected that idea as well.
>
> Advantage of this change is that the minimal cost of calculating the
> size and maintaining the code change is incurred only when filtering
> happens, by the plugins which want to filter and maintain statistics.
Yes, anyway as it's unlikely that we have to fix a bug in a minor release that
would need a signature change to ReorderBufferChangeSize(), I think that's fine
as proposed.
> >
> > === 5
> >
> > ctx->output_plugin_private = data;
> > + ctx->stats = palloc0(sizeof(OutputPluginStats));
> >
> > I was wondering if we need to free this in pg_decode_shutdown, but it looks
> > like it's done through FreeDecodingContext() anyway.
>
> That's correct. Even output_plugin_private is freed when the decoding
> memory context is freed.
>
> Thanks for the review comments. I have addressed the comments in my
> repository and the changes will be included in the next set of
> patches.
Thanks!
> Do you have any further review comments?
Not right now. I'll give it another look by early next week the latest.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-26 11:13 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-26 11:13 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Thu, Sep 25, 2025 at 01:01:55PM +0000, Bertrand Drouvot wrote:
> Hi,
>
> On Thu, Sep 25, 2025 at 10:16:35AM +0530, Ashutosh Bapat wrote:
> > Do you have any further review comments?
>
> Not right now. I'll give it another look by early next week the latest.
>
=== 1
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
I was not sure where it's allocated, but looking at:
Breakpoint 1, pg_decode_startup (ctx=0x1ba853a0, opt=0x1ba85478, is_init=false) at test_decoding.c:164
164 bool enable_streaming = false;
(gdb) n
166 data = palloc0(sizeof(TestDecodingData));
(gdb)
167 data->context = AllocSetContextCreate(ctx->context,
(gdb)
170 data->include_xids = true;
(gdb)
171 data->include_timestamp = false;
(gdb)
172 data->skip_empty_xacts = false;
(gdb)
173 data->only_local = false;
(gdb)
175 ctx->output_plugin_private = data;
(gdb)
176 ctx->stats = palloc0(sizeof(OutputPluginStats));
(gdb)
178 opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
(gdb) p CurrentMemoryContext
$7 = (MemoryContext) 0x1ba852a0
(gdb) p (*CurrentMemoryContext).name
$8 = 0xe4057d "Logical decoding context"
(gdb) p ctx->context
$9 = (MemoryContext) 0x1ba852a0
I can see that CurrentMemoryContext is "ctx->context" so the palloc0 done here
are done in the right context.
=== 2
Playing with "has stats" a bit.
-- Issue 1:
Say, plugin has stats enabled and I get:
postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
plugin | plugin_sent_txns
----------------+------------------
pg_commit_info | 9
(1 row)
If the engine is shutdown and the plugin is now replaced by a version that
does not provide stats, then, right after startup, I still get:
postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
plugin | plugin_sent_txns
----------------+------------------
pg_commit_info | 9
(1 row)
And that will be the case until the plugin decodes something (so that
statent->plugin_has_stats gets replaced in pgstat_report_replslot()).
That's because plugin_has_stats is stored in PgStat_StatReplSlotEntry
and so it's restored from the stat file when the engine starts.
Now, let's do some inserts and decode:
postgres=# insert into t1 values ('a');
INSERT 0 1
postgres=# insert into t1 values ('a');
INSERT 0 1
postgres=# select * from pg_logical_slot_get_changes('logical_slot',NULL,NULL);
lsn | xid | data
------------+-----+-----------------------------------------------------------------------------------------
0/407121C0 | 766 | xid 766: lsn:0/40712190 inserts:1 deletes:0 updates:0 truncates:0 relations truncated:0
0/40712268 | 767 | xid 767: lsn:0/40712238 inserts:1 deletes:0 updates:0 truncates:0 relations truncated:0
(2 rows)
postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
plugin | plugin_sent_txns
----------------+------------------
pg_commit_info |
(1 row)
All good.
Issue 1 is that before any decoding happens, pg_stat_replication_slots is still
showing stale plugin statistics from a plugin that may no longer support stats.
I'm not sure how we could easily fix this issue, as we don't know the plugin's
stats capability until we actually use it.
-- Issue 2:
Let's shutdown, replace the plugin with a version that has stats enabled and
restart.
Same behavior as before:
postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
plugin | plugin_sent_txns
----------------+------------------
pg_commit_info |
(1 row)
Until pgstat_report_replslot() is not called, the statent->plugin_has_stats is
not updated. So it displays the stats as they were before the shutdown. But that's
not an issue in this case (when switching from non stats to stats).
Now, let's do some inserts and decode:
postgres=# insert into t1 values ('a');
INSERT 0 1
postgres=# select * from pg_logical_slot_get_changes('logical_slot',NULL,NULL);
lsn | xid | data
------------+-----+-----------------------------------------------------------------------------------------
0/407125B0 | 768 | xid 768: lsn:0/40712580 inserts:1 deletes:0 updates:0 truncates:0 relations truncated:0
(1 row)
and check the stats:
postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
plugin | plugin_sent_txns
----------------+------------------
pg_commit_info | 10
(1 row)
Now it reports 10, that's the 9 before we changed the plugin to not have stats
enabled plus this new one.
Issue 2: when switching from a non-stats plugin back to a stats-capable plugin, it
shows accumulated values from before the non-stats switch.
PFA attached a proposal to fix Issue 2.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachments:
fix_issue2.txt (text/plain, 1.5K) download
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 895940f4eb9..e4dbbf4f405 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -80,12 +80,17 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
PgStat_EntryRef *entry_ref;
PgStatShared_ReplSlot *shstatent;
PgStat_StatReplSlotEntry *statent;
+ bool previous_had_stats;
+ bool current_has_stats;
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_REPLSLOT, InvalidOid,
ReplicationSlotIndex(slot), false);
shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
statent = &shstatent->stats;
+ previous_had_stats = statent->plugin_has_stats;
+ current_has_stats = repSlotStat->plugin_has_stats;
+
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
REPLSLOT_ACC(spill_txns);
@@ -97,7 +102,15 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(total_wal_txns);
REPLSLOT_ACC(total_wal_bytes);
statent->plugin_has_stats = repSlotStat->plugin_has_stats;
- if (repSlotStat->plugin_has_stats)
+
+ /* Plugin no longer supports stats, reset counters */
+ if (previous_had_stats && !current_has_stats) {
+ statent->plugin_sent_txns = 0;
+ statent->plugin_sent_bytes = 0;
+ statent->plugin_filtered_bytes = 0;
+ }
+
+ if (current_has_stats)
{
REPLSLOT_ACC(plugin_sent_txns);
REPLSLOT_ACC(plugin_sent_bytes);
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-26 12:44 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-26 12:44 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Fri, Sep 26, 2025 at 4:43 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
>
> === 2
>
> Playing with "has stats" a bit.
>
> -- Issue 1:
>
Thanks for experiments! Thanks for bringing it up.
> Say, plugin has stats enabled and I get:
>
> postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
> plugin | plugin_sent_txns
> ----------------+------------------
> pg_commit_info | 9
> (1 row)
>
> If the engine is shutdown and the plugin is now replaced by a version that
> does not provide stats, then, right after startup, I still get:
>
> postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
> plugin | plugin_sent_txns
> ----------------+------------------
> pg_commit_info | 9
> (1 row)
>
> And that will be the case until the plugin decodes something (so that
> statent->plugin_has_stats gets replaced in pgstat_report_replslot()).
>
> That's because plugin_has_stats is stored in PgStat_StatReplSlotEntry
> and so it's restored from the stat file when the engine starts.
>
> Now, let's do some inserts and decode:
>
> postgres=# insert into t1 values ('a');
> INSERT 0 1
> postgres=# insert into t1 values ('a');
> INSERT 0 1
> postgres=# select * from pg_logical_slot_get_changes('logical_slot',NULL,NULL);
> lsn | xid | data
> ------------+-----+-----------------------------------------------------------------------------------------
> 0/407121C0 | 766 | xid 766: lsn:0/40712190 inserts:1 deletes:0 updates:0 truncates:0 relations truncated:0
> 0/40712268 | 767 | xid 767: lsn:0/40712238 inserts:1 deletes:0 updates:0 truncates:0 relations truncated:0
> (2 rows)
>
> postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
> plugin | plugin_sent_txns
> ----------------+------------------
> pg_commit_info |
> (1 row)
>
> All good.
>
> Issue 1 is that before any decoding happens, pg_stat_replication_slots is still
> showing stale plugin statistics from a plugin that may no longer support stats.
>
> I'm not sure how we could easily fix this issue, as we don't know the plugin's
> stats capability until we actually use it.
>
I don't think this is an issue. There is no way for the core to tell
whether the plugin will provide stats or not, unless it sets that
ctx->stats which happens in the startup callback. Till then it is
rightly providing the values accumulated so far. Once the decoding
starts, we know that the plugin is not providing any stats and we
don't display anything.
> -- Issue 2:
>
> Let's shutdown, replace the plugin with a version that has stats enabled and
> restart.
>
> Same behavior as before:
>
> postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
> plugin | plugin_sent_txns
> ----------------+------------------
> pg_commit_info |
> (1 row)
>
> Until pgstat_report_replslot() is not called, the statent->plugin_has_stats is
> not updated. So it displays the stats as they were before the shutdown. But that's
> not an issue in this case (when switching from non stats to stats).
>
> Now, let's do some inserts and decode:
>
> postgres=# insert into t1 values ('a');
> INSERT 0 1
> postgres=# select * from pg_logical_slot_get_changes('logical_slot',NULL,NULL);
> lsn | xid | data
> ------------+-----+-----------------------------------------------------------------------------------------
> 0/407125B0 | 768 | xid 768: lsn:0/40712580 inserts:1 deletes:0 updates:0 truncates:0 relations truncated:0
> (1 row)
>
> and check the stats:
>
> postgres=# select plugin,plugin_sent_txns from pg_stat_replication_slots ;
> plugin | plugin_sent_txns
> ----------------+------------------
> pg_commit_info | 10
> (1 row)
>
> Now it reports 10, that's the 9 before we changed the plugin to not have stats
> enabled plus this new one.
>
> Issue 2: when switching from a non-stats plugin back to a stats-capable plugin, it
> shows accumulated values from before the non-stats switch.
This too seems to be a non-issue to me. The stats in the view get
reset only when a user resets them. So we shouldn't wipe out the
already accumulated values just because the plugin stopped providing
it. If the plugin keeps flip-flopping and only partial statistics
provided by the plugin will be accumulated. That's the plugin's
responsibility. Realistically a plugin will either decide to provide
statistics in some version and then continue forever OR it will decide
against it. Flip-flopping won't happen in practice.
If at all we decide to reset the stats when the plugin does not
provide them, I think a better fix is to set them to 0 in
pgstat_report_replslot() independent of previous state of has_stats.
It will be more or less same CPU instructions. like below
if (repSlotStat->plugin_has_stats)
{
REPLSLOT_ACC(plugin_sent_txns);
REPLSLOT_ACC(plugin_sent_bytes);
REPLSLOT_ACC(plugin_filtered_bytes);
}
else
{
statent->plugin_sent_txns = 0;
statent->plugin_sent_bytes = 0;
statent->plugin_filtered_bytes = 0
}
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-26 16:58 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-26 16:58 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Fri, Sep 26, 2025 at 06:14:28PM +0530, Ashutosh Bapat wrote:
> On Fri, Sep 26, 2025 at 4:43 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> >
> > === 2
> >
> > Issue 1 is that before any decoding happens, pg_stat_replication_slots is still
> > showing stale plugin statistics from a plugin that may no longer support stats.
> >
> > I'm not sure how we could easily fix this issue, as we don't know the plugin's
> > stats capability until we actually use it.
> >
>
> I don't think this is an issue. There is no way for the core to tell
> whether the plugin will provide stats or not, unless it sets that
> ctx->stats which happens in the startup callback. Till then it is
> rightly providing the values accumulated so far. Once the decoding
> starts, we know that the plugin is not providing any stats and we
> don't display anything.
Yeah, I got the technical reasons, but I think there's a valid user experience
concern here: seeing statistics for a plugin that doesn't actually support
statistics is misleading.
What we need is a call to pgstat_report_replslot() to display stats that reflect
the current plugin behavior. We can't just call pgstat_report_replslot()
in say RestoreSlotFromDisk() because we really need the decoding to start.
So one idea could be to set a flag (per slot) when pgstat_report_replslot()
has been called (for good reasons) and check for this flag in
pg_stat_get_replication_slot().
If the flag is not set, then set the plugin fields to NULL.
If the flag is set, then display their values (like now).
And we should document that the plugin stats are not available (i.e are NULL)
until the decoding has valid stats to report after startup.
What do you think?
>
> > -- Issue 2:
> >
> > Now it reports 10, that's the 9 before we changed the plugin to not have stats
> > enabled plus this new one.
> >
> > Issue 2: when switching from a non-stats plugin back to a stats-capable plugin, it
> > shows accumulated values from before the non-stats switch.
>
> This too seems to be a non-issue to me. The stats in the view get
> reset only when a user resets them. So we shouldn't wipe out the
> already accumulated values just because the plugin stopped providing
> it. If the plugin keeps flip-flopping and only partial statistics
> provided by the plugin will be accumulated. That's the plugin's
> responsibility.
Okay but then I think that the plugin is missing some flexibility.
For example, how could the plugin set ctx->stats->sentTxns
to zero if it decides not to enable stats (while it was previously enable)?
Indeed, not enabling stats, means not doing
"ctx->stats = palloc0(sizeof(OutputPluginStats))" which means not having control
over the stats anymore.
So, with the current design, it has not other choice but having its previous
stats not reset to zero.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-09-29 07:24 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-09-29 07:24 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Fri, Sep 26, 2025 at 10:28 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> > >
> >
> > I don't think this is an issue. There is no way for the core to tell
> > whether the plugin will provide stats or not, unless it sets that
> > ctx->stats which happens in the startup callback. Till then it is
> > rightly providing the values accumulated so far. Once the decoding
> > starts, we know that the plugin is not providing any stats and we
> > don't display anything.
>
> Yeah, I got the technical reasons, but I think there's a valid user experience
> concern here: seeing statistics for a plugin that doesn't actually support
> statistics is misleading.
>
1. If the plugin never supported statistics, we will never report
stats. So nothing misleading there.
2. If the plugin starts supporting statistics and continues to do so,
we will report the stats since the time they are made available and
continue to do so. Nothing misleading there.
3. If the plugin starts supporting statistics and midway discontinues
its support, it already has a problem with backward compatibility.
Practically it would 1 or 2, which are working fine.
I don't think we will encounter case 3 practically. Do you have a
practical use case where a plugin would discontinue supporting stats?
Even in case 3, I think we need to consider the fact that these stats
are "cumulative". So if a plugin discontinues reporting stats, they
should go NULL only when the next accumulation action happens, not
before that.
> What we need is a call to pgstat_report_replslot() to display stats that reflect
> the current plugin behavior. We can't just call pgstat_report_replslot()
> in say RestoreSlotFromDisk() because we really need the decoding to start.
>
> So one idea could be to set a flag (per slot) when pgstat_report_replslot()
> has been called (for good reasons) and check for this flag in
> pg_stat_get_replication_slot().
>
> If the flag is not set, then set the plugin fields to NULL.
> If the flag is set, then display their values (like now).
This approach will have the same problem. Till
pgstat_report_replslot() is called, the old statistics will continue
to be shown.
>
> And we should document that the plugin stats are not available (i.e are NULL)
> until the decoding has valid stats to report after startup.
After "startup" would mislead users since then they will think that
the statistics will be NULL just before the decoding (re)starts.
The current documentation is " It is NULL when statistics is not
initialized or immediately after a reset or when not maintained by the
output plugin.". I think that covers all the cases.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-30 06:52 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-09-30 06:52 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Mon, Sep 29, 2025 at 12:54:24PM +0530, Ashutosh Bapat wrote:
> On Fri, Sep 26, 2025 at 10:28 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > > >
> > >
> > > I don't think this is an issue. There is no way for the core to tell
> > > whether the plugin will provide stats or not, unless it sets that
> > > ctx->stats which happens in the startup callback. Till then it is
> > > rightly providing the values accumulated so far. Once the decoding
> > > starts, we know that the plugin is not providing any stats and we
> > > don't display anything.
> >
> > Yeah, I got the technical reasons, but I think there's a valid user experience
> > concern here: seeing statistics for a plugin that doesn't actually support
> > statistics is misleading.
> >
>
> 3. If the plugin starts supporting statistics and midway discontinues
> its support, it already has a problem with backward compatibility.
>
> Practically it would 1 or 2, which are working fine.
>
> I don't think we will encounter case 3 practically. Do you have a
> practical use case where a plugin would discontinue supporting stats?
Not that I can think of currently. That looks unlikely but wanted to raise
the point though. Maybe others see a use case and/or have a different point
of view.
> > What we need is a call to pgstat_report_replslot() to display stats that reflect
> > the current plugin behavior. We can't just call pgstat_report_replslot()
> > in say RestoreSlotFromDisk() because we really need the decoding to start.
> >
> > So one idea could be to set a flag (per slot) when pgstat_report_replslot()
> > has been called (for good reasons) and check for this flag in
> > pg_stat_get_replication_slot().
> >
> > If the flag is not set, then set the plugin fields to NULL.
> > If the flag is set, then display their values (like now).
>
> This approach will have the same problem. Till
> pgstat_report_replslot() is called, the old statistics will continue
> to be shown.
I don't think so because the flag would not be set.
> > And we should document that the plugin stats are not available (i.e are NULL)
> > until the decoding has valid stats to report after startup.
>
> The current documentation is " It is NULL when statistics is not
> initialized or immediately after a reset or when not maintained by the
> output plugin.". I think that covers all the cases.
Do you think the doc covers the case we discussed above? i.e when a plugin
discontinue supporting stats, it would display stats until the decoding actually
starts.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-10-03 06:52 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-03 13:47 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2025-10-03 06:52 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Tue, Sep 30, 2025 at 12:22 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Mon, Sep 29, 2025 at 12:54:24PM +0530, Ashutosh Bapat wrote:
> > On Fri, Sep 26, 2025 at 10:28 PM Bertrand Drouvot
> > <bertranddrouvot.pg@gmail.com> wrote:
> > >
> > > > >
> > > >
> > > > I don't think this is an issue. There is no way for the core to tell
> > > > whether the plugin will provide stats or not, unless it sets that
> > > > ctx->stats which happens in the startup callback. Till then it is
> > > > rightly providing the values accumulated so far. Once the decoding
> > > > starts, we know that the plugin is not providing any stats and we
> > > > don't display anything.
> > >
> > > Yeah, I got the technical reasons, but I think there's a valid user experience
> > > concern here: seeing statistics for a plugin that doesn't actually support
> > > statistics is misleading.
> > >
> >
> > 3. If the plugin starts supporting statistics and midway discontinues
> > its support, it already has a problem with backward compatibility.
> >
> > Practically it would 1 or 2, which are working fine.
> >
> > I don't think we will encounter case 3 practically. Do you have a
> > practical use case where a plugin would discontinue supporting stats?
>
> Not that I can think of currently. That looks unlikely but wanted to raise
> the point though. Maybe others see a use case and/or have a different point
> of view.
>
> > > What we need is a call to pgstat_report_replslot() to display stats that reflect
> > > the current plugin behavior. We can't just call pgstat_report_replslot()
> > > in say RestoreSlotFromDisk() because we really need the decoding to start.
> > >
> > > So one idea could be to set a flag (per slot) when pgstat_report_replslot()
> > > has been called (for good reasons) and check for this flag in
> > > pg_stat_get_replication_slot().
> > >
> > > If the flag is not set, then set the plugin fields to NULL.
> > > If the flag is set, then display their values (like now).
> >
> > This approach will have the same problem. Till
> > pgstat_report_replslot() is called, the old statistics will continue
> > to be shown.
>
> I don't think so because the flag would not be set.
>
> > > And we should document that the plugin stats are not available (i.e are NULL)
> > > until the decoding has valid stats to report after startup.
> >
> > The current documentation is " It is NULL when statistics is not
> > initialized or immediately after a reset or when not maintained by the
> > output plugin.". I think that covers all the cases.
>
> Do you think the doc covers the case we discussed above? i.e when a plugin
> discontinue supporting stats, it would display stats until the decoding actually
> starts.
Here's patchset addressing two issues:
Issue 1: A plugin supports stats in version X. It stopped supporting
the stats in version X + 1. It again started supporting stats in
version X + 2. Plugin stats will be accumulated when it was at version
X. When X + 1 is loaded, the stats will continue to report the stats
accumulated (by version X) till the first startup_call for that
replication slot happens. If the user knows (from documentation say)
that X + 1 does not support stats, seeing statistics will mislead
them. We don't know whether there's a practical need to do so. A
plugin which flip-flops on stats is breaking backward compatibility. I
have added a note in documentation for plugin authors, warning them
that this isn't expected. I don't think it's worth adding complexity
in code to support such a case unless we see a practical need for the
same.
Issue 2: Once X + 2 is loaded, further statistics are accumulated on
the top of statistics accumulated by version X. Attached patch fixes
issue 2 by zero'ing out the stats when the plugin does not report the
statistics.
The patchset also addresses your earlier review comments.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
0001-Report-output-plugin-statistics-in-pg_stat_-20251003.patch (text/x-patch, 49.9K) download
From da8c610c0d2977f513fef25adb487ffd0199518d Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH 1/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 28 +++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 28 ++++++-
.../replication/logical/logicalfuncs.c | 8 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 11 ++-
src/backend/utils/adt/pgstatfuncs.c | 34 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 8 +-
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 10 ++-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 +++++
src/test/subscription/t/028_row_filter.pl | 11 +++
src/tools/pgindent/typedefs.list | 1 +
26 files changed, 344 insertions(+), 89 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..4834b3460a6 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..99f513902d3 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 36e77c69e1c..d06f6c3f92b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..c02d4a88d57 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,34 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 3f4a27a736e..fbe03ffd670 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1545,6 +1545,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1622,19 +1633,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1644,6 +1655,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transctions sent to
+ the decoding plugin. Hence this count is expected to be lesser than or
+ equal to <structfield>total_wal_txns</structfield>. The count is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The count is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index c77fa0234bb..9e8e32b5849 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,14 +1053,18 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index c68c0481f42..1435873101f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,13 +1952,14 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1968,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1975,8 +1980,17 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_txns = rb->streamTxns;
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +2002,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..d2ab41de438 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,14 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index a5e165fb123..840deb5a3b7 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4436,7 +4435,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 92eb17049c3..f87ab5e1d4b 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -450,6 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
ALLOCSET_SMALL_SIZES);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -591,6 +592,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1469,7 +1471,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1487,15 +1492,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1505,6 +1519,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1560,7 +1575,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1688,6 +1706,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 59822f22b8d..d9217ce49aa 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..895940f4eb9 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -94,8 +94,15 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_txns);
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index c756c2bebaa..588b49059b2 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2125,11 +2125,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2152,13 +2158,25 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[4] = Int64GetDatum(slotent->stream_txns);
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->total_txns);
- values[8] = Int64GetDatum(slotent->total_bytes);
+ values[7] = Int64GetDatum(slotent->total_wal_txns);
+ values[8] = Int64GetDatum(slotent->total_wal_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[9] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[10] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[11] = Int64GetDatum(slotent->plugin_sent_bytes);
+ }
+ else
+ {
+ nulls[9] = true;
+ nulls[10] = true;
+ nulls[11] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[12] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 01eba3b5a19..9e4f6620214 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5687,9 +5687,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index e4a59a30b8c..7c680c21f55 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -394,8 +394,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_txns;
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 91dc7e5e448..f5a4c35995c 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -715,6 +715,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..92e42bec6a9 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index c9c182892cf..c8577794eec 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -575,7 +575,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -603,7 +603,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 35e8aad7701..2a401552a7a 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2132,17 +2132,21 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index ca55d8df50d..a7bee7fe5e4 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that plugin_filtered_bytes increases due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..c41ad317221 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. plugin_filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# plugin_filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the plugin_filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..039bf5ff5a0 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the plugin_filtered_bytes reflects that. We can not test the exact value of
+# plugin_filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 37f26f6c6b7..02f984770f7 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1830,6 +1830,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 902c08887aa183100b161ef48f1a2434af079213
--
2.34.1
0002-Address-review-comments-from-Bertrand-20251003.patch (text/x-patch, 4.3K) download
From 4d3e61b362b794a99ca72cc8107d2ed72020fa04 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Thu, 25 Sep 2025 10:15:43 +0530
Subject: [PATCH 2/2] Address review comments from Bertrand
When the stats are not enabled, we should reset the plugin stats to 0, rather
than carrying over the stale stats from the time when the plugin was supporting
the stats. This does not matter if the plugin continues not to support
statistics forever. But in case it was supporting the stats once, discontinued
doing so at some point in time and then starts supporting the stats later,
accumulating the new stats based on the earlier accumulated stats could be
misleading.
Author: Ashutosh Bapat
---
doc/src/sgml/monitoring.sgml | 10 +++++-----
src/backend/utils/activity/pgstat_replslot.c | 7 +++++++
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index fbe03ffd670..4d414d71742 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1663,7 +1663,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
out by the output plugin and not sent downstream. Please note that it
does not include the changes filtered before a change is sent to
- the output plugin, e.g. the changes filtered by origin. The count is
+ the output plugin, e.g. the changes filtered by origin. The counter is
maintained by the output plugin mentioned in
<structfield>plugin</structfield>. It is NULL when statistics is not
initialized or immediately after a reset or when not maintained by the
@@ -1678,9 +1678,9 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<para>
Number of decoded transactions sent downstream for this slot. This
counts top-level transactions only, and is not incremented for
- subtransactions. These transactions are subset of transctions sent to
- the decoding plugin. Hence this count is expected to be lesser than or
- equal to <structfield>total_wal_txns</structfield>. The count is maintained
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>. The counter is maintained
by the output plugin mentioned in <structfield>plugin</structfield>. It
is NULL when statistics is not initialized or immediately after a reset or
when not maintained by the output plugin.
@@ -1694,7 +1694,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<para>
Amount of transaction changes sent downstream for this slot by the
output plugin after applying filtering and converting into its output
- format. The count is maintained by the output plugin mentioned in
+ format. The counter is maintained by the output plugin mentioned in
<structfield>plugin</structfield>. It is NULL when statistics is not
initialized or immediately after a reset or when not maintained by the
output plugin.
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 895940f4eb9..3e486fd28e4 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -88,6 +88,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
+#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
REPLSLOT_ACC(spill_txns);
REPLSLOT_ACC(spill_count);
REPLSLOT_ACC(spill_bytes);
@@ -103,6 +104,12 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(plugin_sent_bytes);
REPLSLOT_ACC(plugin_filtered_bytes);
}
+ else
+ {
+ REPLSLOT_SET_TO_ZERO(plugin_sent_txns);
+ REPLSLOT_SET_TO_ZERO(plugin_sent_bytes);
+ REPLSLOT_SET_TO_ZERO(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-10-03 13:47 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-06 05:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-10-03 13:47 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Fri, Oct 03, 2025 at 12:22:05PM +0530, Ashutosh Bapat wrote:
> Here's patchset addressing two issues:
Thanks for the patch update!
> I
> have added a note in documentation for plugin authors, warning them
> that this isn't expected.
What note are you referring to? (I'm failing to see it).
> I don't think it's worth adding complexity
> in code to support such a case unless we see a practical need for the
> same.
Sounds good.
> Issue 2: Once X + 2 is loaded, further statistics are accumulated on
> the top of statistics accumulated by version X. Attached patch fixes
> issue 2 by zero'ing out the stats when the plugin does not report the
> statistics.
+#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
It looks like that the associated "undef" is missing.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-03 13:47 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-10-06 05:02 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-24 09:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-10-06 05:02 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Fri, Oct 3, 2025 at 7:17 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Fri, Oct 03, 2025 at 12:22:05PM +0530, Ashutosh Bapat wrote:
> > Here's patchset addressing two issues:
>
> Thanks for the patch update!
>
> > I
> > have added a note in documentation for plugin authors, warning them
> > that this isn't expected.
>
> What note are you referring to? (I'm failing to see it).
Patch 0002, changes in logicaldecoding.sgml. I am a bit hesitant to
add more details as to what "misleading" means since mentioning so
might be seen as a documented behaviour and thus plugin authors
relying on it.
>
> > I don't think it's worth adding complexity
> > in code to support such a case unless we see a practical need for the
> > same.
>
> Sounds good.
>
>
> > Issue 2: Once X + 2 is loaded, further statistics are accumulated on
> > the top of statistics accumulated by version X. Attached patch fixes
> > issue 2 by zero'ing out the stats when the plugin does not report the
> > statistics.
>
> +#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
>
> It looks like that the associated "undef" is missing.
Good catch. Fixed.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
0001-Report-output-plugin-statistics-in-pg_stat_-20251006.patch (text/x-patch, 49.9K) download
From 8884d63f49b998e0b586a0e80f8e899811cd6d76 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH 1/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 28 +++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 28 ++++++-
.../replication/logical/logicalfuncs.c | 8 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 11 ++-
src/backend/utils/adt/pgstatfuncs.c | 34 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 8 +-
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 10 ++-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 +++++
src/test/subscription/t/028_row_filter.pl | 11 +++
src/tools/pgindent/typedefs.list | 1 +
26 files changed, 344 insertions(+), 89 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index de6dc416130..4834b3460a6 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | t | t
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | t | t
- regression_slot_stats3 | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes
-------------------------+------------+-------------+------------+-------------
- regression_slot_stats1 | t | t | f | f
- regression_slot_stats2 | t | t | f | f
- regression_slot_stats3 | t | t | f | f
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------
+ regression_slot_stats1 | t | t | f | f | | |
+ regression_slot_stats2 | t | t | f | f | | |
+ regression_slot_stats3 | t | t | f | f | | |
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index a022fe1bf07..99f513902d3 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count F
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 36e77c69e1c..d06f6c3f92b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..c02d4a88d57 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,34 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 3f4a27a736e..fbe03ffd670 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1545,6 +1545,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1622,19 +1633,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1644,6 +1655,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The count is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transctions sent to
+ the decoding plugin. Hence this count is expected to be lesser than or
+ equal to <structfield>total_wal_txns</structfield>. The count is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The count is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index c77fa0234bb..9e8e32b5849 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1053,14 +1053,18 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index c68c0481f42..1435873101f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,13 +1952,14 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1967,7 +1968,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamCount,
rb->streamBytes,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1975,8 +1980,17 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_txns = rb->streamTxns;
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1988,6 +2002,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..d2ab41de438 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,14 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index a5e165fb123..840deb5a3b7 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4436,7 +4435,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 92eb17049c3..f87ab5e1d4b 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -450,6 +450,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
ALLOCSET_SMALL_SIZES);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -591,6 +592,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1469,7 +1471,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1487,15 +1492,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1505,6 +1519,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1560,7 +1575,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1688,6 +1706,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 59822f22b8d..d9217ce49aa 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1573,6 +1573,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index ccfb11c49bf..895940f4eb9 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -94,8 +94,15 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_txns);
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index c756c2bebaa..588b49059b2 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2100,7 +2100,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2125,11 +2125,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2152,13 +2158,25 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[4] = Int64GetDatum(slotent->stream_txns);
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->total_txns);
- values[8] = Int64GetDatum(slotent->total_bytes);
+ values[7] = Int64GetDatum(slotent->total_wal_txns);
+ values[8] = Int64GetDatum(slotent->total_wal_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[9] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[10] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[11] = Int64GetDatum(slotent->plugin_sent_bytes);
+ }
+ else
+ {
+ nulls[9] = true;
+ nulls[10] = true;
+ nulls[11] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[9] = true;
+ nulls[12] = true;
else
- values[9] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 01eba3b5a19..9e4f6620214 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5687,9 +5687,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index e4a59a30b8c..7c680c21f55 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -394,8 +394,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_txns;
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 91dc7e5e448..f5a4c35995c 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -715,6 +715,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 2137c4e5e30..92e42bec6a9 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -212,10 +212,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -233,10 +233,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index c9c182892cf..c8577794eec 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -575,7 +575,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -603,7 +603,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 35e8aad7701..2a401552a7a 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2132,17 +2132,21 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
s.stream_txns,
s.stream_count,
s.stream_bytes,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index ca55d8df50d..a7bee7fe5e4 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that plugin_filtered_bytes increases due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..c41ad317221 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. plugin_filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# plugin_filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the plugin_filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..039bf5ff5a0 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the plugin_filtered_bytes reflects that. We can not test the exact value of
+# plugin_filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 37f26f6c6b7..02f984770f7 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1830,6 +1830,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 0c7f103028202cec94e12cbe45cebdb5c8fbc392
--
2.34.1
0002-Address-review-comments-from-Bertrand-20251006.patch (text/x-patch, 5.2K) download
From 72bb6a453e7e20239e0a900aeb555d9ab745d43e Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Thu, 25 Sep 2025 10:15:43 +0530
Subject: [PATCH 2/2] Address review comments from Bertrand
When the stats are not enabled, we should reset the plugin stats to 0, rather
than carrying over the stale stats from the time when the plugin was supporting
the stats. This does not matter if the plugin continues not to support
statistics forever. But in case it was supporting the stats once, discontinued
doing so at some point in time and then starts supporting the stats later,
accumulating the new stats based on the earlier accumulated stats could be
misleading.
Also add a note in the documentation mentioning that stats, once supported
should remain supported.
Author: Ashutosh Bapat
---
doc/src/sgml/logicaldecoding.sgml | 8 ++++++++
doc/src/sgml/monitoring.sgml | 10 +++++-----
src/backend/utils/activity/pgstat_replslot.c | 8 ++++++++
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index c02d4a88d57..0bf9ffbfd28 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -966,6 +966,14 @@ typedef struct OutputPluginStats
<literal>ReorderBufferChangeSize</literal> may be used to find the size of
filtered <literal>ReorderBufferChange</literal>.
</para>
+
+ <note>
+ <para>
+ Once a plugin starts reporting and maintaining these statistics, it is
+ not expected that they will discontinue doing so. If they do, the result
+ may be misleading because of the cumulative nature of these statistics.
+ </para>
+ </note>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index fbe03ffd670..4d414d71742 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1663,7 +1663,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
out by the output plugin and not sent downstream. Please note that it
does not include the changes filtered before a change is sent to
- the output plugin, e.g. the changes filtered by origin. The count is
+ the output plugin, e.g. the changes filtered by origin. The counter is
maintained by the output plugin mentioned in
<structfield>plugin</structfield>. It is NULL when statistics is not
initialized or immediately after a reset or when not maintained by the
@@ -1678,9 +1678,9 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<para>
Number of decoded transactions sent downstream for this slot. This
counts top-level transactions only, and is not incremented for
- subtransactions. These transactions are subset of transctions sent to
- the decoding plugin. Hence this count is expected to be lesser than or
- equal to <structfield>total_wal_txns</structfield>. The count is maintained
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>. The counter is maintained
by the output plugin mentioned in <structfield>plugin</structfield>. It
is NULL when statistics is not initialized or immediately after a reset or
when not maintained by the output plugin.
@@ -1694,7 +1694,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<para>
Amount of transaction changes sent downstream for this slot by the
output plugin after applying filtering and converting into its output
- format. The count is maintained by the output plugin mentioned in
+ format. The counter is maintained by the output plugin mentioned in
<structfield>plugin</structfield>. It is NULL when statistics is not
initialized or immediately after a reset or when not maintained by the
output plugin.
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 895940f4eb9..c3a2fe3d3f9 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -88,6 +88,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
+#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
REPLSLOT_ACC(spill_txns);
REPLSLOT_ACC(spill_count);
REPLSLOT_ACC(spill_bytes);
@@ -103,7 +104,14 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(plugin_sent_bytes);
REPLSLOT_ACC(plugin_filtered_bytes);
}
+ else
+ {
+ REPLSLOT_SET_TO_ZERO(plugin_sent_txns);
+ REPLSLOT_SET_TO_ZERO(plugin_sent_bytes);
+ REPLSLOT_SET_TO_ZERO(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
+#undef REPLSLOT_SET_TO_ZERO
pgstat_unlock_entry(entry_ref);
}
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-03 13:47 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-06 05:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-10-24 09:53 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-24 12:40 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-10-24 09:53 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Mon, Oct 6, 2025 at 10:32 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Fri, Oct 3, 2025 at 7:17 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > Hi,
> >
> > On Fri, Oct 03, 2025 at 12:22:05PM +0530, Ashutosh Bapat wrote:
> > > Here's patchset addressing two issues:
> >
> > Thanks for the patch update!
> >
> > > I
> > > have added a note in documentation for plugin authors, warning them
> > > that this isn't expected.
> >
> > What note are you referring to? (I'm failing to see it).
>
> Patch 0002, changes in logicaldecoding.sgml. I am a bit hesitant to
> add more details as to what "misleading" means since mentioning so
> might be seen as a documented behaviour and thus plugin authors
> relying on it.
>
> >
> > > I don't think it's worth adding complexity
> > > in code to support such a case unless we see a practical need for the
> > > same.
> >
> > Sounds good.
> >
> >
> > > Issue 2: Once X + 2 is loaded, further statistics are accumulated on
> > > the top of statistics accumulated by version X. Attached patch fixes
> > > issue 2 by zero'ing out the stats when the plugin does not report the
> > > statistics.
> >
> > +#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
> >
> > It looks like that the associated "undef" is missing.
>
> Good catch. Fixed.
>
Squashed patches into one and rebased.
--
Best Wishes,
Ashutosh Bapat
Attachments:
0001-Report-output-plugin-statistics-in-pg_stat_-20251024.patch (text/x-patch, 52.8K) download
From fdb428a07dce3de95103252f6334f2fee6650dcc Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH] Report output plugin statistics in pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
When the stats are disabled after being enabled for a while, the plugin
stats are reset to 0, rather than carrying over the stale stats from the
time when the plugin was supporting the stats. This does not matter if
the plugin continues not to support statistics forever. But in case it
was supporting the stats once, discontinued doing so at some point in
time and then starts supporting the stats later, accumulating the new
stats based on the earlier accumulated stats could be misleading.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 36 +++++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 28 ++++++-
.../replication/logical/logicalfuncs.c | 8 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 19 ++++-
src/backend/utils/adt/pgstatfuncs.c | 34 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 8 +-
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 10 ++-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 +++++
src/test/subscription/t/028_row_filter.pl | 11 +++
src/tools/pgindent/typedefs.list | 1 +
26 files changed, 360 insertions(+), 89 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index 28da9123cc8..0e5c5fa5b18 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | | | | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------+--------------------
+ regression_slot_stats1 | t | t | f | f | | | | t
+ regression_slot_stats2 | t | t | f | f | | | | t
+ regression_slot_stats3 | t | t | f | f | | | | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..d6bf3cde8b1 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 36e77c69e1c..d06f6c3f92b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..0bf9ffbfd28 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,42 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
+
+ <note>
+ <para>
+ Once a plugin starts reporting and maintaining these statistics, it is
+ not expected that they will discontinue doing so. If they do, the result
+ may be misleading because of the cumulative nature of these statistics.
+ </para>
+ </note>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index d5f0fb7ba7c..1ccf781f45e 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1549,6 +1549,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1637,19 +1648,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1659,6 +1670,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The counter is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>. The counter is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The counter is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 823776c1498..be91e9b01e4 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1067,6 +1067,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1074,8 +1075,11 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 93ed2eb368e..f0810f05153 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,6 +1952,7 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
@@ -1959,7 +1960,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1969,7 +1970,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1978,8 +1983,17 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1992,6 +2006,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..d2ab41de438 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,14 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index b57aef9916d..d336ef3a51f 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4458,7 +4457,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 942e1abdb58..4b35f2de6aa 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -473,6 +473,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
MemoryContextRegisterResetCallback(ctx->context, mcallback);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -614,6 +615,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1492,7 +1494,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1510,15 +1515,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1528,6 +1542,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1583,7 +1598,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1711,6 +1729,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 548eafa7a73..b0a5d4da7a7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1587,6 +1587,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index d210c261ac6..42ca13bd76a 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -88,6 +88,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
+#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
REPLSLOT_ACC(spill_txns);
REPLSLOT_ACC(spill_count);
REPLSLOT_ACC(spill_bytes);
@@ -95,9 +96,23 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(mem_exceeded_count);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
+ }
+ else
+ {
+ REPLSLOT_SET_TO_ZERO(plugin_sent_txns);
+ REPLSLOT_SET_TO_ZERO(plugin_sent_bytes);
+ REPLSLOT_SET_TO_ZERO(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
+#undef REPLSLOT_SET_TO_ZERO
pgstat_unlock_entry(entry_ref);
}
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 1fe33df2756..be8d30ca9c6 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2121,7 +2121,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 11
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2148,11 +2148,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2176,13 +2182,25 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
+ values[8] = Int64GetDatum(slotent->total_wal_txns);
+ values[9] = Int64GetDatum(slotent->total_wal_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[10] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[11] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[12] = Int64GetDatum(slotent->plugin_sent_bytes);
+ }
+ else
+ {
+ nulls[10] = true;
+ nulls[11] = true;
+ nulls[12] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[10] = true;
+ nulls[13] = true;
else
- values[10] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index eecb43ec6f0..11404660a56 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5691,9 +5691,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index bc8077cbae6..ae11f39dd3b 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -396,8 +396,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 3cbe106a3c7..382eba66a76 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -718,6 +718,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index f6c0a5bf649..be564b53bc6 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -215,10 +215,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -236,10 +236,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index ebe2fae1789..5f4df30d65a 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -577,7 +577,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -605,7 +605,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 16753b2e4c0..d77059ae186 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2142,6 +2142,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2149,11 +2150,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index 430c1246d14..7f37b6fe6c6 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that plugin_filtered_bytes increases due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..c41ad317221 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. plugin_filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# plugin_filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the plugin_filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..039bf5ff5a0 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the plugin_filtered_bytes reflects that. We can not test the exact value of
+# plugin_filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 43fe3bcd593..9e47d1ebe0e 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1833,6 +1833,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 14ee8e6403001c3788f2622cdcf81a8451502dc2
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-03 13:47 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-06 05:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-24 09:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-10-24 12:40 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: Bertrand Drouvot @ 2025-10-24 12:40 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On Fri, Oct 24, 2025 at 03:23:44PM +0530, Ashutosh Bapat wrote:
> On Mon, Oct 6, 2025 at 10:32 AM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Fri, Oct 3, 2025 at 7:17 PM Bertrand Drouvot
> > <bertranddrouvot.pg@gmail.com> wrote:
> > >
> > > > Issue 2: Once X + 2 is loaded, further statistics are accumulated on
> > > > the top of statistics accumulated by version X. Attached patch fixes
> > > > issue 2 by zero'ing out the stats when the plugin does not report the
> > > > statistics.
> > >
> > > +#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
> > >
> > > It looks like that the associated "undef" is missing.
> >
> > Good catch. Fixed.
> >
>
> Squashed patches into one and rebased.
Thanks for the new version!
LGTM except the plugin flip-flop behaviour that we discussed up-thread.
That said I don't think it hurts that much and maybe that's just me and others
don't have a concern with it (in that case that's fine by me).
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-10-27 10:20 ` shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-10-27 10:20 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Fri, Oct 3, 2025 at 12:22 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
>
> Here's patchset addressing two issues:
>
> Issue 1: A plugin supports stats in version X. It stopped supporting
> the stats in version X + 1. It again started supporting stats in
> version X + 2. Plugin stats will be accumulated when it was at version
> X. When X + 1 is loaded, the stats will continue to report the stats
> accumulated (by version X) till the first startup_call for that
> replication slot happens. If the user knows (from documentation say)
> that X + 1 does not support stats, seeing statistics will mislead
> them. We don't know whether there's a practical need to do so. A
> plugin which flip-flops on stats is breaking backward compatibility. I
> have added a note in documentation for plugin authors, warning them
> that this isn't expected. I don't think it's worth adding complexity
> in code to support such a case unless we see a practical need for the
> same.
I agree. The current Note saying 'result may be misleading' looks good to me.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-10-27 11:17 ` shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-10-27 11:17 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
Few comments:
1)
pgoutput_truncate:
if (nrelids > 0)
{
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_truncate(ctx->out,
xid,
nrelids,
relids,
change->data.truncate.cascade,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
It seems that filteredBytes are only counted for TRUNCATE when nrelids
is 0. Can nrelids only be 0 or same as nrelations?
The below code makes me think that nrelids can be any number between 0
and nrelations, depending on which relations are publishable and which
supports publishing TRUNCATE. If that’s true, shouldn’t we count
filteredBytes in each such skipped case?
if (!is_publishable_relation(relation))
continue;
relentry = get_rel_sync_entry(data, relation);
if (!relentry->pubactions.pubtruncate)
continue;
2)
+ int64 filteredBytes; /* amount of data from reoder buffer that was
reoder --> reorder
3)
One small nitpick:
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) +
sizeof(TransactionId);
The way sentBytes is updated here feels a bit unnatural; we’re adding
the lengths for values[2], then [0], and then [1]. Would it be cleaner
to introduce a len[3] array similar to the existing values[3] and
nulls[3] arrays? We could initialize len[i] alongside values[i], and
later just sum up all three elements when updating
ctx->stats->sentBytes. It would be easier to understand as well.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-10-28 07:15 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-10-28 07:15 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Mon, Oct 27, 2025 at 4:47 PM shveta malik <shveta.malik@gmail.com> wrote:
>
> Few comments:
>
> 1)
> pgoutput_truncate:
>
> if (nrelids > 0)
> {
> OutputPluginPrepareWrite(ctx, true);
> logicalrep_write_truncate(ctx->out,
> xid,
> nrelids,
> relids,
> change->data.truncate.cascade,
> change->data.truncate.restart_seqs);
> OutputPluginWrite(ctx, true);
> }
> + else
> + ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
> +
>
> It seems that filteredBytes are only counted for TRUNCATE when nrelids
> is 0. Can nrelids only be 0 or same as nrelations?
>
> The below code makes me think that nrelids can be any number between 0
> and nrelations, depending on which relations are publishable and which
> supports publishing TRUNCATE. If that’s true, shouldn’t we count
> filteredBytes in each such skipped case?
IIIUC, you are suggesting that we should add
ReorderBufferChangeSize(change) for every relation which is not part
of the publication or whose truncate is not published. I think that
won't be correct since it can lead to a situation where filtered bytes
> total bytes which should never happen. Even if there is a single
publishable relation whose truncate is published, the change should
not be considered as filtered since something would be output
downstream. Otherwise filtered bytes as well as sent bytes both will
be incremented causing an inconsistency (which would be hard to notice
since total bytes - filtered bytes has something to do with the sent
bytes but the exact correlation is hard to grasp in a formula).
We may increment filteredBytes by sizeof(OID) for every relation we
skip here OR by ReoderBufferChangeSize(change) if all the relations
are filtered, but that's too much dependent on how the WAL record is
encoded; and adding that dependency in an output plugin code seems
hard to manage.
If you are suggesting something else, maybe sharing actual code
changes would help.
>
>
> 2)
> + int64 filteredBytes; /* amount of data from reoder buffer that was
>
> reoder --> reorder
Done.
>
> 3)
> One small nitpick:
>
> + /*
> + * If output plugin has chosen to maintain its stats, update the amount of
> + * data sent downstream.
> + */
> + if (ctx->stats)
> + ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) +
> sizeof(TransactionId);
>
> The way sentBytes is updated here feels a bit unnatural; we’re adding
> the lengths for values[2], then [0], and then [1]. Would it be cleaner
> to introduce a len[3] array similar to the existing values[3] and
> nulls[3] arrays? We could initialize len[i] alongside values[i], and
> later just sum up all three elements when updating
> ctx->stats->sentBytes. It would be easier to understand as well.
Instead of an array of length 3, we could keep a counter sentBytes to
accumulate all lengths. It will be assigned to ctx->stats->sentBytes
at the end if ctx->stats != NULL. But that might appear as if we are
performing additions even if it won't be used ultimately. That's not
true, since this plugin will always maintain stats. Changed that way.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
0002-Address-Shveta-s-comments-20251028.patch (text/x-patch, 2.5K) download
From 287217cf4aefeee0461bb77aa3377804752bc6e0 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Tue, 28 Oct 2025 12:42:04 +0530
Subject: [PATCH 2/2] Address Shveta's comments
---
src/backend/replication/logical/logicalfuncs.c | 6 +++++-
src/include/replication/output_plugin.h | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index d2ab41de438..55e02e7ee21 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 sentBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ sentBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ sentBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,6 +90,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ sentBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
@@ -95,7 +99,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
* data sent downstream.
*/
if (ctx->stats)
- ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+ ctx->stats->sentBytes += sentBytes;
p->returned_rows++;
}
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 02018f0593c..4cc939e6c98 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -38,7 +38,7 @@ typedef struct OutputPluginStats
int64 sentTxns; /* number of transactions decoded and sent
* downstream */
int64 sentBytes; /* amount of data decoded and sent downstream */
- int64 filteredBytes; /* amount of data from reoder buffer that was
+ int64 filteredBytes; /* amount of data from reorder buffer that was
* filtered out by the output plugin */
} OutputPluginStats;
--
2.34.1
0001-Report-output-plugin-statistics-in-pg_stat_-20251028.patch (text/x-patch, 52.8K) download
From e353db4c93be08371c6a949d86c33c5bad41bb78 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH 1/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
When the stats are disabled after being enabled for a while, the plugin
stats are reset to 0, rather than carrying over the stale stats from the
time when the plugin was supporting the stats. This does not matter if
the plugin continues not to support statistics forever. But in case it
was supporting the stats once, discontinued doing so at some point in
time and then starts supporting the stats later, accumulating the new
stats based on the earlier accumulated stats could be misleading.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 36 +++++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 28 ++++++-
.../replication/logical/logicalfuncs.c | 8 ++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 21 +++++
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 19 ++++-
src/backend/utils/adt/pgstatfuncs.c | 34 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 8 +-
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 10 ++-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 +++++
src/test/subscription/t/028_row_filter.pl | 11 +++
src/tools/pgindent/typedefs.list | 1 +
26 files changed, 360 insertions(+), 89 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index 28da9123cc8..0e5c5fa5b18 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | | | | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------+--------------------
+ regression_slot_stats1 | t | t | f | f | | | | t
+ regression_slot_stats2 | t | t | f | f | | | | t
+ regression_slot_stats3 | t | t | f | f | | | | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..d6bf3cde8b1 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 36e77c69e1c..d06f6c3f92b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..0bf9ffbfd28 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,42 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
+
+ <note>
+ <para>
+ Once a plugin starts reporting and maintaining these statistics, it is
+ not expected that they will discontinue doing so. If they do, the result
+ may be misleading because of the cumulative nature of these statistics.
+ </para>
+ </note>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index d5f0fb7ba7c..1ccf781f45e 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1549,6 +1549,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1637,19 +1648,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1659,6 +1670,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The counter is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>. The counter is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The counter is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 823776c1498..be91e9b01e4 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1067,6 +1067,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1074,8 +1075,11 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 93ed2eb368e..f0810f05153 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,6 +1952,7 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
@@ -1959,7 +1960,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1969,7 +1970,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1978,8 +1983,17 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1992,6 +2006,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..d2ab41de438 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -89,6 +89,14 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index b57aef9916d..d336ef3a51f 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4458,7 +4457,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 942e1abdb58..4b35f2de6aa 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -473,6 +473,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
MemoryContextRegisterResetCallback(ctx->context, mcallback);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -614,6 +615,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1492,7 +1494,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1510,15 +1515,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1528,6 +1542,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1583,7 +1598,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1711,6 +1729,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 548eafa7a73..b0a5d4da7a7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1587,6 +1587,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index d210c261ac6..42ca13bd76a 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -88,6 +88,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
+#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
REPLSLOT_ACC(spill_txns);
REPLSLOT_ACC(spill_count);
REPLSLOT_ACC(spill_bytes);
@@ -95,9 +96,23 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(mem_exceeded_count);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
+ }
+ else
+ {
+ REPLSLOT_SET_TO_ZERO(plugin_sent_txns);
+ REPLSLOT_SET_TO_ZERO(plugin_sent_bytes);
+ REPLSLOT_SET_TO_ZERO(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
+#undef REPLSLOT_SET_TO_ZERO
pgstat_unlock_entry(entry_ref);
}
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 1fe33df2756..be8d30ca9c6 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2121,7 +2121,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 11
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2148,11 +2148,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2176,13 +2182,25 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
+ values[8] = Int64GetDatum(slotent->total_wal_txns);
+ values[9] = Int64GetDatum(slotent->total_wal_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[10] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[11] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[12] = Int64GetDatum(slotent->plugin_sent_bytes);
+ }
+ else
+ {
+ nulls[10] = true;
+ nulls[11] = true;
+ nulls[12] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[10] = true;
+ nulls[13] = true;
else
- values[10] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index eecb43ec6f0..11404660a56 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5691,9 +5691,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index bc8077cbae6..ae11f39dd3b 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -396,8 +396,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..02018f0593c 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reoder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 3cbe106a3c7..382eba66a76 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -718,6 +718,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index f6c0a5bf649..be564b53bc6 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -215,10 +215,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -236,10 +236,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index ebe2fae1789..5f4df30d65a 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -577,7 +577,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -605,7 +605,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 16753b2e4c0..d77059ae186 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2142,6 +2142,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2149,11 +2150,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index 430c1246d14..7f37b6fe6c6 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that plugin_filtered_bytes increases due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..c41ad317221 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. plugin_filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# plugin_filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the plugin_filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..039bf5ff5a0 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the plugin_filtered_bytes reflects that. We can not test the exact value of
+# plugin_filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index bb4e1b37005..66678b11066 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1832,6 +1832,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: 3e8e05596a020f043f1efd6406e4511ea85170bd
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-10-29 03:43 ` shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-10-29 03:43 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Tue, Oct 28, 2025 at 12:46 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Mon, Oct 27, 2025 at 4:47 PM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > Few comments:
> >
> > 1)
> > pgoutput_truncate:
> >
> > if (nrelids > 0)
> > {
> > OutputPluginPrepareWrite(ctx, true);
> > logicalrep_write_truncate(ctx->out,
> > xid,
> > nrelids,
> > relids,
> > change->data.truncate.cascade,
> > change->data.truncate.restart_seqs);
> > OutputPluginWrite(ctx, true);
> > }
> > + else
> > + ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
> > +
> >
> > It seems that filteredBytes are only counted for TRUNCATE when nrelids
> > is 0. Can nrelids only be 0 or same as nrelations?
> >
> > The below code makes me think that nrelids can be any number between 0
> > and nrelations, depending on which relations are publishable and which
> > supports publishing TRUNCATE. If that’s true, shouldn’t we count
> > filteredBytes in each such skipped case?
>
> IIIUC, you are suggesting that we should add
> ReorderBufferChangeSize(change) for every relation which is not part
> of the publication or whose truncate is not published.
No, that will be wrong.
> I think that
> won't be correct since it can lead to a situation where filtered bytes
> > total bytes which should never happen. Even if there is a single
> publishable relation whose truncate is published, the change should
> not be considered as filtered since something would be output
> downstream.
Yes, the entire change should not be treated as filtered. The idea is
that, for example, if there are 20 relations belonging to different
publications and only one of them supports publishing TRUNCATE, then
when a TRUNCATE is triggered on all, the data for that one relation
should be counted as sent (which is currently happening based on
nrelids), while the data for the remaining 19 should be considered
filtered — which is not happening right now.
> Otherwise filtered bytes as well as sent bytes both will
> be incremented causing an inconsistency (which would be hard to notice
> since total bytes - filtered bytes has something to do with the sent
> bytes but the exact correlation is hard to grasp in a formula).
>
> We may increment filteredBytes by sizeof(OID) for every relation we
> skip here OR by ReoderBufferChangeSize(change) if all the relations
> are filtered, but that's too much dependent on how the WAL record is
> encoded; and adding that dependency in an output plugin code seems
> hard to manage.
>
Yes, that was the idea, to increment filteredBytes in this way. But I
see your point. I can’t think of a better solution at the moment. If
you also don’t have any better ideas, then at least adding a comment
in this function would be helpful. Right now, it looks like we
overlooked the fact that some relationships should contribute to
filteredBytes while others should go to sentBytes.
> If you are suggesting something else, maybe sharing actual code
> changes would help.
>
> >
> >
> > 2)
> > + int64 filteredBytes; /* amount of data from reoder buffer that was
> >
> > reoder --> reorder
>
> Done.
>
> >
> > 3)
> > One small nitpick:
> >
> > + /*
> > + * If output plugin has chosen to maintain its stats, update the amount of
> > + * data sent downstream.
> > + */
> > + if (ctx->stats)
> > + ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) +
> > sizeof(TransactionId);
> >
> > The way sentBytes is updated here feels a bit unnatural; we’re adding
> > the lengths for values[2], then [0], and then [1]. Would it be cleaner
> > to introduce a len[3] array similar to the existing values[3] and
> > nulls[3] arrays? We could initialize len[i] alongside values[i], and
> > later just sum up all three elements when updating
> > ctx->stats->sentBytes. It would be easier to understand as well.
>
> Instead of an array of length 3, we could keep a counter sentBytes to
> accumulate all lengths. It will be assigned to ctx->stats->sentBytes
> at the end if ctx->stats != NULL. But that might appear as if we are
> performing additions even if it won't be used ultimately. That's not
> true, since this plugin will always maintain stats. Changed that way.
>
Looks good.
Apart from the above discussion, I have no more comments on this patch.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-10-29 14:55 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-10-29 14:55 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Wed, Oct 29, 2025 at 9:14 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Tue, Oct 28, 2025 at 12:46 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Mon, Oct 27, 2025 at 4:47 PM shveta malik <shveta.malik@gmail.com> wrote:
> > >
> > > Few comments:
> > >
> > > 1)
> > > pgoutput_truncate:
> > >
> > > if (nrelids > 0)
> > > {
> > > OutputPluginPrepareWrite(ctx, true);
> > > logicalrep_write_truncate(ctx->out,
> > > xid,
> > > nrelids,
> > > relids,
> > > change->data.truncate.cascade,
> > > change->data.truncate.restart_seqs);
> > > OutputPluginWrite(ctx, true);
> > > }
> > > + else
> > > + ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
> > > +
> > >
> > > It seems that filteredBytes are only counted for TRUNCATE when nrelids
> > > is 0. Can nrelids only be 0 or same as nrelations?
> > >
> > > The below code makes me think that nrelids can be any number between 0
> > > and nrelations, depending on which relations are publishable and which
> > > supports publishing TRUNCATE. If that’s true, shouldn’t we count
> > > filteredBytes in each such skipped case?
> >
> > IIIUC, you are suggesting that we should add
> > ReorderBufferChangeSize(change) for every relation which is not part
> > of the publication or whose truncate is not published.
>
> No, that will be wrong.
>
> > I think that
> > won't be correct since it can lead to a situation where filtered bytes
> > > total bytes which should never happen. Even if there is a single
> > publishable relation whose truncate is published, the change should
> > not be considered as filtered since something would be output
> > downstream.
>
> Yes, the entire change should not be treated as filtered. The idea is
> that, for example, if there are 20 relations belonging to different
> publications and only one of them supports publishing TRUNCATE, then
> when a TRUNCATE is triggered on all, the data for that one relation
> should be counted as sent (which is currently happening based on
> nrelids), while the data for the remaining 19 should be considered
> filtered — which is not happening right now.
>
> > Otherwise filtered bytes as well as sent bytes both will
> > be incremented causing an inconsistency (which would be hard to notice
> > since total bytes - filtered bytes has something to do with the sent
> > bytes but the exact correlation is hard to grasp in a formula).
> >
> > We may increment filteredBytes by sizeof(OID) for every relation we
> > skip here OR by ReoderBufferChangeSize(change) if all the relations
> > are filtered, but that's too much dependent on how the WAL record is
> > encoded; and adding that dependency in an output plugin code seems
> > hard to manage.
> >
>
> Yes, that was the idea, to increment filteredBytes in this way. But I
> see your point. I can’t think of a better solution at the moment. If
> you also don’t have any better ideas, then at least adding a comment
> in this function would be helpful. Right now, it looks like we
> overlooked the fact that some relationships should contribute to
> filteredBytes while others should go to sentBytes.
I noticed that we do something similar while filtering columns. I
think we need to add a comment in that code as well. How about
something like below?
diff --git a/src/backend/replication/pgoutput/pgoutput.c
b/src/backend/replication/pgoutput/pgoutput.c
index 4b35f2de6aa..f2d6e20a702 100644
inline patch 1: src/backend/replication/pgoutput/pgoutput.c (+0/-0 lines) download inline-1.patch
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -1621,7 +1621,12 @@ pgoutput_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
OutputPluginPrepareWrite(ctx, true);
- /* Send the data */
+ /*
+ * Send the data. Even if we end up filtering some columns
while sending the
+ * message, we won't consider the change, as a whole, to be
filtered out.
+ * Instead the filtered columns will be reflected as a smaller sentBytes
+ * count.
+ */
switch (action)
{
case REORDER_BUFFER_CHANGE_INSERT:
@@ -1728,6 +1733,13 @@ pgoutput_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
change->data.truncate.cascade,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
+
+ /*
+ * Even if we filtered out some relations, we still
send a TRUNCATE
+ * message for the remaining relations. Since the
change, as a whole, is
+ * not filtered out, we don't count modify
filteredBytes. The filtered
+ * out relations will be reflected as a smaller sentBytes count.
+ */
}
else
ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-10-30 03:38 ` shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-10-30 03:38 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Wed, Oct 29, 2025 at 8:25 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Wed, Oct 29, 2025 at 9:14 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > On Tue, Oct 28, 2025 at 12:46 PM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > > On Mon, Oct 27, 2025 at 4:47 PM shveta malik <shveta.malik@gmail.com> wrote:
> > > >
> > > > Few comments:
> > > >
> > > > 1)
> > > > pgoutput_truncate:
> > > >
> > > > if (nrelids > 0)
> > > > {
> > > > OutputPluginPrepareWrite(ctx, true);
> > > > logicalrep_write_truncate(ctx->out,
> > > > xid,
> > > > nrelids,
> > > > relids,
> > > > change->data.truncate.cascade,
> > > > change->data.truncate.restart_seqs);
> > > > OutputPluginWrite(ctx, true);
> > > > }
> > > > + else
> > > > + ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
> > > > +
> > > >
> > > > It seems that filteredBytes are only counted for TRUNCATE when nrelids
> > > > is 0. Can nrelids only be 0 or same as nrelations?
> > > >
> > > > The below code makes me think that nrelids can be any number between 0
> > > > and nrelations, depending on which relations are publishable and which
> > > > supports publishing TRUNCATE. If that’s true, shouldn’t we count
> > > > filteredBytes in each such skipped case?
> > >
> > > IIIUC, you are suggesting that we should add
> > > ReorderBufferChangeSize(change) for every relation which is not part
> > > of the publication or whose truncate is not published.
> >
> > No, that will be wrong.
> >
> > > I think that
> > > won't be correct since it can lead to a situation where filtered bytes
> > > > total bytes which should never happen. Even if there is a single
> > > publishable relation whose truncate is published, the change should
> > > not be considered as filtered since something would be output
> > > downstream.
> >
> > Yes, the entire change should not be treated as filtered. The idea is
> > that, for example, if there are 20 relations belonging to different
> > publications and only one of them supports publishing TRUNCATE, then
> > when a TRUNCATE is triggered on all, the data for that one relation
> > should be counted as sent (which is currently happening based on
> > nrelids), while the data for the remaining 19 should be considered
> > filtered — which is not happening right now.
> >
> > > Otherwise filtered bytes as well as sent bytes both will
> > > be incremented causing an inconsistency (which would be hard to notice
> > > since total bytes - filtered bytes has something to do with the sent
> > > bytes but the exact correlation is hard to grasp in a formula).
> > >
> > > We may increment filteredBytes by sizeof(OID) for every relation we
> > > skip here OR by ReoderBufferChangeSize(change) if all the relations
> > > are filtered, but that's too much dependent on how the WAL record is
> > > encoded; and adding that dependency in an output plugin code seems
> > > hard to manage.
> > >
> >
> > Yes, that was the idea, to increment filteredBytes in this way. But I
> > see your point. I can’t think of a better solution at the moment. If
> > you also don’t have any better ideas, then at least adding a comment
> > in this function would be helpful. Right now, it looks like we
> > overlooked the fact that some relationships should contribute to
> > filteredBytes while others should go to sentBytes.
>
> I noticed that we do something similar while filtering columns. I
> think we need to add a comment in that code as well. How about
> something like below?
>
> diff --git a/src/backend/replication/pgoutput/pgoutput.c
> b/src/backend/replication/pgoutput/pgoutput.c
> index 4b35f2de6aa..f2d6e20a702 100644
> --- a/src/backend/replication/pgoutput/pgoutput.c
> +++ b/src/backend/replication/pgoutput/pgoutput.c
> @@ -1621,7 +1621,12 @@ pgoutput_change(LogicalDecodingContext *ctx,
> ReorderBufferTXN *txn,
>
> OutputPluginPrepareWrite(ctx, true);
>
> - /* Send the data */
> + /*
> + * Send the data. Even if we end up filtering some columns
> while sending the
> + * message, we won't consider the change, as a whole, to be
> filtered out.
> + * Instead the filtered columns will be reflected as a smaller sentBytes
> + * count.
> + */
> switch (action)
> {
> case REORDER_BUFFER_CHANGE_INSERT:
> @@ -1728,6 +1733,13 @@ pgoutput_truncate(LogicalDecodingContext *ctx,
> ReorderBufferTXN *txn,
>
> change->data.truncate.cascade,
>
> change->data.truncate.restart_seqs);
> OutputPluginWrite(ctx, true);
> +
> + /*
> + * Even if we filtered out some relations, we still
> send a TRUNCATE
> + * message for the remaining relations. Since the
> change, as a whole, is
> + * not filtered out, we don't count modify
> filteredBytes. The filtered
> + * out relations will be reflected as a smaller sentBytes count.
> + */
> }
> else
> ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
>
> + * not filtered out, we don't count modify filteredBytes. The filtered
Something is wrong in this sentence.
Also, regarding "The filtered out relations will be reflected as a
smaller sentBytes count."
Can you please point me to the code where it happens? From what I have
understood, pgoutput_truncate() completely skips the relations which
do not support publishing truncate. Then it sends 'BEGIN', then
schema info of non-filtered relations and then TRUNCATE for
non-filtered relations (based on nrelids).
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-11-03 06:53 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-11-03 06:53 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Thu, Oct 30, 2025 at 9:08 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
>
> > + * not filtered out, we don't count modify filteredBytes. The filtered
>
> Something is wrong in this sentence.
:), here's better one
/*
* Even if we filtered out some relations, we still send a TRUNCATE
* message for the remaining relations. Since the change, as a whole, is
* not filtered out we don't increment filteredBytes. The filtered
* out relations will be reflected as a smaller sentBytes count.
*/
>
> Also, regarding "The filtered out relations will be reflected as a
> smaller sentBytes count."
> Can you please point me to the code where it happens? From what I have
> understood, pgoutput_truncate() completely skips the relations which
> do not support publishing truncate. Then it sends 'BEGIN', then
> schema info of non-filtered relations and then TRUNCATE for
> non-filtered relations (based on nrelids).
Let's take an example. Assume the TRUNCATE WAL record had relids X, Y,
Z and W. Out of those X and Y were filtered out. Then the message sent
to the downstream will have only Z, W, let's say "TRUNCATE Z W" - 12
bytes (hypothetically). So sentBytes will be incremented by 12.
However, if no relation was filtered, the message would be "TRUNCATE X
Y Z W" ~ 16 bytes and thus sentBytes will be incremented by 16 bytes.
Thus when the relations are filtered from the truncate message,
sentBytes is incremented by a smaller value than those when no
relations are filtered. So, even if filteredBytes is same in both
cases (filtered some relations vs no relation was filtered), sentBytes
indicates the difference. Similarly for column level filtering.
However, reading this again, it seems adding more confusion than
reducing it. So I propose to just add comment
in pgoutput_truncate()
/*
* Even if we filtered out some relations, we still send a TRUNCATE
* message for the remaining relations. Since the change, as a whole, is
* not filtered out we don't increment filteredBytes.
*/
and in pgoutput_change
/*
* Send the data. Even if we end up filtering some columns while sending the
* message, we won't consider the change, as a whole, to be filtered out. Hence
* won't increment the filteredBytes.
*/
Does that look good?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-11-03 09:54 ` shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: shveta malik @ 2025-11-03 09:54 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Mon, Nov 3, 2025 at 12:23 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Thu, Oct 30, 2025 at 9:08 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> > >
> >
> > > + * not filtered out, we don't count modify filteredBytes. The filtered
> >
> > Something is wrong in this sentence.
>
> :), here's better one
>
> /*
> * Even if we filtered out some relations, we still send a TRUNCATE
> * message for the remaining relations. Since the change, as a whole, is
> * not filtered out we don't increment filteredBytes. The filtered
> * out relations will be reflected as a smaller sentBytes count.
> */
>
> >
> > Also, regarding "The filtered out relations will be reflected as a
> > smaller sentBytes count."
> > Can you please point me to the code where it happens? From what I have
> > understood, pgoutput_truncate() completely skips the relations which
> > do not support publishing truncate. Then it sends 'BEGIN', then
> > schema info of non-filtered relations and then TRUNCATE for
> > non-filtered relations (based on nrelids).
>
> Let's take an example. Assume the TRUNCATE WAL record had relids X, Y,
> Z and W. Out of those X and Y were filtered out. Then the message sent
> to the downstream will have only Z, W, let's say "TRUNCATE Z W" - 12
> bytes (hypothetically). So sentBytes will be incremented by 12.
> However, if no relation was filtered, the message would be "TRUNCATE X
> Y Z W" ~ 16 bytes and thus sentBytes will be incremented by 16 bytes.
> Thus when the relations are filtered from the truncate message,
> sentBytes is incremented by a smaller value than those when no
> relations are filtered. So, even if filteredBytes is same in both
> cases (filtered some relations vs no relation was filtered), sentBytes
> indicates the difference.
I understand the point, but I didn’t find the message clearly reflecting it.
> Similarly for column level filtering.
> However, reading this again, it seems adding more confusion than
> reducing it.
Right.
> So I propose to just add comment
>
> in pgoutput_truncate()
> /*
> * Even if we filtered out some relations, we still send a TRUNCATE
> * message for the remaining relations. Since the change, as a whole, is
> * not filtered out we don't increment filteredBytes.
> */
>
> and in pgoutput_change
> /*
> * Send the data. Even if we end up filtering some columns while sending the
> * message, we won't consider the change, as a whole, to be filtered out. Hence
> * won't increment the filteredBytes.
> */
>
> Does that look good?
Yes. Works for me.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
@ 2025-11-03 14:23 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-11-03 14:23 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Mon, Nov 3, 2025 at 3:25 PM shveta malik <shveta.malik@gmail.com> wrote:
>
> > So I propose to just add comment
> >
> > in pgoutput_truncate()
> > /*
> > * Even if we filtered out some relations, we still send a TRUNCATE
> > * message for the remaining relations. Since the change, as a whole, is
> > * not filtered out we don't increment filteredBytes.
> > */
> >
> > and in pgoutput_change
> > /*
> > * Send the data. Even if we end up filtering some columns while sending the
> > * message, we won't consider the change, as a whole, to be filtered out. Hence
> > * won't increment the filteredBytes.
> > */
> >
> > Does that look good?
>
> Yes. Works for me.
Here's a patch with all comments addressed.
--
Best Wishes,
Ashutosh Bapat
Attachments:
0001-Report-output-plugin-statistics-in-pg_stat_-20251103.patch (text/x-patch, 54.2K) download
From 3d20178fc66d4a0c105890a139c5d5e7ca618a68 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH] Report output plugin statistics in pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output plugin statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- plugin_filtered_bytes is the amount of changes filtered out by the
output plugin
- plugin_sent_txns is the amount of transactions sent downstream by the
output plugin
- plugin_sent_bytes is the amount of data sent downstream by the output
plugin.
The prefix "plugin_" indicates that these counters are related to and
maintained by the output plugin. An output plugin may choose not to
initialize LogicalDecodingContext::stats, which holds these counters, in
which case the above columns will be reported as NULL.
When the stats are disabled after being enabled for a while, the plugin
stats are reset to 0, rather than carrying over the stale stats from the
time when the plugin was supporting the stats. This does not matter if
the plugin continues not to support statistics forever. But in case it
was supporting the stats once, discontinued doing so at some point in
time and then starts supporting the stats later, accumulating the new
stats based on the earlier accumulated stats could be misleading.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Additionally report name of the output plugin in the view for an easy
reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++++---------
contrib/test_decoding/sql/stats.sql | 16 ++--
contrib/test_decoding/t/001_repl_stats.pl | 22 ++++--
contrib/test_decoding/test_decoding.c | 2 +
doc/src/sgml/logicaldecoding.sgml | 36 +++++++++
doc/src/sgml/monitoring.sgml | 70 +++++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 28 ++++++-
.../replication/logical/logicalfuncs.c | 12 +++
.../replication/logical/reorderbuffer.c | 3 +-
src/backend/replication/pgoutput/pgoutput.c | 33 +++++++-
src/backend/replication/walsender.c | 7 ++
src/backend/utils/activity/pgstat_replslot.c | 19 ++++-
src/backend/utils/adt/pgstatfuncs.c | 34 ++++++--
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 8 +-
src/include/replication/logical.h | 1 +
src/include/replication/output_plugin.h | 13 ++++
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 10 ++-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 +++++
src/test/subscription/t/028_row_filter.pl | 11 +++
src/tools/pgindent/typedefs.list | 1 +
26 files changed, 375 insertions(+), 90 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index 28da9123cc8..0e5c5fa5b18 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | | | | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | plugin_sent_txns | plugin_sent_bytes | plugin_filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------------+-------------------+-----------------------+--------------------
+ regression_slot_stats1 | t | t | f | f | | | | t
+ regression_slot_stats2 | t | t | f | f | | | | t
+ regression_slot_stats3 | t | t | f | f | | | | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | plugin_filtered_bytes | plugin_sent_txns | plugin_sent_bytes | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+-----------------------+------------------+-------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..d6bf3cde8b1 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but plugin_sent_txns
+-- should always be 1 since the background transactions are always skipped.
+-- Filtered bytes would be set only when there's a change that was passed to the
+-- plugin but was filtered out. Depending upon the background transactions,
+-- filtered bytes may or may not be zero.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes > 0 AS sent_bytes, plugin_filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, plugin_sent_txns, plugin_sent_bytes, plugin_filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..756fc691ed6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, plugin_filtered_bytes may be greater than 0. But it's not
+ # guaranteed that such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ plugin_sent_txns > 0 AS sent_txn,
+ plugin_sent_bytes > 0 AS sent_bytes,
+ plugin_filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 36e77c69e1c..d06f6c3f92b 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -173,6 +173,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
data->only_local = false;
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
opt->output_type = OUTPUT_PLUGIN_TEXTUAL_OUTPUT;
opt->receive_rewrites = false;
@@ -310,6 +311,7 @@ static void
pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBufferTXN *txn, bool last_write)
{
OutputPluginPrepareWrite(ctx, last_write);
+ ctx->stats->sentTxns++;
if (data->include_xids)
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
else
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..0bf9ffbfd28 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -938,6 +938,42 @@ typedef struct OutputPluginOptions
needs to have a state, it can
use <literal>ctx->output_plugin_private</literal> to store it.
</para>
+
+ <para>
+ The startup callback may initialize <literal>ctx->stats</literal>,
+ typically as follows, if it chooses to maintain and report statistics
+ about its activity in <structname>pg_stat_replication_slots</structname>.
+<programlisting>
+ctx->stats = palloc0(sizeof(OutputPluginStats));
+</programlisting>
+ where <literal>OutputPluginStats</literal> is defined as follows:
+<programlisting>
+typedef struct OutputPluginStats
+{
+ int64 sentTxns;
+ int64 sentBytes;
+ int64 filteredBytes;
+} OutputPluginStats;
+</programlisting>
+ <literal>sentTxns</literal> is the number of transactions sent downstream
+ by the output plugin. <literal>sentBytes</literal> is the amount of data,
+ in bytes, sent downstream by the output plugin.
+ <literal>filteredBytes</literal> is the size of changes, in bytes, that
+ are filtered out by the output plugin.
+ <function>OutputPluginWrite</function> will update
+ <literal>sentBytes</literal> if <literal>ctx->stats</literal> is
+ initialized by the output plugin. Function
+ <literal>ReorderBufferChangeSize</literal> may be used to find the size of
+ filtered <literal>ReorderBufferChange</literal>.
+ </para>
+
+ <note>
+ <para>
+ Once a plugin starts reporting and maintaining these statistics, it is
+ not expected that they will discontinue doing so. If they do, the result
+ may be misleading because of the cumulative nature of these statistics.
+ </para>
+ </note>
</sect3>
<sect3 id="logicaldecoding-output-plugin-shutdown">
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index f3bf527d5b4..7f30094b228 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1549,6 +1549,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1637,19 +1648,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1659,6 +1670,53 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin. The counter is
+ maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>. The counter is maintained
+ by the output plugin mentioned in <structfield>plugin</structfield>. It
+ is NULL when statistics is not initialized or immediately after a reset or
+ when not maintained by the output plugin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin_sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes sent downstream for this slot by the
+ output plugin after applying filtering and converting into its output
+ format. The counter is maintained by the output plugin mentioned in
+ <structfield>plugin</structfield>. It is NULL when statistics is not
+ initialized or immediately after a reset or when not maintained by the
+ output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index dec8df4f8ee..defca1cf9ac 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1067,6 +1067,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1074,8 +1075,11 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots as r,
LATERAL pg_stat_get_replication_slot(slot_name) as s
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 93ed2eb368e..f0810f05153 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1952,6 +1952,7 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
+ OutputPluginStats *stats = ctx->stats;
PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
@@ -1959,7 +1960,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " (%s) %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1969,7 +1970,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ stats ? "plugin has stats" : "plugin has no stats",
+ stats ? stats->sentTxns : 0,
+ stats ? stats->sentBytes : 0,
+ stats ? stats->filteredBytes : 0);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1978,8 +1983,17 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ if (stats)
+ {
+ repSlotStat.plugin_has_stats = true;
+ repSlotStat.plugin_sent_txns = stats->sentTxns;
+ repSlotStat.plugin_sent_bytes = stats->sentBytes;
+ repSlotStat.plugin_filtered_bytes = stats->filteredBytes;
+ }
+ else
+ repSlotStat.plugin_has_stats = false;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1992,6 +2006,12 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ if (stats)
+ {
+ stats->sentTxns = 0;
+ stats->sentBytes = 0;
+ stats->filteredBytes = 0;
+ }
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 25f890ddeed..55e02e7ee21 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 sentBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ sentBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ sentBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,8 +90,17 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ sentBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /*
+ * If output plugin has chosen to maintain its stats, update the amount of
+ * data sent downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += sentBytes;
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index b57aef9916d..d336ef3a51f 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -4458,7 +4457,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 942e1abdb58..367ba9efab3 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -473,6 +473,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
MemoryContextRegisterResetCallback(ctx->context, mcallback);
ctx->output_plugin_private = data;
+ ctx->stats = palloc0(sizeof(OutputPluginStats));
/* This plugin uses binary protocol. */
opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;
@@ -614,6 +615,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
OutputPluginPrepareWrite(ctx, !send_replication_origin);
logicalrep_write_begin(ctx->out, txn);
txndata->sent_begin_txn = true;
+ ctx->stats->sentTxns++;
send_repl_origin(ctx, txn->origin_id, txn->origin_lsn,
send_replication_origin);
@@ -1492,7 +1494,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
TupleTableSlot *new_slot = NULL;
if (!is_publishable_relation(relation))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1510,15 +1515,24 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
+ }
/*
* This is only possible if deletes are allowed even when replica
@@ -1528,6 +1542,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
return;
}
break;
@@ -1583,7 +1598,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
goto cleanup;
+ }
/*
* Send BEGIN if we haven't yet.
@@ -1603,7 +1621,11 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
OutputPluginPrepareWrite(ctx, true);
- /* Send the data */
+ /*
+ * Send the data. Even if we end up filtering some columns while sending
+ * the message, we won't filter the change, as a whole. Hence we don't
+ * increment filteredBytes.
+ */
switch (action)
{
case REORDER_BUFFER_CHANGE_INSERT:
@@ -1710,7 +1732,16 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.cascade,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
+
+ /*
+ * Even if we filtered out some relations, we still send a TRUNCATE
+ * message for the remaining relations. Since the change, as a whole,
+ * is not filtered out we don't increment filteredBytes.
+ */
}
+ else
+ ctx->stats->filteredBytes += ReorderBufferChangeSize(change);
+
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 548eafa7a73..b0a5d4da7a7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1587,6 +1587,13 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /*
+ * If output plugin maintains statistics, update the amount of data sent
+ * downstream.
+ */
+ if (ctx->stats)
+ ctx->stats->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index d210c261ac6..42ca13bd76a 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -88,6 +88,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
+#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0
REPLSLOT_ACC(spill_txns);
REPLSLOT_ACC(spill_count);
REPLSLOT_ACC(spill_bytes);
@@ -95,9 +96,23 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(mem_exceeded_count);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ statent->plugin_has_stats = repSlotStat->plugin_has_stats;
+ if (repSlotStat->plugin_has_stats)
+ {
+ REPLSLOT_ACC(plugin_sent_txns);
+ REPLSLOT_ACC(plugin_sent_bytes);
+ REPLSLOT_ACC(plugin_filtered_bytes);
+ }
+ else
+ {
+ REPLSLOT_SET_TO_ZERO(plugin_sent_txns);
+ REPLSLOT_SET_TO_ZERO(plugin_sent_bytes);
+ REPLSLOT_SET_TO_ZERO(plugin_filtered_bytes);
+ }
#undef REPLSLOT_ACC
+#undef REPLSLOT_SET_TO_ZERO
pgstat_unlock_entry(entry_ref);
}
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index a710508979e..672b01a246d 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2129,7 +2129,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 11
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2156,11 +2156,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "plugin_filtered_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "plugin_sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "plugin_sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2184,13 +2190,25 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
+ values[8] = Int64GetDatum(slotent->total_wal_txns);
+ values[9] = Int64GetDatum(slotent->total_wal_bytes);
+ if (slotent->plugin_has_stats)
+ {
+ values[10] = Int64GetDatum(slotent->plugin_filtered_bytes);
+ values[11] = Int64GetDatum(slotent->plugin_sent_txns);
+ values[12] = Int64GetDatum(slotent->plugin_sent_bytes);
+ }
+ else
+ {
+ nulls[10] = true;
+ nulls[11] = true;
+ nulls[12] = true;
+ }
if (slotent->stat_reset_timestamp == 0)
- nulls[10] = true;
+ nulls[13] = true;
else
- values[10] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 9121a382f76..e78d4f0ab1e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5691,9 +5691,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,plugin_filtered_bytes,plugin_sent_txns,plugin_sent_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 7ae503e71a2..427cf55d4b6 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -396,8 +396,12 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ bool plugin_has_stats;
+ PgStat_Counter plugin_sent_txns;
+ PgStat_Counter plugin_sent_bytes;
+ PgStat_Counter plugin_filtered_bytes;
TimestampTz stat_reset_timestamp;
} PgStat_StatReplSlotEntry;
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h
index 2e562bee5a9..010c59f783d 100644
--- a/src/include/replication/logical.h
+++ b/src/include/replication/logical.h
@@ -52,6 +52,7 @@ typedef struct LogicalDecodingContext
OutputPluginCallbacks callbacks;
OutputPluginOptions options;
+ OutputPluginStats *stats;
/*
* User specified options
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..4cc939e6c98 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -29,6 +29,19 @@ typedef struct OutputPluginOptions
bool receive_rewrites;
} OutputPluginOptions;
+/*
+ * Statistics about the transactions decoded and sent downstream by the output
+ * plugin.
+ */
+typedef struct OutputPluginStats
+{
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data from reorder buffer that was
+ * filtered out by the output plugin */
+} OutputPluginStats;
+
/*
* Type of the shared library symbol _PG_output_plugin_init that is looked up
* when loading an output plugin shared library.
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 3cbe106a3c7..382eba66a76 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -718,6 +718,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 96b70b84d5e..49bfe679249 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, plugin_sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, plugin_sent_bytes is NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and plugin_sent_bytes were set to 0 and NULL respectively.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index ebe2fae1789..5f4df30d65a 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -577,7 +577,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -605,7 +605,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 77e25ca029e..4bc5668f0fd 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2142,6 +2142,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2149,11 +2150,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.plugin_filtered_bytes,
+ s.plugin_sent_txns,
+ s.plugin_sent_bytes,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, plugin_filtered_bytes, plugin_sent_txns, plugin_sent_bytes, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index 430c1246d14..7f37b6fe6c6 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that plugin_filtered_bytes increases due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..c41ad317221 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. plugin_filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# plugin_filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the plugin_filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..039bf5ff5a0 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT coalesce(plugin_filtered_bytes, 0) FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the plugin_filtered_bytes reflects that. We can not test the exact value of
+# plugin_filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT plugin_filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'plugin_filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 018b5919cf6..3f1206a59c8 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1833,6 +1833,7 @@ OuterJoinClauseInfo
OutputPluginCallbacks
OutputPluginOptions
OutputPluginOutputType
+OutputPluginStats
OverridingKind
PACE_HEADER
PACL
base-commit: f242dbcede9cb1c2f60ca31e6ad1141e0713bc65
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-11-03 15:20 ` Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Andres Freund @ 2025-11-03 15:20 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
Hi,
On 2025-11-03 19:53:30 +0530, Ashutosh Bapat wrote:
> This commit adds following fields to pg_stat_replication_slots
> - plugin_filtered_bytes is the amount of changes filtered out by the
> output plugin
> - plugin_sent_txns is the amount of transactions sent downstream by the
> output plugin
> - plugin_sent_bytes is the amount of data sent downstream by the output
> plugin.
>
> The prefix "plugin_" indicates that these counters are related to and
> maintained by the output plugin. An output plugin may choose not to
> initialize LogicalDecodingContext::stats, which holds these counters, in
> which case the above columns will be reported as NULL.
I continue to be uncomfortable with doing all this tracking explicitly in
output plugins. This still seems like something core infrastructure should
take care of, instead of re-implementing it in different output plugins, with
the inevitable behaviour differences that will entail.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
@ 2025-11-04 10:58 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-11-04 10:58 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers
On Mon, Nov 3, 2025 at 8:50 PM Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> On 2025-11-03 19:53:30 +0530, Ashutosh Bapat wrote:
> > This commit adds following fields to pg_stat_replication_slots
> > - plugin_filtered_bytes is the amount of changes filtered out by the
> > output plugin
> > - plugin_sent_txns is the amount of transactions sent downstream by the
> > output plugin
> > - plugin_sent_bytes is the amount of data sent downstream by the output
> > plugin.
> >
> > The prefix "plugin_" indicates that these counters are related to and
> > maintained by the output plugin. An output plugin may choose not to
> > initialize LogicalDecodingContext::stats, which holds these counters, in
> > which case the above columns will be reported as NULL.
>
> I continue to be uncomfortable with doing all this tracking explicitly in
> output plugins. This still seems like something core infrastructure should
> take care of, instead of re-implementing it in different output plugins, with
> the inevitable behaviour differences that will entail.
I understand your concern, and while I agree that it's ideal to keep
as much of the stats bookkeeping in core there are some nuances here
which makes it hard as explained below.
My first patch [1] had the stats placed in ReorderBuffer directly. It
was evident from the patch that the sentTxns needs to be set somewhere
in the output plugin code since the output plugin may decide to filter
out or send transaction when processing a change in that transaction
(not necessarily when in begin_cb). Filtered bytes is also something
that is in plugin's control and needs to be updated in the output
plugin code. Few emails, starting from [2], discussed possible
approaches to maintain those in the core vs maintain those in the
output plugin. We decided to let output plugin maintain it for
following reasons
a. sentTxns and filteredBytes need to be modified in the output plugin
code. The behaviour there is inherently output plugin specific, and
requires output plugin specific implementation.
b. an output plugin may or may not want to update their code to track
the statistics for various logistic and technical reasons. We need to
be flexible about that if possible.
The current approach requires only the output plugin specific changes
to be made to the output plugin code and also makes it optional for
them to do those changes. The only changes in output plugin code are
for a. indicating whether it updates the stats and b. updating
filteredBytes and sentBytes at appropriate places. I don't see a way
to avoid that. Rest of the logic is actually in the core. Unless
there's anything we've overlooked in the thread the current approach
seems to balance the constraints quite well. Do you have an
alternative design in mind?
This has been a long thread with many patch versions, and the commit
message might need some rewording to describe the proposed
functionality better. I hope the above explanation is clearer, and if
so I can reword the commit message to include more of it.
sentBytes is a slightly different story. The core code updates it. But
it's a stat about output plugin's behaviour. Hence it's still exposed
as a plugin stats and maintained in LogicalDecodingContext::stats. It
can be maintained in ReorderBuffer directly and can be projected as a
core stats, renaming it as just "sent_bytes". Please let me know if
you would like it that way.
[1] https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2%2BAnTgYGAzo%3DQv61wA%40mail...
[2] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-11-18 09:54 ` Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2025-11-18 09:54 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Tue, Nov 4, 2025 at 4:29 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Mon, Nov 3, 2025 at 8:50 PM Andres Freund <andres@anarazel.de> wrote:
> >
> > Hi,
> >
> > On 2025-11-03 19:53:30 +0530, Ashutosh Bapat wrote:
> > > This commit adds following fields to pg_stat_replication_slots
> > > - plugin_filtered_bytes is the amount of changes filtered out by the
> > > output plugin
> > > - plugin_sent_txns is the amount of transactions sent downstream by the
> > > output plugin
> > > - plugin_sent_bytes is the amount of data sent downstream by the output
> > > plugin.
> > >
> > > The prefix "plugin_" indicates that these counters are related to and
> > > maintained by the output plugin. An output plugin may choose not to
> > > initialize LogicalDecodingContext::stats, which holds these counters, in
> > > which case the above columns will be reported as NULL.
> >
> > I continue to be uncomfortable with doing all this tracking explicitly in
> > output plugins. This still seems like something core infrastructure should
> > take care of, instead of re-implementing it in different output plugins, with
> > the inevitable behaviour differences that will entail.
>
> I understand your concern, and while I agree that it's ideal to keep
> as much of the stats bookkeeping in core there are some nuances here
> which makes it hard as explained below.
>
> My first patch [1] had the stats placed in ReorderBuffer directly. It
> was evident from the patch that the sentTxns needs to be set somewhere
> in the output plugin code since the output plugin may decide to filter
> out or send transaction when processing a change in that transaction
> (not necessarily when in begin_cb). Filtered bytes is also something
> that is in plugin's control and needs to be updated in the output
> plugin code. Few emails, starting from [2], discussed possible
> approaches to maintain those in the core vs maintain those in the
> output plugin. We decided to let output plugin maintain it for
> following reasons
>
> a. sentTxns and filteredBytes need to be modified in the output plugin
> code. The behaviour there is inherently output plugin specific, and
> requires output plugin specific implementation.
>
Is it possible that we allow change callback (LogicalDecodeChangeCB)
to return a boolean such that if the change is decoded and sent, it
returns true, otherwise, false? If so, the caller could deduce from it
the filtered bytes, and if none of the change calls returns true, this
means the entire transaction is not sent.
I think this should address Andres's concern of explicitly tracking
these stats in plugins, what do you think?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2025-11-18 10:35 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-11-18 10:35 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Tue, Nov 18, 2025 at 3:24 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Nov 4, 2025 at 4:29 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Mon, Nov 3, 2025 at 8:50 PM Andres Freund <andres@anarazel.de> wrote:
> > >
> > > Hi,
> > >
> > > On 2025-11-03 19:53:30 +0530, Ashutosh Bapat wrote:
> > > > This commit adds following fields to pg_stat_replication_slots
> > > > - plugin_filtered_bytes is the amount of changes filtered out by the
> > > > output plugin
> > > > - plugin_sent_txns is the amount of transactions sent downstream by the
> > > > output plugin
> > > > - plugin_sent_bytes is the amount of data sent downstream by the output
> > > > plugin.
> > > >
> > > > The prefix "plugin_" indicates that these counters are related to and
> > > > maintained by the output plugin. An output plugin may choose not to
> > > > initialize LogicalDecodingContext::stats, which holds these counters, in
> > > > which case the above columns will be reported as NULL.
> > >
> > > I continue to be uncomfortable with doing all this tracking explicitly in
> > > output plugins. This still seems like something core infrastructure should
> > > take care of, instead of re-implementing it in different output plugins, with
> > > the inevitable behaviour differences that will entail.
> >
> > I understand your concern, and while I agree that it's ideal to keep
> > as much of the stats bookkeeping in core there are some nuances here
> > which makes it hard as explained below.
> >
> > My first patch [1] had the stats placed in ReorderBuffer directly. It
> > was evident from the patch that the sentTxns needs to be set somewhere
> > in the output plugin code since the output plugin may decide to filter
> > out or send transaction when processing a change in that transaction
> > (not necessarily when in begin_cb). Filtered bytes is also something
> > that is in plugin's control and needs to be updated in the output
> > plugin code. Few emails, starting from [2], discussed possible
> > approaches to maintain those in the core vs maintain those in the
> > output plugin. We decided to let output plugin maintain it for
> > following reasons
> >
> > a. sentTxns and filteredBytes need to be modified in the output plugin
> > code. The behaviour there is inherently output plugin specific, and
> > requires output plugin specific implementation.
> >
>
> Is it possible that we allow change callback (LogicalDecodeChangeCB)
> to return a boolean such that if the change is decoded and sent, it
> returns true, otherwise, false? If so, the caller could deduce from it
> the filtered bytes, and if none of the change calls returns true, this
> means the entire transaction is not sent.
>
> I think this should address Andres's concern of explicitly tracking
> these stats in plugins, what do you think?
>
I was thinking about a similar thing. But I am skeptical since the
calling logic is not straight forward - there's an indirection in
between. Second, it means that all the plugins have to adapt to the
new callback definition. It is optional in my current approach. Since
both of us have thought of this approach, I think it's worth a try.
"if none of the change calls returns true, this means the entire
transaction is not sent" isn't true. A plugin may still send an empty
transaction. I was thinking of making commit/abort/prepare callbacks
to return true/false to indicate whether a transaction was sent or not
and increment the counter accordingly. The plugin has to take care of
not returning true for both prepare and commit or prepare and abort.
So may be just commit and abort should be made to return true or
false. What do you think?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-11-18 10:44 ` Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2025-11-18 10:44 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Tue, Nov 18, 2025 at 4:05 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Tue, Nov 18, 2025 at 3:24 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Tue, Nov 4, 2025 at 4:29 PM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > > a. sentTxns and filteredBytes need to be modified in the output plugin
> > > code. The behaviour there is inherently output plugin specific, and
> > > requires output plugin specific implementation.
> > >
> >
> > Is it possible that we allow change callback (LogicalDecodeChangeCB)
> > to return a boolean such that if the change is decoded and sent, it
> > returns true, otherwise, false? If so, the caller could deduce from it
> > the filtered bytes, and if none of the change calls returns true, this
> > means the entire transaction is not sent.
> >
> > I think this should address Andres's concern of explicitly tracking
> > these stats in plugins, what do you think?
> >
>
> I was thinking about a similar thing. But I am skeptical since the
> calling logic is not straight forward - there's an indirection in
> between. Second, it means that all the plugins have to adapt to the
> new callback definition. It is optional in my current approach. Since
> both of us have thought of this approach, I think it's worth a try.
>
> "if none of the change calls returns true, this means the entire
> transaction is not sent" isn't true. A plugin may still send an empty
> transaction. I was thinking of making commit/abort/prepare callbacks
> to return true/false to indicate whether a transaction was sent or not
> and increment the counter accordingly. The plugin has to take care of
> not returning true for both prepare and commit or prepare and abort.
> So may be just commit and abort should be made to return true or
> false. What do you think?
>
Sounds reasonable to me.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2025-12-11 04:59 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-17 08:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-01-12 05:11 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
0 siblings, 4 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2025-12-11 04:59 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi All,
On Tue, Nov 18, 2025 at 4:14 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Nov 18, 2025 at 4:05 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Tue, Nov 18, 2025 at 3:24 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > > On Tue, Nov 4, 2025 at 4:29 PM Ashutosh Bapat
> > > <ashutosh.bapat.oss@gmail.com> wrote:
> > > >
> > > > a. sentTxns and filteredBytes need to be modified in the output plugin
> > > > code. The behaviour there is inherently output plugin specific, and
> > > > requires output plugin specific implementation.
> > > >
> > >
> > > Is it possible that we allow change callback (LogicalDecodeChangeCB)
> > > to return a boolean such that if the change is decoded and sent, it
> > > returns true, otherwise, false? If so, the caller could deduce from it
> > > the filtered bytes, and if none of the change calls returns true, this
> > > means the entire transaction is not sent.
> > >
> > > I think this should address Andres's concern of explicitly tracking
> > > these stats in plugins, what do you think?
> > >
> >
> > I was thinking about a similar thing. But I am skeptical since the
> > calling logic is not straight forward - there's an indirection in
> > between. Second, it means that all the plugins have to adapt to the
> > new callback definition. It is optional in my current approach. Since
> > both of us have thought of this approach, I think it's worth a try.
> >
> > "if none of the change calls returns true, this means the entire
> > transaction is not sent" isn't true. A plugin may still send an empty
> > transaction. I was thinking of making commit/abort/prepare callbacks
> > to return true/false to indicate whether a transaction was sent or not
> > and increment the counter accordingly. The plugin has to take care of
> > not returning true for both prepare and commit or prepare and abort.
> > So may be just commit and abort should be made to return true or
> > false. What do you think?
> >
>
> Sounds reasonable to me.
Sorry for the delayed response. PFA the patch implementing the idea
discussed above. It relies on the output plugin callback to return
correct boolean but maintains the statistics in the core itself.
I have reviewed all the previous comments and applied the ones which
are relevant to the new approach again. Following two are worth noting
here.
In order to address Amit's concern [1] that an inaccuracy in these
counts because of a bug in output plugin code may be blamed on the
core, I have added a note in the documentation of view
pg_stat_replication_slot in order to avoid such a blame and also
directing users to plugin they should investigate.
With the statistics being maintained by the core, Bertrand's concern
about stale statistics [2] are also addressed. Also it does not have
the asymmetry mentioned in point 2 in [3].
Please review.
[1] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
[2] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
[3] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
--
Best Wishes,
Ashutosh Bapat
Attachments:
v20251211-0001-Report-output-plugin-statistics-in-pg_stat.patch (text/x-patch, 81.7K) download
From f15d7ca6075f5364713582f7714d166c22b36e88 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 27 Jun 2025 09:16:23 +0530
Subject: [PATCH v20251211] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output statistics like the amount of data
filtered by the output plugin, amount of data sent downstream or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- filtered_bytes is the amount of changes filtered out by the
output plugin
- sent_txns is the amount of transactions sent downstream by the
output plugin
- sent_bytes is the amount of data sent downstream by the output
plugin.
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Though these counts are stored and maintained by the core, they require
the output plugin to return correct values to the relevant callbacks.
This has been added as note in the documentation. In order to aid
debugging descripancies in these counter, name of the output plugin is
added to the view for an easy reference.
total_bytes and total_txns are the only fields remaining unqualified -
they do not convey what those bytes and txns are. Hence rename them
total_wal_bytes and total_wal_txns respectively to indicate that those
counts come from WAL stream.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++-------
contrib/test_decoding/sql/stats.sql | 16 +++-
contrib/test_decoding/t/001_repl_stats.pl | 22 +++--
contrib/test_decoding/test_decoding.c | 55 ++++++-----
doc/src/sgml/logicaldecoding.sgml | 96 ++++++++++++++-----
doc/src/sgml/monitoring.sgml | 70 ++++++++++++--
src/backend/catalog/system_views.sql | 8 +-
src/backend/replication/logical/logical.c | 44 ++++++---
.../replication/logical/logicalfuncs.c | 8 ++
.../replication/logical/reorderbuffer.c | 6 +-
src/backend/replication/pgoutput/pgoutput.c | 65 +++++++++----
src/backend/replication/walsender.c | 3 +
src/backend/utils/activity/pgstat_replslot.c | 7 +-
src/backend/utils/adt/pgstatfuncs.c | 35 ++++---
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 7 +-
src/include/replication/output_plugin.h | 43 +++++----
src/include/replication/reorderbuffer.h | 6 ++
src/test/recovery/t/006_logical_decoding.pl | 12 +--
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 10 +-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 ++++
src/test/subscription/t/028_row_filter.pl | 11 +++
24 files changed, 452 insertions(+), 190 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..54079b7d83d 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+-- total_wal_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Usually we
+-- expect filtered_bytes to be 0 since the entire transaction executed by this
+-- test is replicated. But there may be some background transactions, changes
+-- from which are filtered out by the output plugin, so we check for >= 0 here.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_txns, sent_bytes > 0 AS sent_bytes, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+-----------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_txns, sent_bytes > 0 AS sent_bytes, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+-----------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | f | t | t
+ regression_slot_stats2 | t | t | t | t | 1 | t | t | t
+ regression_slot_stats3 | t | t | t | t | 1 | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_txns, sent_bytes, filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_txns | sent_bytes | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+-----------+------------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | 0 | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | 0 | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | 0 | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | filtered_bytes | sent_txns | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+----------------+-----------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | filtered_bytes | sent_txns | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+----------------+-----------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..17e7c0e8f88 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,22 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+-- total_wal_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Usually we
+-- expect filtered_bytes to be 0 since the entire transaction executed by this
+-- test is replicated. But there may be some background transactions, changes
+-- from which are filtered out by the output plugin, so we check for >= 0 here.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_txns, sent_bytes > 0 AS sent_bytes, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_txns, sent_bytes > 0 AS sent_bytes, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_txns, sent_bytes, filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -46,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 0de62edb7d8..89d3ff0a239 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,16 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, filtered_bytes may be greater than 0. But it's not guaranteed that
+ # such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ sent_txns > 0 AS sent_txn,
+ sent_bytes > 0 AS sent_bytes,
+ filtered_bytes >= 0 AS filtered_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +71,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 47094f86f5f..69ad9599804 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -60,12 +60,12 @@ static void pg_output_begin(LogicalDecodingContext *ctx,
TestDecodingData *data,
ReorderBufferTXN *txn,
bool last_write);
-static void pg_decode_commit_txn(LogicalDecodingContext *ctx,
+static bool pg_decode_commit_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
-static void pg_decode_change(LogicalDecodingContext *ctx,
+static bool pg_decode_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, Relation relation,
ReorderBufferChange *change);
-static void pg_decode_truncate(LogicalDecodingContext *ctx,
+static bool pg_decode_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change);
@@ -80,7 +80,7 @@ static bool pg_decode_filter_prepare(LogicalDecodingContext *ctx,
const char *gid);
static void pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pg_decode_prepare_txn(LogicalDecodingContext *ctx,
+static bool pg_decode_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
static void pg_decode_commit_prepared_txn(LogicalDecodingContext *ctx,
@@ -98,16 +98,16 @@ static void pg_output_stream_start(LogicalDecodingContext *ctx,
bool last_write);
static void pg_decode_stream_stop(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pg_decode_stream_abort(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_abort(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
-static void pg_decode_stream_prepare(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_prepare(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
-static void pg_decode_stream_commit(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_commit(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
-static void pg_decode_stream_change(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -115,7 +115,7 @@ static void pg_decode_stream_message(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr lsn,
bool transactional, const char *prefix,
Size sz, const char *message);
-static void pg_decode_stream_truncate(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change);
@@ -318,7 +318,7 @@ pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBuff
}
/* COMMIT callback */
-static void
+static bool
pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
{
@@ -330,7 +330,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
txn->output_plugin_private = NULL;
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
if (data->include_xids)
@@ -343,6 +343,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/* BEGIN PREPARE callback */
@@ -367,7 +368,7 @@ pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
}
/* PREPARE callback */
-static void
+static bool
pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
{
@@ -379,7 +380,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* where the first operation is received for this transaction.
*/
if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -394,6 +395,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/* COMMIT PREPARED callback */
@@ -599,7 +601,7 @@ tuple_to_stringinfo(StringInfo s, TupleDesc tupdesc, HeapTuple tuple, bool skip_
/*
* callback for individual changed tuples
*/
-static void
+static bool
pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
Relation relation, ReorderBufferChange *change)
{
@@ -684,9 +686,10 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
MemoryContextReset(data->context);
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[], ReorderBufferChange *change)
{
@@ -739,6 +742,7 @@ pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
MemoryContextReset(data->context);
OutputPluginWrite(ctx, true);
+ return true;
}
static void
@@ -818,7 +822,7 @@ pg_decode_stream_stop(LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
}
-static void
+static bool
pg_decode_stream_abort(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn)
@@ -842,7 +846,7 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
}
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
if (data->include_xids)
@@ -850,9 +854,10 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
else
appendStringInfoString(ctx->out, "aborting streamed (sub)transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_stream_prepare(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
@@ -861,7 +866,7 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
TestDecodingTxnData *txndata = txn->output_plugin_private;
if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -877,9 +882,10 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_stream_commit(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
@@ -892,7 +898,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
txn->output_plugin_private = NULL;
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -906,6 +912,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -913,7 +920,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
* at a later point in time. We don't want users to see the changes until the
* transaction is committed.
*/
-static void
+static bool
pg_decode_stream_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
@@ -935,6 +942,7 @@ pg_decode_stream_change(LogicalDecodingContext *ctx,
else
appendStringInfoString(ctx->out, "streaming change for transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -981,7 +989,7 @@ pg_decode_stream_message(LogicalDecodingContext *ctx,
* In streaming mode, we don't display the detailed information of Truncate.
* See pg_decode_stream_change.
*/
-static void
+static bool
pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change)
@@ -1001,4 +1009,5 @@ pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
else
appendStringInfoString(ctx->out, "streaming truncate for transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index d5a5e22fe2c..886c7d940df 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -981,10 +981,15 @@ typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
rows will have been called before this, if there have been any modified
rows.
<programlisting>
-typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
</programlisting>
+ If the callback outputs the transaction, it is expected to return true;
+ otherwise false. The return value is used to update the
+ <literal>sent_txns</literal> counter reported in <link
+ linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
</para>
</sect3>
@@ -1005,7 +1010,7 @@ typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
this very same transaction. In that case, the logical decoding of this
aborted transaction is stopped gracefully.
<programlisting>
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -1015,8 +1020,12 @@ typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
and <function>commit_cb</function> callbacks, but additionally the
relation descriptor <parameter>relation</parameter> points to the
relation the row belongs to and a struct
- <parameter>change</parameter> describing the row modification are passed
- in.
+ <parameter>change</parameter> describing the row modification are passed in.
+ If the output plugin decoded and output the change, it is expected
+ to return true; otherwise false. This return value is used to update the
+ <structfield>filtered_bytes</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
</para>
<note>
@@ -1036,18 +1045,18 @@ typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
The optional <function>truncate_cb</function> callback is called for a
<command>TRUNCATE</command> command.
<programlisting>
-typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
ReorderBufferChange *change);
</programlisting>
- The parameters are analogous to the <function>change_cb</function>
- callback. However, because <command>TRUNCATE</command> actions on
- tables connected by foreign keys need to be executed together, this
- callback receives an array of relations instead of just a single one.
- See the description of the <xref linkend="sql-truncate"/> statement for
- details.
+ The parameters and the expected return value are analogous to the
+ <function>change_cb</function> callback. However, because
+ <command>TRUNCATE</command> actions on tables connected by foreign keys
+ need to be executed together, this callback receives an array of relations
+ instead of just a single one. See the description of the <xref
+ linkend="sql-truncate"/> statement for details.
</para>
</sect3>
@@ -1180,8 +1189,18 @@ typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
rows will have been called before this, if there have been any modified
rows. The <parameter>gid</parameter> field, which is part of the
<parameter>txn</parameter> parameter, can be used in this callback.
+ If the callback outputs the prepared transaction, it is expected to return
+ true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view. Please
+ note that the return value of this callback suffices to determine
+ whether a prepared transaction was output or not; callbacks
+ <function>commit_prepared_cb</function> and
+ <function>rollback_prepared_cb</function> do not need to return this
+ status again.
<programlisting>
-typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
</programlisting>
@@ -1255,9 +1274,14 @@ typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
<title>Stream Abort Callback</title>
<para>
The required <function>stream_abort_cb</function> callback is called to
- abort a previously streamed transaction.
+ abort a previously streamed transaction. If the output plugin has output
+ the streamed transaction, the callback is expected to return true;
+ otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
<programlisting>
-typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
</programlisting>
@@ -1270,9 +1294,19 @@ typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
The <function>stream_prepare_cb</function> callback is called to prepare
a previously streamed transaction as part of a two-phase commit. This
callback is required when the output plugin supports both the streaming
- of large in-progress transactions and two-phase commits.
+ of large in-progress transactions and two-phase commits. If the output
+ plugin has output the streamed transaction, the callback is expected to
+ return true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view. Please
+ note that only the return value of this callback suffices to determine
+ whether a prepared transaction was output or not; callbacks
+ <function>commit_prepared_cb</function> and
+ <function>rollback_prepared_cb</function> do not need to return this
+ status again.
<programlisting>
-typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
</programlisting>
@@ -1283,9 +1317,14 @@ typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx
<title>Stream Commit Callback</title>
<para>
The required <function>stream_commit_cb</function> callback is called to
- commit a previously streamed transaction.
+ commit a previously streamed transaction. If the output plugin
+ has output the streamed transaction, the callback is expected to return
+ true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
<programlisting>
-typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
</programlisting>
@@ -1298,10 +1337,15 @@ typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
The required <function>stream_change_cb</function> callback is called
when sending a change in a block of streamed changes (demarcated by
<function>stream_start_cb</function> and <function>stream_stop_cb</function> calls).
+ If the output plugin decoded and output the change, it is expected to
+ return true. Otherwise it is expected to return false. This return value
+ is used to update the <structfield>filtered_bytes</structfield> counter
+ reported in <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
The actual changes are not displayed as the transaction can abort at a later
point in time and we don't decode changes for aborted transactions.
<programlisting>
-typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -1338,18 +1382,18 @@ typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx
(demarcated by <function>stream_start_cb</function> and
<function>stream_stop_cb</function> calls).
<programlisting>
-typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
ReorderBufferChange *change);
</programlisting>
- The parameters are analogous to the <function>stream_change_cb</function>
- callback. However, because <command>TRUNCATE</command> actions on
- tables connected by foreign keys need to be executed together, this
- callback receives an array of relations instead of just a single one.
- See the description of the <xref linkend="sql-truncate"/> statement for
- details.
+ The parameters and the return value are analogous to the
+ <function>stream_change_cb</function> callback. However, because
+ <command>TRUNCATE</command> actions on tables connected by foreign keys
+ need to be executed together, this callback receives an array of relations
+ instead of just a single one. See the description of the <xref
+ linkend="sql-truncate"/> statement for details.
</para>
</sect3>
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 817fd9f4ca7..d3710e762e4 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1547,6 +1547,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1635,19 +1646,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1657,6 +1668,42 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes, in the output format, sent downstream for
+ this slot by the output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
@@ -1693,6 +1740,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</tgroup>
</table>
+ <note>
+ <para>
+ The accuracy of columns <structfield>filtered_bytes</structfield>, and
+ <structfield>sent_txns</structfield> depends upon the accuracy of return values
+ from respective callbacks associated with those counts as mentioned in <xref
+ linkend="logicaldecoding-output-plugin-callbacks"/>. A descripancy in those
+ counts may be result of incorrect implementation of those callbacks in the
+ output plugin given by column <structfield>plugin</structfield>.
+ </para>
+ </note>
+
</sect2>
<sect2 id="monitoring-pg-stat-wal-receiver-view">
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 0a0f95f6bb9..2b30361d32a 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1068,6 +1068,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1075,8 +1076,11 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.filtered_bytes,
+ s.sent_txns,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 1b11ed63dc6..c65399a9c3d 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -888,7 +888,8 @@ commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = true;
/* do the actual work: call callback */
- ctx->callbacks.commit_cb(ctx, txn, commit_lsn);
+ if (ctx->callbacks.commit_cb(ctx, txn, commit_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -984,7 +985,8 @@ prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
"prepare_cb")));
/* do the actual work: call callback */
- ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1115,7 +1117,8 @@ change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1157,7 +1160,8 @@ truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1396,7 +1400,8 @@ stream_abort_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_abort_cb")));
- ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn);
+ if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1441,7 +1446,8 @@ stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming at prepare time requires a %s callback",
"stream_prepare_cb")));
- ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1482,7 +1488,8 @@ stream_commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_commit_cb")));
- ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn);
+ if (ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1531,7 +1538,8 @@ stream_change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_change_cb")));
- ctx->callbacks.stream_change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.stream_change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1619,7 +1627,8 @@ stream_truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1959,7 +1968,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1969,7 +1978,10 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->sentTxns,
+ rb->sentBytes,
+ rb->filteredBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1978,8 +1990,11 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ repSlotStat.sent_txns = rb->sentTxns;
+ repSlotStat.sent_bytes = rb->sentBytes;
+ repSlotStat.filtered_bytes = rb->filteredBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1992,6 +2007,9 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->sentTxns = 0;
+ rb->sentBytes = 0;
+ rb->filteredBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index cf77ee28dfe..0acbda94941 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 sentBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ sentBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ sentBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,8 +90,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ sentBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += sentBytes;
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index f18c6fb52b5..e4e65688235 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -393,6 +392,9 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentTxns = 0;
+ buffer->sentBytes = 0;
+ buffer->filteredBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
@@ -4455,7 +4457,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 787998abb8a..8377c2ea464 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -46,12 +46,12 @@ static void pgoutput_startup(LogicalDecodingContext *ctx,
static void pgoutput_shutdown(LogicalDecodingContext *ctx);
static void pgoutput_begin_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_commit_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_commit_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
-static void pgoutput_change(LogicalDecodingContext *ctx,
+static bool pgoutput_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, Relation relation,
ReorderBufferChange *change);
-static void pgoutput_truncate(LogicalDecodingContext *ctx,
+static bool pgoutput_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, int nrelations, Relation relations[],
ReorderBufferChange *change);
static void pgoutput_message(LogicalDecodingContext *ctx,
@@ -62,7 +62,7 @@ static bool pgoutput_origin_filter(LogicalDecodingContext *ctx,
RepOriginId origin_id);
static void pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_prepare_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr prepare_lsn);
static void pgoutput_commit_prepared_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
@@ -74,13 +74,13 @@ static void pgoutput_stream_start(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
static void pgoutput_stream_stop(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
+static bool pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
-static void pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
+static bool pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
-static void pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr prepare_lsn);
static bool publications_valid;
@@ -624,7 +624,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
/*
* COMMIT callback
*/
-static void
+static bool
pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
{
@@ -645,12 +645,13 @@ pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!sent_begin_txn)
{
elog(DEBUG1, "skipped replication of an empty transaction with XID: %u", txn->xid);
- return;
+ return false;
}
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_commit(ctx->out, txn, commit_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -673,7 +674,7 @@ pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
/*
* PREPARE callback
*/
-static void
+static bool
pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
{
@@ -682,6 +683,7 @@ pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_prepare(ctx->out, txn, prepare_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -1476,7 +1478,7 @@ pgoutput_row_filter(Relation relation, TupleTableSlot *old_slot,
*
* This is called both in streaming and non-streaming modes.
*/
-static void
+static bool
pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
Relation relation, ReorderBufferChange *change)
{
@@ -1490,9 +1492,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
ReorderBufferChangeType action = change->action;
TupleTableSlot *old_slot = NULL;
TupleTableSlot *new_slot = NULL;
+ bool result;
if (!is_publishable_relation(relation))
- return;
+ return false;
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1510,15 +1513,15 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
- return;
+ return false;
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
- return;
+ return false;
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
- return;
+ return false;
/*
* This is only possible if deletes are allowed even when replica
@@ -1528,7 +1531,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
- return;
+ return false;
}
break;
default:
@@ -1583,7 +1586,16 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ result = false;
goto cleanup;
+ }
+
+ /*
+ * Even if we filter some columns while sending the message we are not
+ * filtering the change as a whole. Hence we will return true.
+ */
+ result = true;
/*
* Send BEGIN if we haven't yet.
@@ -1646,9 +1658,10 @@ cleanup:
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
+ return result;
}
-static void
+static bool
pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[], ReorderBufferChange *change)
{
@@ -1660,6 +1673,7 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelids;
Oid *relids;
TransactionId xid = InvalidTransactionId;
+ bool result = false;
/* Remember the xid for the change in streaming mode. See pgoutput_change. */
if (data->in_streaming)
@@ -1710,10 +1724,18 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.cascade,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
+
+ /*
+ * Even if we filtered out some relations, we still send a TRUNCATE
+ * message for the remaining relations. Since the change, as a whole,
+ * is not filtered out we return true.
+ */
+ result = true;
}
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
+ return result;
}
static void
@@ -1885,7 +1907,7 @@ pgoutput_stream_stop(struct LogicalDecodingContext *ctx,
* Notify downstream to discard the streamed transaction (along with all
* its subtransactions, if it's a toplevel transaction).
*/
-static void
+static bool
pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn)
@@ -1912,13 +1934,14 @@ pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
cleanup_rel_sync_cache(toptxn->xid, false);
+ return true;
}
/*
* Notify downstream to apply the streamed transaction (along with all
* its subtransactions).
*/
-static void
+static bool
pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
@@ -1939,6 +1962,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
cleanup_rel_sync_cache(txn->xid, true);
+ return true;
}
/*
@@ -1946,7 +1970,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
*
* Notify the downstream to prepare the transaction.
*/
-static void
+static bool
pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
@@ -1957,6 +1981,7 @@ pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_stream_prepare(ctx->out, txn, prepare_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 449632ad1aa..8ff11f7e5c8 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1587,6 +1587,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index d757e00eb54..541c39bd0cc 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -95,8 +95,11 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(mem_exceeded_count);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ REPLSLOT_ACC(sent_txns);
+ REPLSLOT_ACC(sent_bytes);
+ REPLSLOT_ACC(filtered_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index ef6fffe60b9..3752a89553c 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2129,7 +2129,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 16
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2156,15 +2156,21 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "filtered_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "sent_txns",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 15, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 16, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2188,19 +2194,22 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[8] = Int64GetDatum(slotent->total_wal_txns);
+ values[9] = Int64GetDatum(slotent->total_wal_bytes);
+ values[10] = Int64GetDatum(slotent->filtered_bytes);
+ values[11] = Int64GetDatum(slotent->sent_txns);
+ values[12] = Int64GetDatum(slotent->sent_bytes);
+ values[13] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[14] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[14] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[15] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[15] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index fd9448ec7b9..8cd14c88bdb 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5691,9 +5691,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,filtered_bytes,sent_txns,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index f23dd5870da..cc4e0a561b0 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -398,8 +398,11 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ PgStat_Counter sent_txns;
+ PgStat_Counter sent_bytes;
+ PgStat_Counter filtered_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 8d4d5b71887..8c27e8266e7 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -56,17 +56,19 @@ typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
/*
- * Callback for every individual change in a successful transaction.
+ * Callback for every individual change in a successful transaction. Should
+ * return true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
/*
- * Callback for every TRUNCATE in a successful transaction.
+ * Callback for every TRUNCATE in a successful transaction. Should return true if
+ * the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
@@ -74,8 +76,9 @@ typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
/*
* Called for every (explicit or implicit) COMMIT of a successful transaction.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
@@ -118,10 +121,10 @@ typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
/*
- * Called for PREPARE record unless it was filtered by filter_prepare()
- * callback.
+ * Called for PREPARE record unless it was filtered by filter_prepare() callback.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
@@ -159,32 +162,35 @@ typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
/*
* Called to discard changes streamed to remote node from in-progress
- * transaction.
+ * transaction. Should return true if the transaction is output, false
+ * otherwise.
*/
-typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
/*
* Called to prepare changes streamed to remote node from in-progress
- * transaction. This is called as part of a two-phase commit.
+ * transaction. This is called as part of a two-phase commit. Should return true
+ * if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
/*
- * Called to apply changes streamed to remote node from in-progress
- * transaction.
+ * Called to apply changes streamed to remote node from in-progress transaction.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
/*
* Callback for streaming individual changes from in-progress transactions.
+ * Should return true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -202,9 +208,10 @@ typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx
const char *message);
/*
- * Callback for streaming truncates from in-progress transactions.
+ * Callback for streaming truncates from in-progress transactions. Should return
+ * true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 3cbe106a3c7..bd4c17da7ac 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,11 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
+ int64 filteredBytes; /* amount of data filtered out by output
+ * plugin */
};
@@ -718,6 +723,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 96b70b84d5e..c8ada58379b 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and plugin sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, sent_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and sent_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index ebe2fae1789..5f4df30d65a 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -577,7 +577,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -605,7 +605,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 4286c266e17..9801c66fba8 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2160,6 +2160,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2167,13 +2168,16 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.filtered_bytes,
+ s.sent_txns,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, filtered_bytes, sent_txns, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index 430c1246d14..68501aa6ad5 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that filtered_bytes increased due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 3d16c2a800d..011c931dbd3 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index e2c83670053..b772676d6bc 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the filtered_bytes reflects that. We can not test the exact value of
+# filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
base-commit: 1362bc33e025fd2848ff38558f5672e2f0f0c7de
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-12-11 09:38 ` Chao Li <li.evan.chao@gmail.com>
2025-12-17 05:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
3 siblings, 1 reply; 123+ messages in thread
From: Chao Li @ 2025-12-11 09:38 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi, Ashutosh,
I just quickly went through the patch. Obviously I need more time to fully understand the patch, I will do a deep review today. In the meantime, I just caught a nit issue.
> On Dec 11, 2025, at 12:59, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
>
>
> Please review.
>
> [1] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
> [2] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
> [3] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
>
> --
> Best Wishes,
> Ashutosh Bapat
> <v20251211-0001-Report-output-plugin-statistics-in-pg_stat.patch>
1
```
+ linkend="logicaldecoding-output-plugin-callbacks"/>. A descripancy in those
```
Typo: descripancy => discrepancy
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
@ 2025-12-17 05:55 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 02:25 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-12-17 05:55 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi Chao,
On Thu, Dec 11, 2025 at 3:09 PM Chao Li <li.evan.chao@gmail.com> wrote:
>
> Hi, Ashutosh,
>
> I just quickly went through the patch. Obviously I need more time to fully understand the patch, I will do a deep review today. In the meantime, I just caught a nit issue.
>
Thanks for your review.
> > On Dec 11, 2025, at 12:59, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
> >
> >
> > Please review.
> >
> > [1] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
> > [2] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
> > [3] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
> >
> > --
> > Best Wishes,
> > Ashutosh Bapat
> > <v20251211-0001-Report-output-plugin-statistics-in-pg_stat.patch>
>
> 1
> ```
> + linkend="logicaldecoding-output-plugin-callbacks"/>. A descripancy in those
> ```
>
> Typo: descripancy => discrepancy
>
Thanks for pointing this out. I have fixed it my code. However, at
this point I am looking for a design review, especially to verify that
the new implementation addresses Andres's concern raised in [1] while
not introducing any design issues raised earlier e.g. those raised in
threads [2], [3] and [4]
[1] https://www.postgresql.org/message-id/zzidfgaowvlv4opptrcdlw57vmulnh7gnes4aerl6u35mirelm@tj2vzseptkj...
> > [2] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
> > [3] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
> > [4] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-17 05:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-12-18 02:25 ` Chao Li <li.evan.chao@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Chao Li @ 2025-12-18 02:25 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
> On Dec 17, 2025, at 13:55, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
>
> Thanks for pointing this out. I have fixed it my code. However, at
> this point I am looking for a design review, especially to verify that
> the new implementation addresses Andres's concern raised in [1] while
> not introducing any design issues raised earlier e.g. those raised in
> threads [2], [3] and [4]
>
> [1] https://www.postgresql.org/message-id/zzidfgaowvlv4opptrcdlw57vmulnh7gnes4aerl6u35mirelm@tj2vzseptkj...
>>> [2] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
>>> [3] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
>>> [4] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
>
> --
> Best Wishes,
> Ashutosh Bapat
Hi Ashutosh,
Yeah, I owe you a review. I committed to review this patch but I forgot, sorry about that.
From design perspective, I agree increasing counters should belong to the core, plugin should return properly values following the contract. And I got some more comments:
1. I just feel a bool return value might not be clear enough. For example:
```
- ctx->callbacks.change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
```
You increase filteredBytes when change_cb returns false. But if we look at pgoutput_change(), there are many reasons to return false. Counting all the cases to filteredBytes seems wrong.
2.
```
- ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
```
Row filter doesn’t impact TRUNCATE, why increase filteredBytes after truncate_cb()?
3.
```
- ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
```
For 2-phase commit, it increase sentTxns after prepare_cb, and
```
+ if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
+ cache->sentTxns++;
```
If the transaction is aborted, sentTxns is increased again, which is confusing. Though for aborting there is some data (a notification) is streamed, but I don’t think that should be counted as a transaction.
After commit, sentTxns is also increased, so that, a 2-phase commit is counted as two transactions, which feels also confusing. IMO, a 2-phase commit should still be counted as one transaction.
4. You add sentBytes and filteredBytes. I am thinking if it makes sense to also add sentRows and filteredRows. Because tables could be big or small, bytes + rows could show a more clear picture to users.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-17 05:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 02:25 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
@ 2025-12-18 12:52 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-19 01:53 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-12-18 12:52 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Thu, Dec 18, 2025 at 7:56 AM Chao Li <li.evan.chao@gmail.com> wrote:
>
>
>
> > On Dec 17, 2025, at 13:55, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > Thanks for pointing this out. I have fixed it my code. However, at
> > this point I am looking for a design review, especially to verify that
> > the new implementation addresses Andres's concern raised in [1] while
> > not introducing any design issues raised earlier e.g. those raised in
> > threads [2], [3] and [4]
> >
> > [1] https://www.postgresql.org/message-id/zzidfgaowvlv4opptrcdlw57vmulnh7gnes4aerl6u35mirelm@tj2vzseptkj...
> >>> [2] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
> >>> [3] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
> >>> [4] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
> >
> > --
> > Best Wishes,
> > Ashutosh Bapat
>
>
> Hi Ashutosh,
>
> Yeah, I owe you a review. I committed to review this patch but I forgot, sorry about that.
>
> From design perspective, I agree increasing counters should belong to the core, plugin should return properly values following the contract. And I got some more comments:
>
> 1. I just feel a bool return value might not be clear enough. For example:
>
> ```
> - ctx->callbacks.change_cb(ctx, txn, relation, change);
> + if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
> + cache->filteredBytes += ReorderBufferChangeSize(change);
> ```
>
> You increase filteredBytes when change_cb returns false. But if we look at pgoutput_change(), there are many reasons to return false. Counting all the cases to filteredBytes seems wrong.
I am not able to understand this. Every "return false" from
pgoutput_change() indicates that the change was filtered out and hence
the size of corresponding change is being added to filteredBytes by
the caller. Which "return false" does not indicate a filtered out
change?
>
> 2.
> ```
> - ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
> + if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
> + cache->filteredBytes += ReorderBufferChangeSize(change);
> ```
>
> Row filter doesn’t impact TRUNCATE, why increase filteredBytes after truncate_cb()?
A TRUNCATE of a relation which is not part of the publication will be
filtered out.
>
> 3.
> ```
> - ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
> + if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
> + cache->sentTxns++;
> ```
>
> For 2-phase commit, it increase sentTxns after prepare_cb, and
> ```
> + if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
> + cache->sentTxns++;
> ```
>
> If the transaction is aborted, sentTxns is increased again, which is confusing. Though for aborting there is some data (a notification) is streamed, but I don’t think that should be counted as a transaction.
>
> After commit, sentTxns is also increased, so that, a 2-phase commit is counted as two transactions, which feels also confusing. IMO, a 2-phase commit should still be counted as one transaction.
stream_commit/abort_cb is called after stream_prepare_cb not after prepare_cb.
>
> 4. You add sentBytes and filteredBytes. I am thinking if it makes sense to also add sentRows and filteredRows. Because tables could be big or small, bytes + rows could show a more clear picture to users.
We don't have corresponding total_rows and streamed_rows counts. I
think that's because we haven't come across a use case for them. Do
you have a use case in mind?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-17 05:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 02:25 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-12-19 01:53 ` Chao Li <li.evan.chao@gmail.com>
2025-12-19 08:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Chao Li @ 2025-12-19 01:53 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
> On Dec 18, 2025, at 20:52, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
>
> On Thu, Dec 18, 2025 at 7:56 AM Chao Li <li.evan.chao@gmail.com> wrote:
>>
>>
>>
>>> On Dec 17, 2025, at 13:55, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
>>>
>>> Thanks for pointing this out. I have fixed it my code. However, at
>>> this point I am looking for a design review, especially to verify that
>>> the new implementation addresses Andres's concern raised in [1] while
>>> not introducing any design issues raised earlier e.g. those raised in
>>> threads [2], [3] and [4]
>>>
>>> [1] https://www.postgresql.org/message-id/zzidfgaowvlv4opptrcdlw57vmulnh7gnes4aerl6u35mirelm@tj2vzseptkj...
>>>>> [2] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
>>>>> [3] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
>>>>> [4] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
>>>
>>> --
>>> Best Wishes,
>>> Ashutosh Bapat
>>
>>
>> Hi Ashutosh,
>>
>> Yeah, I owe you a review. I committed to review this patch but I forgot, sorry about that.
>>
>> From design perspective, I agree increasing counters should belong to the core, plugin should return properly values following the contract. And I got some more comments:
>>
>> 1. I just feel a bool return value might not be clear enough. For example:
>>
>> ```
>> - ctx->callbacks.change_cb(ctx, txn, relation, change);
>> + if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
>> + cache->filteredBytes += ReorderBufferChangeSize(change);
>> ```
>>
>> You increase filteredBytes when change_cb returns false. But if we look at pgoutput_change(), there are many reasons to return false. Counting all the cases to filteredBytes seems wrong.
>
> I am not able to understand this. Every "return false" from
> pgoutput_change() indicates that the change was filtered out and hence
> the size of corresponding change is being added to filteredBytes by
> the caller. Which "return false" does not indicate a filtered out
> change?
I think the confusion comes from the counter name “filteredBytes”, what does “filtered” mean? There are 3 types of data not steaming out:
a. WAL data of tables that doesn’t belong to the publication
b. table belong to the publication, but action doesn’t. For example, FOR ALL TABLES (INSERT), then update/delete will not be streamed out
c. Filtered by row filter (WHERE)
I thought only c should be counted to filteredBytes; thinking over again, maybe b should also be counted. But I still don’t think a should be counted.
IMO, sentBytes + filteredBytes == supposedToSendBytes. If a table doesn’t belong to a publication, then it should not be counted into supposedToSendBytes, so it should not be counted into filteredBytes.
The other point is that, if we count a into filteredBytes, then ends up totalBytes == sendBytes + filteredBytes, if that’s true, why don’t compute such a number by (totalBytes-sendBytes) in client side?
If we insist to count a, then maybe we need to consider a better counter name.
>>
>> 2.
>> ```
>> - ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
>> + if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
>> + cache->filteredBytes += ReorderBufferChangeSize(change);
>> ```
>>
>> Row filter doesn’t impact TRUNCATE, why increase filteredBytes after truncate_cb()?
>
> A TRUNCATE of a relation which is not part of the publication will be
> filtered out.
Same as 1.
>
>>
>> 3.
>> ```
>> - ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
>> + if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
>> + cache->sentTxns++;
>> ```
>>
>> For 2-phase commit, it increase sentTxns after prepare_cb, and
>> ```
>> + if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
>> + cache->sentTxns++;
>> ```
>>
>> If the transaction is aborted, sentTxns is increased again, which is confusing. Though for aborting there is some data (a notification) is streamed, but I don’t think that should be counted as a transaction.
>>
>> After commit, sentTxns is also increased, so that, a 2-phase commit is counted as two transactions, which feels also confusing. IMO, a 2-phase commit should still be counted as one transaction.
>
> stream_commit/abort_cb is called after stream_prepare_cb not after prepare_cb.
That’s my typo, but the problem is still there. Should we count a 2-phase-commit as 2 transactions?
>
>>
>> 4. You add sentBytes and filteredBytes. I am thinking if it makes sense to also add sentRows and filteredRows. Because tables could be big or small, bytes + rows could show a more clear picture to users.
>
> We don't have corresponding total_rows and streamed_rows counts. I
> think that's because we haven't come across a use case for them. Do
> you have a use case in mind?
>
That’s still related to 1. totalBytes includes tables don’t belong to the publication, thus totalRows doesn’t make much sense. But sendRows will only include those rows belonging to the publication. For filterRows, if we exclude a, then I believe filterRows also makes sense.
If you argue that “rows” request should be treated in a separate thread, I’ll be okay with that.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-17 05:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 02:25 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-19 01:53 ` Re: Report bytes and transactions actually sent downtream Chao Li <li.evan.chao@gmail.com>
@ 2025-12-19 08:53 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2025-12-19 08:53 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Fri, Dec 19, 2025 at 7:24 AM Chao Li <li.evan.chao@gmail.com> wrote:
>
>
>
> > On Dec 18, 2025, at 20:52, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Thu, Dec 18, 2025 at 7:56 AM Chao Li <li.evan.chao@gmail.com> wrote:
> >>
> >>
> >>
> >>> On Dec 17, 2025, at 13:55, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
> >>>
> >>> Thanks for pointing this out. I have fixed it my code. However, at
> >>> this point I am looking for a design review, especially to verify that
> >>> the new implementation addresses Andres's concern raised in [1] while
> >>> not introducing any design issues raised earlier e.g. those raised in
> >>> threads [2], [3] and [4]
> >>>
> >>> [1] https://www.postgresql.org/message-id/zzidfgaowvlv4opptrcdlw57vmulnh7gnes4aerl6u35mirelm@tj2vzseptkj...
> >>>>> [2] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
> >>>>> [3] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
> >>>>> [4] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
> >>>
> >>> --
> >>> Best Wishes,
> >>> Ashutosh Bapat
> >>
> >>
> >> Hi Ashutosh,
> >>
> >> Yeah, I owe you a review. I committed to review this patch but I forgot, sorry about that.
> >>
> >> From design perspective, I agree increasing counters should belong to the core, plugin should return properly values following the contract. And I got some more comments:
> >>
> >> 1. I just feel a bool return value might not be clear enough. For example:
> >>
> >> ```
> >> - ctx->callbacks.change_cb(ctx, txn, relation, change);
> >> + if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
> >> + cache->filteredBytes += ReorderBufferChangeSize(change);
> >> ```
> >>
> >> You increase filteredBytes when change_cb returns false. But if we look at pgoutput_change(), there are many reasons to return false. Counting all the cases to filteredBytes seems wrong.
> >
> > I am not able to understand this. Every "return false" from
> > pgoutput_change() indicates that the change was filtered out and hence
> > the size of corresponding change is being added to filteredBytes by
> > the caller. Which "return false" does not indicate a filtered out
> > change?
>
> I think the confusion comes from the counter name “filteredBytes”, what does “filtered” mean? There are 3 types of data not steaming out:
>
> a. WAL data of tables that doesn’t belong to the publication
> b. table belong to the publication, but action doesn’t. For example, FOR ALL TABLES (INSERT), then update/delete will not be streamed out
> c. Filtered by row filter (WHERE)
>
> I thought only c should be counted to filteredBytes; thinking over again, maybe b should also be counted. But I still don’t think a should be counted.
>
> IMO, sentBytes + filteredBytes == supposedToSendBytes. If a table doesn’t belong to a publication, then it should not be counted into supposedToSendBytes, so it should not be counted into filteredBytes.
>
> The other point is that, if we count a into filteredBytes, then ends up totalBytes == sendBytes + filteredBytes, if that’s true, why don’t compute such a number by (totalBytes-sendBytes) in client side?
>
> If we insist to count a, then maybe we need to consider a better counter name.
>
> >>
> >> 2.
> >> ```
> >> - ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
> >> + if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
> >> + cache->filteredBytes += ReorderBufferChangeSize(change);
> >> ```
> >>
> >> Row filter doesn’t impact TRUNCATE, why increase filteredBytes after truncate_cb()?
> >
> > A TRUNCATE of a relation which is not part of the publication will be
> > filtered out.
>
> Same as 1.
>
filtered_bytes is the amount of data filtered out of total_bytes.
Since total_bytes accounts for the changes from tables which are not
included in the publications, filtered_bytes should include them since
they are "filtered" from total_bytes. Hence include a in
filtered_bytes. Quoting from the document
--
Amount of changes, from
<structfield>total_wal_bytes</structfield>, filtered
out by the output plugin and not sent downstream. Please note that it
does not include the changes filtered before a change is sent to
the output plugin, e.g. the changes filtered by origin.
--
sent_bytes is related but different metric. From the documentation
--
Amount of transaction changes, in the output format, sent downstream for
this slot by the output plugin.
--
Assumption sentBytes + filteredBytes == supposedToSendBytes. is wrong.
Since filtered_bytes were never converted into the output format we
don't know how many bytes would have been sent downstream, had those
bytes not been filtered. We will never know how much supposedToSend
bytes would be. ALso note that sent_bytes + filtered_bytes is not the
same as total_wal_bytes.
> >
> >>
> >> 3.
> >> ```
> >> - ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
> >> + if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
> >> + cache->sentTxns++;
> >> ```
> >>
> >> For 2-phase commit, it increase sentTxns after prepare_cb, and
> >> ```
> >> + if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
> >> + cache->sentTxns++;
> >> ```
> >>
> >> If the transaction is aborted, sentTxns is increased again, which is confusing. Though for aborting there is some data (a notification) is streamed, but I don’t think that should be counted as a transaction.
> >>
> >> After commit, sentTxns is also increased, so that, a 2-phase commit is counted as two transactions, which feels also confusing. IMO, a 2-phase commit should still be counted as one transaction.
> >
> > stream_commit/abort_cb is called after stream_prepare_cb not after prepare_cb.
>
> That’s my typo, but the problem is still there. Should we count a 2-phase-commit as 2 transactions?
>
Can you please provide me a repro where a prepared transaction gets
counted twice as sent_txns?
> >
> >>
> >> 4. You add sentBytes and filteredBytes. I am thinking if it makes sense to also add sentRows and filteredRows. Because tables could be big or small, bytes + rows could show a more clear picture to users.
> >
> > We don't have corresponding total_rows and streamed_rows counts. I
> > think that's because we haven't come across a use case for them. Do
> > you have a use case in mind?
> >
>
> That’s still related to 1. totalBytes includes tables don’t belong to the publication, thus totalRows doesn’t make much sense. But sendRows will only include those rows belonging to the publication. For filterRows, if we exclude a, then I believe filterRows also makes sense.
>
> If you argue that “rows” request should be treated in a separate thread, I’ll be okay with that.
I think so. It will be good to provide examples of how this statistics
will be used. A separate thread will be better.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-12-17 08:42 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
3 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-12-17 08:42 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi,
On Thu, Dec 11, 2025 at 10:29:42AM +0530, Ashutosh Bapat wrote:
> Sorry for the delayed response. PFA the patch implementing the idea
> discussed above. It relies on the output plugin callback to return
> correct boolean but maintains the statistics in the core itself.
Thanks for the new patch version!
What worries me is all those API changes:
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
Those changes will break existing third party logical decoding plugin, even ones
that don't want the new statistics features.
What about not changing those and just add a single new optional callback, say?
typedef void (*LogicalDecodeReportStatsCB)(
LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
bool *transaction_sent,
size_t *bytes_filtered
);
This way:
- Existing plugins can still work without modification
- New or existing plugins can choose to provide statistics
Thoughts?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-17 08:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-12-18 12:52 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 18:22 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-12-18 12:52 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi Bertrand,
On Wed, Dec 17, 2025 at 2:12 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> What worries me is all those API changes:
>
> -typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
> +typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
>
> Those changes will break existing third party logical decoding plugin, even ones
> that don't want the new statistics features.
>
> What about not changing those and just add a single new optional callback, say?
>
> typedef void (*LogicalDecodeReportStatsCB)(
> LogicalDecodingContext *ctx,
> ReorderBufferTXN *txn,
> bool *transaction_sent,
> size_t *bytes_filtered
> );
>
> This way:
>
> - Existing plugins can still work without modification
> - New or existing plugins can choose to provide statistics
>
I think that it will bring back the same problems that the previous
design had or am I missing something? Let me elaborate:
1. If every plugin implements the calculation of filtered_bytes
differently, the same set of WAL passed through different output
plugins would report different filtered bytes, even if they filtered
the same changes. I think Andres wants minimal changes in the output
plugins to avoid these divergences.
2. This also has the problem that you had raised. What if an output
plugin had calls to this callback in one version but removed them in
the next.
3. An output plugin may simply not realise that it can use this
function to maintain statistics. Or The plugin may not call the
function in all the places that it needs to. Or It may not realise it
needs to call this function in a new callback added in the new
PostgreSQL version. There are many ways an output plugin may get it
wrong. I think this is also the reason Andres wants minimal changes
output plugin to maintaining statistics.
4. filteredBytes and sentTxns are not updated at the same place, so
the plugins have to send one of those values as 0 always when calling
the function. We need two functions one for each sentTxns and
filteredBytes. That means more chances of error and divergence.
The new implementation does not have these problems
1. As the API is changed in the new implementation, every output
plugin is forced to change their implementation. Amit and I discussed
this aspect starting [1]. The plugins will detect the change when
compiling their code against PG 19, so they won't miss it. The change
expected from every plugin is minimal and well documented. They have
to simply return true or false and rest will be taken care of by the
core. So there is less chance of error or divergence.
2. The plugin can not go back and forth on maintaining the statistics
- an issue you raised. The API will force it to always return the
required status.
3. I think getting the correct statistics is more important than
making it optional, especially when the changes expected from the
plugin are simple. Thinking more about it, users wouldn't want to
change their output plugin just because other output plugin supports
statistics.
Ideally, it would have been better if this was raised when Myself and
Amit discussed this proposal [1], a month ago; before I spent time and
effort implementing the design. But better now than before a commit.
[1] https://www.postgresql.org/message-id/CAA4eK1K4Pq=acoXx3dEF7us_NFrDVU+M7f_j7KXm+Q2ywY+LSQ@mail.gmail...
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-17 08:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-12-18 18:22 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-19 07:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2025-12-18 18:22 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi,
On Thu, Dec 18, 2025 at 06:22:40PM +0530, Ashutosh Bapat wrote:
> Hi Bertrand,
>
> On Wed, Dec 17, 2025 at 2:12 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > What worries me is all those API changes:
> >
> > -typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
> > +typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
> >
> > Those changes will break existing third party logical decoding plugin, even ones
> > that don't want the new statistics features.
> >
> > What about not changing those and just add a single new optional callback, say?
> >
> > typedef void (*LogicalDecodeReportStatsCB)(
> > LogicalDecodingContext *ctx,
> > ReorderBufferTXN *txn,
> > bool *transaction_sent,
> > size_t *bytes_filtered
> > );
> >
> > This way:
> >
> > - Existing plugins can still work without modification
> > - New or existing plugins can choose to provide statistics
> >
>
> I think that it will bring back the same problems that the previous
> design had or am I missing something?
I think that my example was confusing due to "size_t *bytes_filtered". I think
that what we could do is something like:
"
typedef void (*LogicalDecodeReportStatsCB)(
LogicalDecodingContext *ctx,
LogicalDecodeEventType event_type,
bool *filtered,
bool *txn_sent);
"
Note that there is no more size_t.
Then for, for example in change_cb_wrapper(), we could do:
"
ctx->callbacks.change_cb(ctx, txn, relation, change);
if (ctx->callbacks.report_stats_cb)
{
bool filtered = false;
ctx->callbacks.report_stats_cb(ctx, LOGICALDECODE_CHANGE,
&filtered, NULL);
if (filtered)
cache->filteredBytes += ReorderBufferChangeSize(change);
}
"
The plugin would need to "remember" that it filtered (so that it can
reply to the callback). It could do that by adding say "last_event_filtered" to
it's output_plugin_private structure.
That's more work on the plugin side and we would probably need to provide some
examples from our side.
I think the pros are that:
- plugins that don't want to report stats would have nothing to do (no breaking
changes)
- the core does the computation
Thoughts?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-17 08:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 18:22 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2025-12-19 07:02 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-19 07:51 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2025-12-19 07:02 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Thu, Dec 18, 2025 at 11:52 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Thu, Dec 18, 2025 at 06:22:40PM +0530, Ashutosh Bapat wrote:
> > Hi Bertrand,
> >
> > On Wed, Dec 17, 2025 at 2:12 PM Bertrand Drouvot
> > <bertranddrouvot.pg@gmail.com> wrote:
> > >
> > > What worries me is all those API changes:
> > >
> > > -typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
> > > +typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
> > >
> > > Those changes will break existing third party logical decoding plugin, even ones
> > > that don't want the new statistics features.
> > >
> > > What about not changing those and just add a single new optional callback, say?
> > >
> > > typedef void (*LogicalDecodeReportStatsCB)(
> > > LogicalDecodingContext *ctx,
> > > ReorderBufferTXN *txn,
> > > bool *transaction_sent,
> > > size_t *bytes_filtered
> > > );
> > >
> > > This way:
> > >
> > > - Existing plugins can still work without modification
> > > - New or existing plugins can choose to provide statistics
> > >
> >
> > I think that it will bring back the same problems that the previous
> > design had or am I missing something?
>
> I think that my example was confusing due to "size_t *bytes_filtered". I think
> that what we could do is something like:
>
> "
> typedef void (*LogicalDecodeReportStatsCB)(
> LogicalDecodingContext *ctx,
> LogicalDecodeEventType event_type,
> bool *filtered,
> bool *txn_sent);
> "
>
> Note that there is no more size_t.
>
Thanks for the clarification. It fixes the problem of filteredBytes
divergence. Since the core is calling stats callback, the problem of
plugin not calling the function at appropriate places is also not
there. IIUC, it still has some problems from the previous solution and
some new problems as explained below.
> Then for, for example in change_cb_wrapper(), we could do:
>
> "
> ctx->callbacks.change_cb(ctx, txn, relation, change);
>
> if (ctx->callbacks.report_stats_cb)
> {
> bool filtered = false;
>
> ctx->callbacks.report_stats_cb(ctx, LOGICALDECODE_CHANGE,
> &filtered, NULL);
>
> if (filtered)
> cache->filteredBytes += ReorderBufferChangeSize(change);
> }
> "
>
> The plugin would need to "remember" that it filtered (so that it can
> reply to the callback). It could do that by adding say "last_event_filtered" to
> it's output_plugin_private structure.
Why does the core send NULL for the second parameter? Does the output
plugin have to take care of NULL references too?
I think the core will end up calling this or similar stanza at every
callback since it won't know when the output plugin will have
statistics to report. That's more complexity and wasted CPU cycles in
core.
>
> That's more work on the plugin side and we would probably need to provide some
> examples from our side.
Andres is objecting to this exact thing. IIUC, the code changes there
were far simpler than this proposal. Am I missing something?
My feeling is that the core will end up
>
> I think the pros are that:
>
> - plugins that don't want to report stats would have nothing to do (no breaking
> changes)
I don't think there will be an output plugin which wouldn't want to
take advantage of the statistics. The easier it is for them to adopt
the statistics, as is with my proposal, the better. With this proposal
output plugins have to do more work if they want to support
statistics. That itself will create a barrier for them to adopt the
statistics. We want the output plugins to support statistics so that
users can benefit. Let's make it easier for the output plugins to
implement them.
I feel this proposal makes both sides, the core and the output plugin
complex in pursuit of a goal which is not worth it.
This stil has the problem that you had raised. What if an output
plugin stops supporting statistics across versions?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-17 08:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-18 12:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 18:22 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-19 07:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-12-19 07:51 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: Bertrand Drouvot @ 2025-12-19 07:51 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi,
On Fri, Dec 19, 2025 at 12:32:49PM +0530, Ashutosh Bapat wrote:
> On Thu, Dec 18, 2025 at 11:52 PM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.com> wrote:
> >
> > I think that my example was confusing due to "size_t *bytes_filtered". I think
> > that what we could do is something like:
> >
> > "
> > typedef void (*LogicalDecodeReportStatsCB)(
> > LogicalDecodingContext *ctx,
> > LogicalDecodeEventType event_type,
> > bool *filtered,
> > bool *txn_sent);
> > "
> >
> > Note that there is no more size_t.
> >
>
> Thanks for the clarification. It fixes the problem of filteredBytes
> divergence. Since the core is calling stats callback, the problem of
> plugin not calling the function at appropriate places is also not
> there.
Yeah.
> IIUC, it still has some problems from the previous solution and
> some new problems as explained below.
>
> > Then for, for example in change_cb_wrapper(), we could do:
> >
> > "
> > ctx->callbacks.change_cb(ctx, txn, relation, change);
> >
> > if (ctx->callbacks.report_stats_cb)
> > {
> > bool filtered = false;
> >
> > ctx->callbacks.report_stats_cb(ctx, LOGICALDECODE_CHANGE,
> > &filtered, NULL);
> >
> > if (filtered)
> > cache->filteredBytes += ReorderBufferChangeSize(change);
> > }
> > "
> >
> > The plugin would need to "remember" that it filtered (so that it can
> > reply to the callback). It could do that by adding say "last_event_filtered" to
> > it's output_plugin_private structure.
>
>
> Why does the core send NULL for the second parameter? Does the output
> plugin have to take care of NULL references too?
It was just a quick example. I was more focused on demonstrating the concept than
the exact API details.
>
> I think the core will end up calling this or similar stanza at every
> callback since it won't know when the output plugin will have
> statistics to report.
Yes.
> That's more complexity and wasted CPU cycles in core.
I think that should be negligible as compared to what the logical decoding is
already doing at those places.
> > That's more work on the plugin side and we would probably need to provide some
> > examples from our side.
>
> Andres is objecting to this exact thing. IIUC, the code changes there
> were far simpler than this proposal. Am I missing something?
You are right. My main motivation with this idea was to avoid the APIs break.
But maybe that's not worth it.
> I don't think there will be an output plugin which wouldn't want to
> take advantage of the statistics. The easier it is for them to adopt
> the statistics, as is with my proposal, the better. With this proposal
> output plugins have to do more work if they want to support
> statistics. That itself will create a barrier for them to adopt the
> statistics. We want the output plugins to support statistics so that
> users can benefit. Let's make it easier for the output plugins to
> implement them.
That was the main point. With your proposal, the APIs break will occur (and so
the plugin will need some changes) even if they don't want the stats. But, if
we are confident that most (all?) would want to use it, then I agree that your
proposal is better and that's fine by me to move forward with yours.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-01-12 05:11 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
3 siblings, 0 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2026-01-12 05:11 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; Andres Freund <andres@anarazel.de>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Hi Amit and Andres,
On Thu, Dec 11, 2025 at 10:29 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> Sorry for the delayed response. PFA the patch implementing the idea
> discussed above. It relies on the output plugin callback to return
> correct boolean but maintains the statistics in the core itself.
>
> I have reviewed all the previous comments and applied the ones which
> are relevant to the new approach again. Following two are worth noting
> here.
>
> In order to address Amit's concern [1] that an inaccuracy in these
> counts because of a bug in output plugin code may be blamed on the
> core, I have added a note in the documentation of view
> pg_stat_replication_slot in order to avoid such a blame and also
> directing users to plugin they should investigate.
>
> With the statistics being maintained by the core, Bertrand's concern
> about stale statistics [2] are also addressed. Also it does not have
> the asymmetry mentioned in point 2 in [3].
>
> Please review.
>
> [1] https://www.postgresql.org/message-id/CAA4eK1KzYaq9dcaa20Pv44ewomUPj_PbbeLfEnvzuXYMZtNw0A%40mail.gma...
> [2] https://www.postgresql.org/message-id/aNZ1T5vYC1BtKs4M@ip-10-97-1-34.eu-west-3.compute.internal
> [3] https://www.postgresql.org/message-id/CAExHW5tfVHABuv1moL_shp7oPrWmg8ha7T8CqwZxiMrKror7iw%40mail.gma...
Andres, Can you please review the new implementation and let me know
whether it addresses the concern you raised in [4]
Amit, does it address your concerns in [1] (see above references) reasonably?
[4] https://www.postgresql.org/message-id/zzidfgaowvlv4opptrcdlw57vmulnh7gnes4aerl6u35mirelm@tj2vzseptkj...
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-01-27 17:38 ` Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
3 siblings, 1 reply; 123+ messages in thread
From: Andres Freund @ 2026-01-27 17:38 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi,
On 2025-12-11 10:29:42 +0530, Ashutosh Bapat wrote:
> Please review.
I'd simplify the patch to, initially, to just track the sent bytes. For one,
that's by *far* the most useful statistic. But I also have some concerns
about the other stats:
- To me filteredBytes is a pretty bogus number - the size that the output
plugin would have sent and ReorderBufferChangeSize() are only kinda
related. It'll be a hard number to interpret, I think.
It also seems to not account for filtering that happens based on the origin
id.
- I don't have fundamental opposition to tracking the number of sent
transactions, but I think the implementation is at the wrong place.
I think we ought to add explicit support for output plugins to filter
transactions. Calling output plugins once for each change in a large
transaction, which we already decided to not send out, makes no sense. It's
far from free to do all the setup to decode a tuple, if the transaction is
filtered, we shouldn't do that.
It's also far far from free to restore changes from disk if we are going to
throw away the whole transaction.
The current way requires each output plugin to maintain its own tracking
about whether it decided to not output the transaction, which doesn't seem
right to me.
I'm also just not sure how useful it is, because most of the time we're
going to filter on a per-change basis (e.g. only rels in a publication). But
that's only sometimes going to affect the numbers of sent transactions.
I'm not convinced as-is it's worth the breakage of all output plugins.
Greetings,
Andres
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
@ 2026-02-02 08:36 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-02-02 08:36 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Tue, Jan 27, 2026 at 11:08 PM Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> On 2025-12-11 10:29:42 +0530, Ashutosh Bapat wrote:
> > Please review.
>
> I'd simplify the patch to, initially, to just track the sent bytes. For one,
> that's by *far* the most useful statistic. But I also have some concerns
> about the other stats:
>
Ok. I have split the patch into two
0001 to track sent_bytes
0002 to track filtered_bytes and sent_txns
>
> - To me filteredBytes is a pretty bogus number - the size that the output
> plugin would have sent and ReorderBufferChangeSize() are only kinda
> related. It'll be a hard number to interpret, I think.
>
> It also seems to not account for filtering that happens based on the origin
> id.
>
total_bytes doesn't count the amount of changes that were never added
to the reorder buffer including those filtered based on the origin.
filtered_bytes is supposed to report the amount of changes out of
total_bytes that were filtered by the output plugin. It acts as an
indicator of filtering efficiency of a publication or whatever
filtering mechanism is employed by the output plugin.
>
> - I don't have fundamental opposition to tracking the number of sent
> transactions, but I think the implementation is at the wrong place.
>
> I think we ought to add explicit support for output plugins to filter
> transactions. Calling output plugins once for each change in a large
> transaction, which we already decided to not send out, makes no sense. It's
> far from free to do all the setup to decode a tuple, if the transaction is
> filtered, we shouldn't do that.
>
> It's also far far from free to restore changes from disk if we are going to
> throw away the whole transaction.
All the transactions that decided not to be sent out e.g. the
transactions committed before a confirmed_flush_lsn or the
transactions from filtered origins never reach the reorder buffer.
They don't have the problems you mention above. These transactions are
not subject of sent_txns at all.
>
> The current way requires each output plugin to maintain its own tracking
> about whether it decided to not output the transaction, which doesn't seem
> right to me.
The transactions which are sent downstream after applying transaction
level filtering by the output plugin are counted by sent_txns. Right
now these are the transactions whose all changes have been filtered
out by the output plugin. The output plugin can realize only at the
time of decoding the end of the transaction that it has not sent any
changes for that transaction and filter it out. It can not report
earlier than that. So I don't see any other way to implement the
counter.
If it would have been the case that the output plugin could know that
a transaction is going to get filtered completely when decoding one of
the changes, what you are suggesting would be helpful. But that's not
the case today.
>
> I'm also just not sure how useful it is, because most of the time we're
> going to filter on a per-change basis (e.g. only rels in a publication). But
> that's only sometimes going to affect the numbers of sent transactions.
>
>
> I'm not convinced as-is it's worth the breakage of all output plugins.
Hmm. I do see a usecase for both filtered_bytes and sent_txns as
indicators of filtering efficiency of output plugin. But not everybody
will see it worth breaking all output plugins.
I think we all agree that sent_bytes is useful, so I suggest that we
review and commit 0001. We can debate about 0002 after that.
--
Best Wishes,
Ashutosh Bapat
Attachments: download all (2 files, .tar.gz)
v20260202-0001-Number-of-bytes-sent-downstream-by-logical.patch (text/x-patch, 30.7K) download
From 9dedd0dc406b25ffbac55bedefb00cf383f7490e Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 30 Jan 2026 17:10:37 +0530
Subject: [PATCH v20260202 1/2] Number of bytes sent downstream by logical wal
sender
pg_stat_replication_slots reports the number of bytes added to the reorder
buffer, but it does not report the number of bytes sent downstream. This
statistics is useful when investigating issues related to a slow downstream.
total_bytes and total_txns are metrics related to the contents of the WAL that
are added to the reorder buffer. However sent_bytes is related to the data
output by output plugin. They are not related. But the current naming and the
documentation suggest that they are related. Hence rename them total_wal_bytes
and total_wal_txns respectively to indicate that those counts come from WAL.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 +++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 17 +++----
doc/src/sgml/monitoring.sgml | 23 ++++++---
src/backend/catalog/system_views.sql | 5 +-
src/backend/replication/logical/logical.c | 11 +++--
.../replication/logical/logicalfuncs.c | 8 ++++
.../replication/logical/reorderbuffer.c | 1 +
src/backend/replication/walsender.c | 3 ++
src/backend/utils/activity/pgstat_replslot.c | 5 +-
src/backend/utils/adt/pgstatfuncs.c | 29 ++++++-----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 5 +-
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
.../t/035_standby_logical_decoding.pl | 4 +-
src/test/regress/expected/rules.out | 7 +--
17 files changed, 114 insertions(+), 78 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..514db8563a8 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..feb74ba4854 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..c9eaa53ddae 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -25,8 +25,9 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
- SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ SELECT slot_name, total_wal_txns > 0 AS total_txn,
+ total_wal_bytes > 0 AS total_bytes,
+ sent_bytes > 0 AS sent_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -65,7 +66,7 @@ $node->poll_query_until(
'postgres', qq[
SELECT count(slot_name) >= 4 FROM pg_stat_replication_slots
WHERE slot_name ~ 'regression_slot'
- AND total_txns > 0 AND total_bytes > 0;
+ AND total_wal_txns > 0 AND total_wal_bytes > 0;
]) or die "Timed out while waiting for statistics to be updated";
# Test to drop one of the replication slot and verify replication statistics data is
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index b77d189a500..70c217b2c1a 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1635,19 +1635,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_txns</structfield> <type>bigint</type>
+ <structfield>total_wal_txns</structfield> <type>bigint</type>
</para>
<para>
- Number of decoded transactions sent to the decoding output plugin for
- this slot. This counts top-level transactions only, and is not incremented
- for subtransactions. Note that this includes the transactions that are
- streamed and/or spilled.
+ Number of decoded transactions from WAL sent to the decoding output
+ plugin for this slot. This counts top-level transactions only, and is
+ not incremented for subtransactions. Note that this includes the
+ transactions that are streamed and/or spilled.
</para></entry>
</row>
<row>
<entry role="catalog_table_entry"><para role="column_definition">
- <structfield>total_bytes</structfield><type>bigint</type>
+ <structfield>total_wal_bytes</structfield><type>bigint</type>
</para>
<para>
Amount of transaction data decoded for sending transactions to the
@@ -1657,6 +1657,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of transaction changes, in the output format, sent downstream for
+ this slot by the output plugin.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 7553f31fef0..763231265a7 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1075,8 +1075,9 @@ CREATE VIEW pg_stat_replication_slots AS
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 85060d19a49..3288bb43aed 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1950,7 +1950,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1960,7 +1960,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->sentBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1969,8 +1970,9 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.total_wal_txns = rb->totalTxns;
+ repSlotStat.total_wal_bytes = rb->totalBytes;
+ repSlotStat.sent_bytes = rb->sentBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1983,6 +1985,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->sentBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 9760818941d..b8a9209c300 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 sentBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ sentBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ sentBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,8 +90,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ sentBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += sentBytes;
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 2d2a6d5e9e7..2ee980aa859 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -393,6 +393,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index a0e6a3d200c..1b4b639dedb 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1593,6 +1593,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 168ef8f8f45..de174d8ec2e 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -94,8 +94,9 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(stream_count);
REPLSLOT_ACC(stream_bytes);
REPLSLOT_ACC(mem_exceeded_count);
- REPLSLOT_ACC(total_txns);
- REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(total_wal_txns);
+ REPLSLOT_ACC(total_wal_bytes);
+ REPLSLOT_ACC(sent_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 73ca0bb0b7f..496170b3d5b 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2129,7 +2129,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2156,15 +2156,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_wal_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "sent_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2188,19 +2190,20 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[5] = Int64GetDatum(slotent->stream_count);
values[6] = Int64GetDatum(slotent->stream_bytes);
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[8] = Int64GetDatum(slotent->total_wal_txns);
+ values[9] = Int64GetDatum(slotent->total_wal_bytes);
+ values[10] = Int64GetDatum(slotent->sent_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 5e5e33f64fc..f323500c95d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5700,9 +5700,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index fff7ecc2533..954839ebd16 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -398,8 +398,9 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter stream_count;
PgStat_Counter stream_bytes;
PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
+ PgStat_Counter total_wal_txns;
+ PgStat_Counter total_wal_bytes;
+ PgStat_Counter sent_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 2d717a9e152..d3a6c7cd85b 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..e639d0bb709 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_wal_bytes > 0, sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_wal_bytes = 0, sent_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_wal_bytes and sent_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index d264a698ff6..0782f1fc569 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -577,7 +577,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT 100,'100';]);
$node_standby->poll_query_until('testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
) or die "replication slot stats of vacuum_full_activeslot not updated";
# This should trigger the conflict
@@ -605,7 +605,7 @@ ok( $stderr =~
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby->safe_psql(
'testdb',
- qq[SELECT total_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
+ qq[SELECT total_wal_txns > 0 FROM pg_stat_replication_slots WHERE slot_name = 'vacuum_full_activeslot']
),
't',
'replication slot stats not removed after invalidation');
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index f4ee2bd7459..fc77720c535 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2169,13 +2169,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.stream_count,
s.stream_bytes,
s.mem_exceeded_count,
- s.total_txns,
- s.total_bytes,
+ s.total_wal_txns,
+ s.total_wal_bytes,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
base-commit: a9afa021e95f2b0ffaaf26f3a27e685f634f4ac9
--
2.34.1
v20260202-0002-Report-output-plugin-statistics-in-pg_stat.patch (text/x-patch, 73.7K) download
From c26ef13bf588f04584d26de3ddc5547c79df55e9 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 30 Jan 2026 17:32:05 +0530
Subject: [PATCH v20260202 2/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output statistics like the amount of data
filtered by the output plugin, or the
number of transactions sent downstream. This statistics is useful when
investigating issues related to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- filtered_bytes is the amount of changes filtered out by the
output plugin
- sent_txns is the amount of transactions sent downstream by the
output plugin
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Though these counts are stored and maintained by the core, they require
the output plugin to return correct values to the relevant callbacks.
This has been added as note in the documentation. In order to aid
debugging descripancies in these counter, name of the output plugin is
added to the view for an easy reference.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++-------
contrib/test_decoding/sql/stats.sql | 15 ++-
contrib/test_decoding/t/001_repl_stats.pl | 15 ++-
contrib/test_decoding/test_decoding.c | 55 ++++++-----
doc/src/sgml/logicaldecoding.sgml | 96 ++++++++++++++-----
doc/src/sgml/monitoring.sgml | 47 +++++++++
src/backend/catalog/system_views.sql | 3 +
src/backend/replication/logical/logical.c | 35 +++++--
.../replication/logical/reorderbuffer.c | 5 +-
src/backend/replication/pgoutput/pgoutput.c | 65 +++++++++----
src/backend/utils/activity/pgstat_replslot.c | 2 +
src/backend/utils/adt/pgstatfuncs.c | 28 +++---
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 2 +
src/include/replication/output_plugin.h | 43 +++++----
src/include/replication/reorderbuffer.h | 5 +
src/test/regress/expected/rules.out | 5 +-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 ++++
src/test/subscription/t/028_row_filter.pl | 11 +++
20 files changed, 386 insertions(+), 160 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index 514db8563a8..d2f9ddd6417 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | mem_exceeded_count
-------------------------+------------+-------------+----------------+-----------------+------------+--------------------
- regression_slot_stats1 | t | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t | t
+-- total_wal_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Usually we
+-- expect filtered_bytes to be 0 since the entire transaction executed by this
+-- test is replicated. But there may be some background transactions, changes
+-- from which are filtered out by the output plugin, so we check for >= 0 here.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | sent_txns | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------+-----------+----------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | mem_exceeded_count
-------------------------+------------+-------------+----------------+-----------------+------------+--------------------
- regression_slot_stats1 | t | t | f | f | f | t
- regression_slot_stats2 | t | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | sent_txns | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------+-----------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | 0 | t | t
+ regression_slot_stats2 | t | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | mem_exceeded_count
-------------------------+------------+-------------+----------------+-----------------+------------+--------------------
- regression_slot_stats1 | t | t | f | f | 0 | t
- regression_slot_stats2 | t | t | f | f | 0 | t
- regression_slot_stats3 | t | t | f | f | 0 | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_wal_txns | total_wal_bytes | sent_bytes | sent_txns | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+----------------+-----------------+------------+-----------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | 0 | t | t
+ regression_slot_stats2 | t | t | f | f | 0 | 0 | t | t
+ regression_slot_stats3 | t | t | f | f | 0 | 0 | t | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | filtered_bytes | sent_txns | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+----------------+-----------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_wal_txns | total_wal_bytes | filtered_bytes | sent_txns | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+----------------+-----------------+----------------+-----------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index feb74ba4854..271a13cfba8 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -16,16 +16,21 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+-- total_wal_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Usually we
+-- expect filtered_bytes to be 0 since the entire transaction executed by this
+-- test is replicated. But there may be some background transactions, changes
+-- from which are filtered out by the output plugin, so we check for >= 0 here.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_wal_txns > 0 AS total_wal_txns, total_wal_bytes > 0 AS total_wal_bytes, sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -47,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index c9eaa53ddae..38431dcafd6 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,15 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, filtered_bytes may be greater than 0. But it's not guaranteed that
+ # such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_wal_txns > 0 AS total_txn,
total_wal_bytes > 0 AS total_bytes,
+ filtered_bytes >= 0 AS filtered_bytes,
+ sent_txns > 0 AS sent_txn,
sent_bytes > 0 AS sent_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
@@ -81,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t|t
-regression_slot2|t|t|t
-regression_slot3|t|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -105,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t|t
-regression_slot2|t|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index d5cf0fa02b0..c1271a01e0d 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -60,12 +60,12 @@ static void pg_output_begin(LogicalDecodingContext *ctx,
TestDecodingData *data,
ReorderBufferTXN *txn,
bool last_write);
-static void pg_decode_commit_txn(LogicalDecodingContext *ctx,
+static bool pg_decode_commit_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
-static void pg_decode_change(LogicalDecodingContext *ctx,
+static bool pg_decode_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, Relation relation,
ReorderBufferChange *change);
-static void pg_decode_truncate(LogicalDecodingContext *ctx,
+static bool pg_decode_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change);
@@ -80,7 +80,7 @@ static bool pg_decode_filter_prepare(LogicalDecodingContext *ctx,
const char *gid);
static void pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pg_decode_prepare_txn(LogicalDecodingContext *ctx,
+static bool pg_decode_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
static void pg_decode_commit_prepared_txn(LogicalDecodingContext *ctx,
@@ -98,16 +98,16 @@ static void pg_output_stream_start(LogicalDecodingContext *ctx,
bool last_write);
static void pg_decode_stream_stop(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pg_decode_stream_abort(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_abort(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
-static void pg_decode_stream_prepare(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_prepare(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
-static void pg_decode_stream_commit(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_commit(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
-static void pg_decode_stream_change(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -115,7 +115,7 @@ static void pg_decode_stream_message(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr lsn,
bool transactional, const char *prefix,
Size sz, const char *message);
-static void pg_decode_stream_truncate(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change);
@@ -318,7 +318,7 @@ pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBuff
}
/* COMMIT callback */
-static void
+static bool
pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
{
@@ -330,7 +330,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
txn->output_plugin_private = NULL;
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
if (data->include_xids)
@@ -343,6 +343,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/* BEGIN PREPARE callback */
@@ -367,7 +368,7 @@ pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
}
/* PREPARE callback */
-static void
+static bool
pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
{
@@ -379,7 +380,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* where the first operation is received for this transaction.
*/
if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -394,6 +395,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/* COMMIT PREPARED callback */
@@ -599,7 +601,7 @@ tuple_to_stringinfo(StringInfo s, TupleDesc tupdesc, HeapTuple tuple, bool skip_
/*
* callback for individual changed tuples
*/
-static void
+static bool
pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
Relation relation, ReorderBufferChange *change)
{
@@ -684,9 +686,10 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
MemoryContextReset(data->context);
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[], ReorderBufferChange *change)
{
@@ -739,6 +742,7 @@ pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
MemoryContextReset(data->context);
OutputPluginWrite(ctx, true);
+ return true;
}
static void
@@ -818,7 +822,7 @@ pg_decode_stream_stop(LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
}
-static void
+static bool
pg_decode_stream_abort(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn)
@@ -842,7 +846,7 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
}
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
if (data->include_xids)
@@ -850,9 +854,10 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
else
appendStringInfoString(ctx->out, "aborting streamed (sub)transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_stream_prepare(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
@@ -861,7 +866,7 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
TestDecodingTxnData *txndata = txn->output_plugin_private;
if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -877,9 +882,10 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_stream_commit(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
@@ -892,7 +898,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
txn->output_plugin_private = NULL;
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -906,6 +912,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -913,7 +920,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
* at a later point in time. We don't want users to see the changes until the
* transaction is committed.
*/
-static void
+static bool
pg_decode_stream_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
@@ -935,6 +942,7 @@ pg_decode_stream_change(LogicalDecodingContext *ctx,
else
appendStringInfoString(ctx->out, "streaming change for transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -981,7 +989,7 @@ pg_decode_stream_message(LogicalDecodingContext *ctx,
* In streaming mode, we don't display the detailed information of Truncate.
* See pg_decode_stream_change.
*/
-static void
+static bool
pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change)
@@ -1001,4 +1009,5 @@ pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
else
appendStringInfoString(ctx->out, "streaming truncate for transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index 6dc49108997..dc37545681c 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -1020,10 +1020,15 @@ typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
rows will have been called before this, if there have been any modified
rows.
<programlisting>
-typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
</programlisting>
+ If the callback outputs the transaction, it is expected to return true;
+ otherwise false. The return value is used to update the
+ <literal>sent_txns</literal> counter reported in <link
+ linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
</para>
</sect3>
@@ -1044,7 +1049,7 @@ typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
this very same transaction. In that case, the logical decoding of this
aborted transaction is stopped gracefully.
<programlisting>
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -1054,8 +1059,12 @@ typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
and <function>commit_cb</function> callbacks, but additionally the
relation descriptor <parameter>relation</parameter> points to the
relation the row belongs to and a struct
- <parameter>change</parameter> describing the row modification are passed
- in.
+ <parameter>change</parameter> describing the row modification are passed in.
+ If the output plugin decoded and output the change, it is expected
+ to return true; otherwise false. This return value is used to update the
+ <structfield>filtered_bytes</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
</para>
<note>
@@ -1075,18 +1084,18 @@ typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
The optional <function>truncate_cb</function> callback is called for a
<command>TRUNCATE</command> command.
<programlisting>
-typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
ReorderBufferChange *change);
</programlisting>
- The parameters are analogous to the <function>change_cb</function>
- callback. However, because <command>TRUNCATE</command> actions on
- tables connected by foreign keys need to be executed together, this
- callback receives an array of relations instead of just a single one.
- See the description of the <xref linkend="sql-truncate"/> statement for
- details.
+ The parameters and the expected return value are analogous to the
+ <function>change_cb</function> callback. However, because
+ <command>TRUNCATE</command> actions on tables connected by foreign keys
+ need to be executed together, this callback receives an array of relations
+ instead of just a single one. See the description of the <xref
+ linkend="sql-truncate"/> statement for details.
</para>
</sect3>
@@ -1219,8 +1228,18 @@ typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
rows will have been called before this, if there have been any modified
rows. The <parameter>gid</parameter> field, which is part of the
<parameter>txn</parameter> parameter, can be used in this callback.
+ If the callback outputs the prepared transaction, it is expected to return
+ true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view. Please
+ note that the return value of this callback suffices to determine
+ whether a prepared transaction was output or not; callbacks
+ <function>commit_prepared_cb</function> and
+ <function>rollback_prepared_cb</function> do not need to return this
+ status again.
<programlisting>
-typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
</programlisting>
@@ -1294,9 +1313,14 @@ typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
<title>Stream Abort Callback</title>
<para>
The required <function>stream_abort_cb</function> callback is called to
- abort a previously streamed transaction.
+ abort a previously streamed transaction. If the output plugin has output
+ the streamed transaction, the callback is expected to return true;
+ otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
<programlisting>
-typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
</programlisting>
@@ -1309,9 +1333,19 @@ typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
The <function>stream_prepare_cb</function> callback is called to prepare
a previously streamed transaction as part of a two-phase commit. This
callback is required when the output plugin supports both the streaming
- of large in-progress transactions and two-phase commits.
+ of large in-progress transactions and two-phase commits. If the output
+ plugin has output the streamed transaction, the callback is expected to
+ return true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view. Please
+ note that only the return value of this callback suffices to determine
+ whether a prepared transaction was output or not; callbacks
+ <function>commit_prepared_cb</function> and
+ <function>rollback_prepared_cb</function> do not need to return this
+ status again.
<programlisting>
-typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
</programlisting>
@@ -1322,9 +1356,14 @@ typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx
<title>Stream Commit Callback</title>
<para>
The required <function>stream_commit_cb</function> callback is called to
- commit a previously streamed transaction.
+ commit a previously streamed transaction. If the output plugin
+ has output the streamed transaction, the callback is expected to return
+ true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
<programlisting>
-typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
</programlisting>
@@ -1337,10 +1376,15 @@ typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
The required <function>stream_change_cb</function> callback is called
when sending a change in a block of streamed changes (demarcated by
<function>stream_start_cb</function> and <function>stream_stop_cb</function> calls).
+ If the output plugin decoded and output the change, it is expected to
+ return true. Otherwise it is expected to return false. This return value
+ is used to update the <structfield>filtered_bytes</structfield> counter
+ reported in <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
The actual changes are not displayed as the transaction can abort at a later
point in time and we don't decode changes for aborted transactions.
<programlisting>
-typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -1377,18 +1421,18 @@ typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx
(demarcated by <function>stream_start_cb</function> and
<function>stream_stop_cb</function> calls).
<programlisting>
-typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
ReorderBufferChange *change);
</programlisting>
- The parameters are analogous to the <function>stream_change_cb</function>
- callback. However, because <command>TRUNCATE</command> actions on
- tables connected by foreign keys need to be executed together, this
- callback receives an array of relations instead of just a single one.
- See the description of the <xref linkend="sql-truncate"/> statement for
- details.
+ The parameters and the return value are analogous to the
+ <function>stream_change_cb</function> callback. However, because
+ <command>TRUNCATE</command> actions on tables connected by foreign keys
+ need to be executed together, this callback receives an array of relations
+ instead of just a single one. See the description of the <xref
+ linkend="sql-truncate"/> statement for details.
</para>
</sect3>
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 70c217b2c1a..6adcaf1edf6 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1547,6 +1547,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1657,6 +1668,31 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_wal_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_wal_txns</structfield>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>sent_bytes</structfield><type>bigint</type>
@@ -1704,6 +1740,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</tgroup>
</table>
+ <note>
+ <para>
+ The accuracy of columns <structfield>filtered_bytes</structfield>, and
+ <structfield>sent_txns</structfield> depends upon the accuracy of return values
+ from respective callbacks associated with those counts as mentioned in <xref
+ linkend="logicaldecoding-output-plugin-callbacks"/>. A descripancy in those
+ counts may be result of incorrect implementation of those callbacks in the
+ output plugin given by column <structfield>plugin</structfield>.
+ </para>
+ </note>
+
</sect2>
<sect2 id="monitoring-pg-stat-wal-receiver-view">
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 763231265a7..6e6695ca20c 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1068,6 +1068,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1077,6 +1078,8 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_wal_txns,
s.total_wal_bytes,
+ s.filtered_bytes,
+ s.sent_txns,
s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3288bb43aed..a7746439536 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -879,7 +879,8 @@ commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = true;
/* do the actual work: call callback */
- ctx->callbacks.commit_cb(ctx, txn, commit_lsn);
+ if (ctx->callbacks.commit_cb(ctx, txn, commit_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -975,7 +976,8 @@ prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
"prepare_cb")));
/* do the actual work: call callback */
- ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1106,7 +1108,8 @@ change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1148,7 +1151,8 @@ truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1387,7 +1391,8 @@ stream_abort_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_abort_cb")));
- ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn);
+ if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1432,7 +1437,8 @@ stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming at prepare time requires a %s callback",
"stream_prepare_cb")));
- ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1473,7 +1479,8 @@ stream_commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_commit_cb")));
- ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn);
+ if (ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1522,7 +1529,8 @@ stream_change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_change_cb")));
- ctx->callbacks.stream_change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.stream_change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1610,7 +1618,8 @@ stream_truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1950,7 +1959,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1961,6 +1970,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount,
rb->totalTxns,
rb->totalBytes,
+ rb->filteredBytes,
+ rb->sentTxns,
rb->sentBytes);
repSlotStat.spill_txns = rb->spillTxns;
@@ -1972,6 +1983,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_wal_txns = rb->totalTxns;
repSlotStat.total_wal_bytes = rb->totalBytes;
+ repSlotStat.filtered_bytes = rb->filteredBytes;
+ repSlotStat.sent_txns = rb->sentTxns;
repSlotStat.sent_bytes = rb->sentBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1985,6 +1998,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->filteredBytes = 0;
+ rb->sentTxns = 0;
rb->sentBytes = 0;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 2ee980aa859..b7f2e6b8825 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -310,7 +310,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -393,7 +392,9 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentTxns = 0;
buffer->sentBytes = 0;
+ buffer->filteredBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
@@ -4456,7 +4457,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index e016f64e0b3..c4408095456 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -46,12 +46,12 @@ static void pgoutput_startup(LogicalDecodingContext *ctx,
static void pgoutput_shutdown(LogicalDecodingContext *ctx);
static void pgoutput_begin_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_commit_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_commit_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
-static void pgoutput_change(LogicalDecodingContext *ctx,
+static bool pgoutput_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, Relation relation,
ReorderBufferChange *change);
-static void pgoutput_truncate(LogicalDecodingContext *ctx,
+static bool pgoutput_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, int nrelations, Relation relations[],
ReorderBufferChange *change);
static void pgoutput_message(LogicalDecodingContext *ctx,
@@ -62,7 +62,7 @@ static bool pgoutput_origin_filter(LogicalDecodingContext *ctx,
ReplOriginId origin_id);
static void pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_prepare_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr prepare_lsn);
static void pgoutput_commit_prepared_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
@@ -74,13 +74,13 @@ static void pgoutput_stream_start(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
static void pgoutput_stream_stop(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
+static bool pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
-static void pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
+static bool pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
-static void pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr prepare_lsn);
static bool publications_valid;
@@ -628,7 +628,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
/*
* COMMIT callback
*/
-static void
+static bool
pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
{
@@ -649,12 +649,13 @@ pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!sent_begin_txn)
{
elog(DEBUG1, "skipped replication of an empty transaction with XID: %u", txn->xid);
- return;
+ return false;
}
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_commit(ctx->out, txn, commit_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -677,7 +678,7 @@ pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
/*
* PREPARE callback
*/
-static void
+static bool
pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
{
@@ -686,6 +687,7 @@ pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_prepare(ctx->out, txn, prepare_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -1480,7 +1482,7 @@ pgoutput_row_filter(Relation relation, TupleTableSlot *old_slot,
*
* This is called both in streaming and non-streaming modes.
*/
-static void
+static bool
pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
Relation relation, ReorderBufferChange *change)
{
@@ -1494,9 +1496,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
ReorderBufferChangeType action = change->action;
TupleTableSlot *old_slot = NULL;
TupleTableSlot *new_slot = NULL;
+ bool result;
if (!is_publishable_relation(relation))
- return;
+ return false;
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1514,15 +1517,15 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
- return;
+ return false;
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
- return;
+ return false;
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
- return;
+ return false;
/*
* This is only possible if deletes are allowed even when replica
@@ -1532,7 +1535,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
- return;
+ return false;
}
break;
default:
@@ -1587,7 +1590,16 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ result = false;
goto cleanup;
+ }
+
+ /*
+ * Even if we filter some columns while sending the message we are not
+ * filtering the change as a whole. Hence we will return true.
+ */
+ result = true;
/*
* Send BEGIN if we haven't yet.
@@ -1650,9 +1662,10 @@ cleanup:
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
+ return result;
}
-static void
+static bool
pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[], ReorderBufferChange *change)
{
@@ -1664,6 +1677,7 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelids;
Oid *relids;
TransactionId xid = InvalidTransactionId;
+ bool result = false;
/* Remember the xid for the change in streaming mode. See pgoutput_change. */
if (data->in_streaming)
@@ -1714,10 +1728,18 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.cascade,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
+
+ /*
+ * Even if we filtered out some relations, we still send a TRUNCATE
+ * message for the remaining relations. Since the change, as a whole,
+ * is not filtered out we return true.
+ */
+ result = true;
}
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
+ return result;
}
static void
@@ -1889,7 +1911,7 @@ pgoutput_stream_stop(struct LogicalDecodingContext *ctx,
* Notify downstream to discard the streamed transaction (along with all
* its subtransactions, if it's a toplevel transaction).
*/
-static void
+static bool
pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn)
@@ -1916,13 +1938,14 @@ pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
cleanup_rel_sync_cache(toptxn->xid, false);
+ return true;
}
/*
* Notify downstream to apply the streamed transaction (along with all
* its subtransactions).
*/
-static void
+static bool
pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
@@ -1943,6 +1966,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
cleanup_rel_sync_cache(txn->xid, true);
+ return true;
}
/*
@@ -1950,7 +1974,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
*
* Notify the downstream to prepare the transaction.
*/
-static void
+static bool
pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
@@ -1961,6 +1985,7 @@ pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_stream_prepare(ctx->out, txn, prepare_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index de174d8ec2e..e86fea17f71 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,8 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_wal_txns);
REPLSLOT_ACC(total_wal_bytes);
+ REPLSLOT_ACC(filtered_bytes);
+ REPLSLOT_ACC(sent_txns);
REPLSLOT_ACC(sent_bytes);
#undef REPLSLOT_ACC
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 496170b3d5b..c7db02cd5f9 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2129,7 +2129,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 16
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2160,13 +2160,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_wal_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "sent_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "filtered_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "sent_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 15, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 16, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -2192,18 +2196,20 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_wal_txns);
values[9] = Int64GetDatum(slotent->total_wal_bytes);
- values[10] = Int64GetDatum(slotent->sent_bytes);
- values[11] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->filtered_bytes);
+ values[11] = Int64GetDatum(slotent->sent_txns);
+ values[12] = Int64GetDatum(slotent->sent_bytes);
+ values[13] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[12] = true;
+ nulls[14] = true;
else
- values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[14] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[13] = true;
+ nulls[15] = true;
else
- values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[15] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index f323500c95d..c999e5daf51 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5700,9 +5700,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_wal_txns,total_wal_bytes,filtered_bytes,sent_txns,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 954839ebd16..28e504fcc88 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -400,6 +400,8 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_wal_txns;
PgStat_Counter total_wal_bytes;
+ PgStat_Counter filtered_bytes;
+ PgStat_Counter sent_txns;
PgStat_Counter sent_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 842fcde67f9..622e806145d 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -56,17 +56,19 @@ typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
/*
- * Callback for every individual change in a successful transaction.
+ * Callback for every individual change in a successful transaction. Should
+ * return true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
/*
- * Callback for every TRUNCATE in a successful transaction.
+ * Callback for every TRUNCATE in a successful transaction. Should return true if
+ * the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
@@ -74,8 +76,9 @@ typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
/*
* Called for every (explicit or implicit) COMMIT of a successful transaction.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
@@ -118,10 +121,10 @@ typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
/*
- * Called for PREPARE record unless it was filtered by filter_prepare()
- * callback.
+ * Called for PREPARE record unless it was filtered by filter_prepare() callback.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
@@ -159,32 +162,35 @@ typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
/*
* Called to discard changes streamed to remote node from in-progress
- * transaction.
+ * transaction. Should return true if the transaction is output, false
+ * otherwise.
*/
-typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
/*
* Called to prepare changes streamed to remote node from in-progress
- * transaction. This is called as part of a two-phase commit.
+ * transaction. This is called as part of a two-phase commit. Should return true
+ * if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
/*
- * Called to apply changes streamed to remote node from in-progress
- * transaction.
+ * Called to apply changes streamed to remote node from in-progress transaction.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
/*
* Callback for streaming individual changes from in-progress transactions.
+ * Should return true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -202,9 +208,10 @@ typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx
const char *message);
/*
- * Callback for streaming truncates from in-progress transactions.
+ * Callback for streaming truncates from in-progress transactions. Should return
+ * true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index d3a6c7cd85b..982af1ce2ae 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,10 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 filteredBytes; /* amount of data filtered out by output
+ * plugin */
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
int64 sentBytes; /* amount of data decoded and sent downstream */
};
@@ -719,6 +723,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index fc77720c535..fb5813cdb54 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2162,6 +2162,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2171,12 +2172,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_wal_txns,
s.total_wal_bytes,
+ s.filtered_bytes,
+ s.sent_txns,
s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_wal_txns, total_wal_bytes, filtered_bytes, sent_txns, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index d7e62e4d488..e3fb189d8e3 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that filtered_bytes increased due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 945505d0239..9d58db467b1 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index c666ae00483..f15373f55bb 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the filtered_bytes reflects that. We can not test the exact value of
+# filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
--
2.34.1
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-02-10 13:38 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Bertrand Drouvot @ 2026-02-10 13:38 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
Hi,
On Mon, Feb 02, 2026 at 02:06:07PM +0530, Ashutosh Bapat wrote:
> On Tue, Jan 27, 2026 at 11:08 PM Andres Freund <andres@anarazel.de> wrote:
> >
> > Hi,
> >
> > On 2025-12-11 10:29:42 +0530, Ashutosh Bapat wrote:
> > > Please review.
> >
> > I'd simplify the patch to, initially, to just track the sent bytes. For one,
> > that's by *far* the most useful statistic. But I also have some concerns
> > about the other stats:
> >
>
> Ok. I have split the patch into two
Thanks!
> 0001 to track sent_bytes
> 0002 to track filtered_bytes and sent_txns
>
> I think we all agree that sent_bytes is useful, so I suggest that we
> review and commit 0001.
I had a look at 0001 and it looks ok to me. That's an extract of the previous
patches that we already iterated over up-thread.
I just have a few more comments:
1/ commit message
s/This statistics/This statistic/
2/ LogicalOutputWrite
+ /* Update the amount of data sent downstream. */
I think we can remove the period to be consistent with most of the one line
comments around.
3/ WalSndWriteData
Same as 2/., remove the period for the same comment.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2026-02-10 15:40 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-02-10 15:40 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Tue, Feb 10, 2026 at 7:08 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Mon, Feb 02, 2026 at 02:06:07PM +0530, Ashutosh Bapat wrote:
> > On Tue, Jan 27, 2026 at 11:08 PM Andres Freund <andres@anarazel.de> wrote:
> > >
> > > Hi,
> > >
> > > On 2025-12-11 10:29:42 +0530, Ashutosh Bapat wrote:
> > > > Please review.
> > >
> > > I'd simplify the patch to, initially, to just track the sent bytes. For one,
> > > that's by *far* the most useful statistic. But I also have some concerns
> > > about the other stats:
> > >
> >
> > Ok. I have split the patch into two
>
> Thanks!
>
> > 0001 to track sent_bytes
> > 0002 to track filtered_bytes and sent_txns
> >
> > I think we all agree that sent_bytes is useful, so I suggest that we
> > review and commit 0001.
>
> I had a look at 0001 and it looks ok to me. That's an extract of the previous
> patches that we already iterated over up-thread.
Thanks.
>
> I just have a few more comments:
>
> 1/ commit message
>
> s/This statistics/This statistic/
>
It might be better to just use the phrase "This number ..." since the
earlier sentence mentions it as "number". I have made that change in
my repository. Will send it with the next version of patchset.
> 2/ LogicalOutputWrite
>
> + /* Update the amount of data sent downstream. */
>
> I think we can remove the period to be consistent with most of the one line
> comments around.
I see a few variations, starting with lower case, without a period at
the end etc. Don't see a standard per say. Let's defer for the
committer to decide.
>
> 3/ WalSndWriteData
>
> Same as 2/., remove the period for the same comment.
>
Same here. I see the following comment which has a period at the end.
/* Try taking fast path unless we get too close to walsender timeout. */
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-02-13 05:17 ` Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Michael Paquier @ 2026-02-13 05:17 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Tue, Feb 10, 2026 at 09:10:45PM +0530, Ashutosh Bapat wrote:
> It might be better to just use the phrase "This number ..." since the
> earlier sentence mentions it as "number". I have made that change in
> my repository. Will send it with the next version of patchset.
I have studied this thread, and can get behind the idea of adding the
number of bytes sent to the output plugin at this level.
However, I think that patch 0001 should be split into two parts,
because it is doing two separate things, not one:
- One patch for the rename of the existing fields total_txns and
total_bytes to respectively total_wal_txns and total_wal_bytes, so as
it becomes possible to make the distinction between the stats data
coming from WAL. (The suggested rename was a bit confusing for me
first, FWIW, when I read total_wal_bytes, my mind understood that as a
total number of WAL generated, even if I get that that it comes from
an amount of WAL data processed when decoding transactions. Not an
objection, just a feeling).
- A second patch to introduce the new field for the number of bytes
sent to the output plugin.
I am also questioning why you did not make the choice of renaming
totalBytes and totalTxns in ReorderBuffer. On consistency ground, at
least, that seems relevant to me as these two numbers are the source
data fed to pgstats.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-02-13 12:58 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-02-13 12:58 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; pgsql-hackers
On Fri, Feb 13, 2026 at 10:47 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Tue, Feb 10, 2026 at 09:10:45PM +0530, Ashutosh Bapat wrote:
> > It might be better to just use the phrase "This number ..." since the
> > earlier sentence mentions it as "number". I have made that change in
> > my repository. Will send it with the next version of patchset.
>
> I have studied this thread, and can get behind the idea of adding the
> number of bytes sent to the output plugin at this level.
>
> However, I think that patch 0001 should be split into two parts,
> because it is doing two separate things, not one:
> - One patch for the rename of the existing fields total_txns and
> total_bytes to respectively total_wal_txns and total_wal_bytes, so as
> it becomes possible to make the distinction between the stats data
> coming from WAL. (The suggested rename was a bit confusing for me
> first, FWIW, when I read total_wal_bytes, my mind understood that as a
> total number of WAL generated, even if I get that that it comes from
> an amount of WAL data processed when decoding transactions. Not an
> objection, just a feeling).
> - A second patch to introduce the new field for the number of bytes
> sent to the output plugin.
>
I am open to other suggestions. Since the bytes in total_bytes and
sent_bytes refer to different set of bytes, it was thought to be
better to rename total_bytes and hence total_txns. But then
stream_bytes, spill_bytes too come from WAL and they are not renamed
right now. So there's already some awkwardness. I also see that wal in
the name can be confusing. I thought of using "reordered" instead of
"wal" but reorder buffer is an internal concept. If we change the
reorder buffer mechanism tomorrow, we will need to change the name of
the field. So we discarded that. I am wondering whether we should just
leave the name as is and rely on documentation to clarify the
difference. What do you think?
Although renaming is a separate change, it's closely related with the
new field. Committing that separately won't be any value addition. As
is, the fields in the view are quite clear from their names. So it's
not clear why we need separate patch for it. If you insist, I will
create a separate patch.
> I am also questioning why you did not make the choice of renaming
> totalBytes and totalTxns in ReorderBuffer. On consistency ground, at
> least, that seems relevant to me as these two numbers are the source
> data fed to pgstats.
No particular reason. In the code it's quite clear what totalBytes
means, so I didn't feel like renaming. But I think it's better to be
consistent and rename the internal variables as well, if we decide to
rename those fields.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-03-12 12:43 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-03-12 12:43 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
Hi Michael,
On Fri, Feb 13, 2026 at 6:28 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Fri, Feb 13, 2026 at 10:47 AM Michael Paquier <michael@paquier.xyz> wrote:
> >
> > On Tue, Feb 10, 2026 at 09:10:45PM +0530, Ashutosh Bapat wrote:
> > > It might be better to just use the phrase "This number ..." since the
> > > earlier sentence mentions it as "number". I have made that change in
> > > my repository. Will send it with the next version of patchset.
> >
> > I have studied this thread, and can get behind the idea of adding the
> > number of bytes sent to the output plugin at this level.
> >
> > However, I think that patch 0001 should be split into two parts,
> > because it is doing two separate things, not one:
> > - One patch for the rename of the existing fields total_txns and
> > total_bytes to respectively total_wal_txns and total_wal_bytes, so as
> > it becomes possible to make the distinction between the stats data
> > coming from WAL. (The suggested rename was a bit confusing for me
> > first, FWIW, when I read total_wal_bytes, my mind understood that as a
> > total number of WAL generated, even if I get that that it comes from
> > an amount of WAL data processed when decoding transactions. Not an
> > objection, just a feeling).
> > - A second patch to introduce the new field for the number of bytes
> > sent to the output plugin.
> >
>
> I am open to other suggestions. Since the bytes in total_bytes and
> sent_bytes refer to different set of bytes, it was thought to be
> better to rename total_bytes and hence total_txns. But then
> stream_bytes, spill_bytes too come from WAL and they are not renamed
> right now. So there's already some awkwardness. I also see that wal in
> the name can be confusing. I thought of using "reordered" instead of
> "wal" but reorder buffer is an internal concept. If we change the
> reorder buffer mechanism tomorrow, we will need to change the name of
> the field. So we discarded that. I am wondering whether we should just
> leave the name as is and rely on documentation to clarify the
> difference. What do you think?
>
Could you please share your thoughts on this? Your inputs would help
us determine the next steps - whether we should proceed with renaming,
and if so, what names you would suggest, or whether we should leave
things as they are.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-03-13 02:09 ` Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-14 10:01 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Michael Paquier @ 2026-03-13 02:09 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Thu, Mar 12, 2026 at 06:13:33PM +0530, Ashutosh Sharma wrote:
> Could you please share your thoughts on this? Your inputs would help
> us determine the next steps - whether we should proceed with renaming,
> and if so, what names you would suggest, or whether we should leave
> things as they are.
FWIW, I still find the use of _wal_ in these fields rather confusing,
and they add more inconsistencies with the internal structures of
reorderbuffer.c. The goal is to add a field to track the number of
bytes sent downstream. Hence, I would suggest to give up on the
rename, add the new field, perhaps consider improving the docs for the
existing fields to tell to which context these numbers refer to, then
call it a day.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-13 05:09 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
1 sibling, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-03-13 05:09 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Fri, Mar 13, 2026 at 7:39 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Thu, Mar 12, 2026 at 06:13:33PM +0530, Ashutosh Sharma wrote:
> > Could you please share your thoughts on this? Your inputs would help
> > us determine the next steps - whether we should proceed with renaming,
> > and if so, what names you would suggest, or whether we should leave
> > things as they are.
>
> FWIW, I still find the use of _wal_ in these fields rather confusing,
> and they add more inconsistencies with the internal structures of
> reorderbuffer.c. The goal is to add a field to track the number of
> bytes sent downstream. Hence, I would suggest to give up on the
> rename, add the new field, perhaps consider improving the docs for the
> existing fields to tell to which context these numbers refer to, then
> call it a day.
Thanks for sharing your thoughts, Michael, I had a similar idea in
mind. I'll go ahead and implement these changes and come up with the
new patches. Now since this is purely additive (new columns only), I'm
thinking a single patch might suffice, Or maybe, we could split it
into two: one that corrects the existing documentation and another
that introduces the new fields for displaying downstream bytes sent
and some other information related to this.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-03-15 22:16 ` Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Michael Paquier @ 2026-03-15 22:16 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Fri, Mar 13, 2026 at 10:39:40AM +0530, Ashutosh Sharma wrote:
> Thanks for sharing your thoughts, Michael, I had a similar idea in
> mind. I'll go ahead and implement these changes and come up with the
> new patches. Now since this is purely additive (new columns only), I'm
> thinking a single patch might suffice, Or maybe, we could split it
> into two: one that corrects the existing documentation and another
> that introduces the new fields for displaying downstream bytes sent
> and some other information related to this.
Thanks. We'd better move forward quickly with this one based on the
current calendar, still it would be good to hear from Ashutosh Bapat
and double-check with him.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-16 03:25 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-03-16 03:25 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 3:47 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Fri, Mar 13, 2026 at 10:39:40AM +0530, Ashutosh Sharma wrote:
> > Thanks for sharing your thoughts, Michael, I had a similar idea in
> > mind. I'll go ahead and implement these changes and come up with the
> > new patches. Now since this is purely additive (new columns only), I'm
> > thinking a single patch might suffice, Or maybe, we could split it
> > into two: one that corrects the existing documentation and another
> > that introduces the new fields for displaying downstream bytes sent
> > and some other information related to this.
>
> Thanks. We'd better move forward quickly with this one based on the
> current calendar, still it would be good to hear from Ashutosh Bapat
> and double-check with him.
I got busy with SQL/PGQ [1], resizable shared structures [2] and
pgconf.india last week. Thanks Ashutosh Sharma for picking this up.
Addition of _wal_ was suggested by Andres offlist [3]. That was long
back and didn't have other opinions to validate the renaming. I see
that there are more opinions against renaming now. There is also merit
in not renaming it on the grounds that the users are used to the old
names and will find new names confusing. Whether we do it now or
later, it's going to break backward compatibility. Not renaming now
has the advantage that we can avoid it all together if users do not
find the names confusing in the context of the new column. Let's leave
the renaming aside for now.
I would post two patches
1. To introduce the new column sent_bytes + clarify total_bytes in the
context of sent_bytes. We should consider this patch for committing.
2. Addition of filtered_bytes + sent_txns and also the clarification
of total_bytes and total_txns in the context of the new columns. We
will decide whether to commit the patch after 0001 is committed.
[1] https://www.postgresql.org/message-id/CAExHW5ufB8y1oguSea_9WPFHFDOOTsxZ3Na_OAUBF-H%2BB7AfYw%40mail.g...
[2] https://www.postgresql.org/message-id/flat/CAExHW5vM1bneLYfg0wGeAa%3D52UiJ3z4vKd3AJ72X8Fw6k3KKrg%40m...
[3] https://www.postgresql.org/message-id/CAExHW5vnRPp5dof35DEGdc8W2tS16E5CbmGey28Y=RJ9QrpfAQ@mail.gmail...
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-03-16 06:50 ` Michael Paquier <michael@paquier.xyz>
2026-03-16 07:03 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Michael Paquier @ 2026-03-16 06:50 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 08:55:17AM +0530, Ashutosh Bapat wrote:
> I would post two patches
> 1. To introduce the new column sent_bytes + clarify total_bytes in the
> context of sent_bytes. We should consider this patch for committing.
Sounds to me like two patches: one for the new column, a second for
the docs of the existing columns. Could somebody send these patches?
I would be OK to look at them once posted, driving things for this CF.
> 2. Addition of filtered_bytes + sent_txns and also the clarification
> of total_bytes and total_txns in the context of the new columns. We
> will decide whether to commit the patch after 0001 is committed.
Not sure about this one, neither do I know if I would be able to look
at any proposal for this release cycle on this part. Getting 0001 out
of its box seems like a goal good enough for me, TBH.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-16 07:03 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2026-03-16 07:03 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 12:20 PM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Mon, Mar 16, 2026 at 08:55:17AM +0530, Ashutosh Bapat wrote:
> > I would post two patches
> > 1. To introduce the new column sent_bytes + clarify total_bytes in the
> > context of sent_bytes. We should consider this patch for committing.
>
> Sounds to me like two patches: one for the new column, a second for
> the docs of the existing columns. Could somebody send these patches?
> I would be OK to look at them once posted, driving things for this CF.
>
The way I look at it, we don't need to modify documentation of
existing columns. The documentation of the new column should describe
it in the context of the existing columns. Let's wait for Ashutosh
Sharma to share the patches. If we think we need to modify
documentation of the existing columns, we will split it into two as
you suggest.
> > 2. Addition of filtered_bytes + sent_txns and also the clarification
> > of total_bytes and total_txns in the context of the new columns. We
> > will decide whether to commit the patch after 0001 is committed.
>
> Not sure about this one, neither do I know if I would be able to look
> at any proposal for this release cycle on this part. Getting 0001 out
> of its box seems like a goal good enough for me, TBH.
+1. I am fine if we ignore the other patch for now, but let it be
there on this thread for completeness/future consideration/reference.
I am completely fine if we ignore it forever :).
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-16 07:50 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
1 sibling, 2 replies; 123+ messages in thread
From: Ashutosh Sharma @ 2026-03-16 07:50 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
Hi,
On Mon, Mar 16, 2026 at 12:20 PM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Mon, Mar 16, 2026 at 08:55:17AM +0530, Ashutosh Bapat wrote:
> > I would post two patches
> > 1. To introduce the new column sent_bytes + clarify total_bytes in the
> > context of sent_bytes. We should consider this patch for committing.
>
> Sounds to me like two patches: one for the new column, a second for
> the docs of the existing columns. Could somebody send these patches?
> I would be OK to look at them once posted, driving things for this CF.
>
PFA patches:
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.
2) v20260316-0002-Report-output-plugin-statistics-in-pg_stat_replicati.patch:
This patch adds a couple of more metrics to report the amount of
changes filtered out by the output plugin, as well as the total number
of transactions sent downstream.
--
With Regards,
Ashutosh Sharma.
Attachments: download all (2 files, .tar.gz)
v20260316-0002-Report-output-plugin-statistics-in-pg_stat_replicati.patch (application/octet-stream, 73.1K) download
From 4ee9983ab409220cd0d34cd6ba74fff6fdc2b267 Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Fri, 13 Mar 2026 13:37:06 +0000
Subject: [PATCH 2/2] Report output plugin statistics in
pg_stat_replication_slots
As of now pg_stat_replication_slots reports statistics about the reorder
buffer, but it does not report output statistics like the amount of data
filtered by the output plugin, or the number of transactions sent
downstream. This statistics is useful when investigating issues related
to a slow downstream.
This commit adds following fields to pg_stat_replication_slots
- filtered_bytes is the amount of changes filtered out by the
output plugin
- sent_txns is the amount of transactions sent downstream by the
output plugin
Filtered bytes are reported next to total_bytes to keep these two
closely related fields together.
Though these counts are stored and maintained by the core, they require
the output plugin to return correct values to the relevant callbacks.
This has been added as note in the documentation. In order to aid
debugging descripancies in these counter, name of the output plugin is
added to the view for an easy reference.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 ++++++++-------
contrib/test_decoding/sql/stats.sql | 15 ++-
contrib/test_decoding/t/001_repl_stats.pl | 15 ++-
contrib/test_decoding/test_decoding.c | 55 ++++++-----
doc/src/sgml/logicaldecoding.sgml | 96 ++++++++++++++-----
doc/src/sgml/monitoring.sgml | 47 +++++++++
src/backend/catalog/system_views.sql | 3 +
src/backend/replication/logical/logical.c | 35 +++++--
.../replication/logical/reorderbuffer.c | 5 +-
src/backend/replication/pgoutput/pgoutput.c | 65 +++++++++----
src/backend/utils/activity/pgstat_replslot.c | 2 +
src/backend/utils/adt/pgstatfuncs.c | 28 +++---
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 2 +
src/include/replication/output_plugin.h | 43 +++++----
src/include/replication/reorderbuffer.h | 5 +
src/test/regress/expected/rules.out | 5 +-
src/test/subscription/t/001_rep_changes.pl | 11 +++
src/test/subscription/t/010_truncate.pl | 20 ++++
src/test/subscription/t/028_row_filter.pl | 11 +++
20 files changed, 386 insertions(+), 160 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index 2dd45460317..250733a8337 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,17 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+------------+--------------------
- regression_slot_stats1 | t | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t | t
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Usually we
+-- expect filtered_bytes to be 0 since the entire transaction executed by this
+-- test is replicated. But there may be some background transactions, changes
+-- from which are filtered out by the output plugin, so we check for >= 0 here.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | sent_txns | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+-----------+----------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | 1 | t | t
+ regression_slot_stats2 | t | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | t | 1 | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +58,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+------------+--------------------
- regression_slot_stats1 | t | t | f | f | f | t
- regression_slot_stats2 | t | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | sent_txns | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+-----------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | 0 | t | t
+ regression_slot_stats2 | t | t | t | t | t | 1 | t | t
+ regression_slot_stats3 | t | t | t | t | t | 1 | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +73,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+------------+--------------------
- regression_slot_stats1 | t | t | f | f | 0 | t
- regression_slot_stats2 | t | t | f | f | 0 | t
- regression_slot_stats3 | t | t | f | f | 0 | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | sent_txns | filtered_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+-----------+----------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | 0 | t | t
+ regression_slot_stats2 | t | t | f | f | 0 | 0 | t | t
+ regression_slot_stats3 | t | t | f | f | 0 | 0 | t | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | filtered_bytes | sent_txns | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+----------------+-----------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | filtered_bytes | sent_txns | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+----------------+-----------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
@@ -121,20 +126,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
-SELECT slot_name FROM pg_stat_replication_slots;
- slot_name
-------------------------
- regression_slot_stats1
- regression_slot_stats2
- regression_slot_stats3
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+ slot_name | plugin
+------------------------+---------------
+ regression_slot_stats1 | test_decoding
+ regression_slot_stats2 | test_decoding
+ regression_slot_stats3 | test_decoding
(3 rows)
COMMIT;
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 9f85455bce1..4c4eb0c39a5 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -16,16 +16,21 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+-- total_txns may vary based on the background activity but sent_txns should
+-- always be 1 since the background transactions are always skipped. Usually we
+-- expect filtered_bytes to be 0 since the entire transaction executed by this
+-- test is replicated. But there may be some background transactions, changes
+-- from which are filtered out by the output plugin, so we check for >= 0 here.
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, sent_txns, filtered_bytes >= 0 AS filtered_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
@@ -47,8 +52,8 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
BEGIN;
-SELECT slot_name FROM pg_stat_replication_slots;
-SELECT slot_name FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
+SELECT slot_name, plugin FROM pg_stat_replication_slots;
COMMIT;
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 88899824bae..e88fec4ab04 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -23,10 +23,15 @@ sub test_slot_stats
my ($node, $expected, $msg) = @_;
+ # If there are background transactions which are filtered out by the output
+ # plugin, filtered_bytes may be greater than 0. But it's not guaranteed that
+ # such transactions would be present.
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
total_bytes > 0 AS total_bytes,
+ filtered_bytes >= 0 AS filtered_bytes,
+ sent_txns > 0 AS sent_txn,
sent_bytes > 0 AS sent_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
@@ -81,9 +86,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t|t
-regression_slot2|t|t|t
-regression_slot3|t|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t
+regression_slot3|t|t|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -105,8 +110,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t|t
-regression_slot2|t|t|t),
+ qq(regression_slot1|t|t|t|t|t
+regression_slot2|t|t|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index d5cf0fa02b0..c1271a01e0d 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -60,12 +60,12 @@ static void pg_output_begin(LogicalDecodingContext *ctx,
TestDecodingData *data,
ReorderBufferTXN *txn,
bool last_write);
-static void pg_decode_commit_txn(LogicalDecodingContext *ctx,
+static bool pg_decode_commit_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
-static void pg_decode_change(LogicalDecodingContext *ctx,
+static bool pg_decode_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, Relation relation,
ReorderBufferChange *change);
-static void pg_decode_truncate(LogicalDecodingContext *ctx,
+static bool pg_decode_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change);
@@ -80,7 +80,7 @@ static bool pg_decode_filter_prepare(LogicalDecodingContext *ctx,
const char *gid);
static void pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pg_decode_prepare_txn(LogicalDecodingContext *ctx,
+static bool pg_decode_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
static void pg_decode_commit_prepared_txn(LogicalDecodingContext *ctx,
@@ -98,16 +98,16 @@ static void pg_output_stream_start(LogicalDecodingContext *ctx,
bool last_write);
static void pg_decode_stream_stop(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pg_decode_stream_abort(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_abort(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
-static void pg_decode_stream_prepare(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_prepare(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
-static void pg_decode_stream_commit(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_commit(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
-static void pg_decode_stream_change(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -115,7 +115,7 @@ static void pg_decode_stream_message(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr lsn,
bool transactional, const char *prefix,
Size sz, const char *message);
-static void pg_decode_stream_truncate(LogicalDecodingContext *ctx,
+static bool pg_decode_stream_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change);
@@ -318,7 +318,7 @@ pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBuff
}
/* COMMIT callback */
-static void
+static bool
pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
{
@@ -330,7 +330,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
txn->output_plugin_private = NULL;
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
if (data->include_xids)
@@ -343,6 +343,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/* BEGIN PREPARE callback */
@@ -367,7 +368,7 @@ pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
}
/* PREPARE callback */
-static void
+static bool
pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
{
@@ -379,7 +380,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* where the first operation is received for this transaction.
*/
if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -394,6 +395,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/* COMMIT PREPARED callback */
@@ -599,7 +601,7 @@ tuple_to_stringinfo(StringInfo s, TupleDesc tupdesc, HeapTuple tuple, bool skip_
/*
* callback for individual changed tuples
*/
-static void
+static bool
pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
Relation relation, ReorderBufferChange *change)
{
@@ -684,9 +686,10 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
MemoryContextReset(data->context);
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[], ReorderBufferChange *change)
{
@@ -739,6 +742,7 @@ pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
MemoryContextReset(data->context);
OutputPluginWrite(ctx, true);
+ return true;
}
static void
@@ -818,7 +822,7 @@ pg_decode_stream_stop(LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
}
-static void
+static bool
pg_decode_stream_abort(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn)
@@ -842,7 +846,7 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
}
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
if (data->include_xids)
@@ -850,9 +854,10 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
else
appendStringInfoString(ctx->out, "aborting streamed (sub)transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_stream_prepare(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
@@ -861,7 +866,7 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
TestDecodingTxnData *txndata = txn->output_plugin_private;
if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -877,9 +882,10 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true);
+ return true;
}
-static void
+static bool
pg_decode_stream_commit(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
@@ -892,7 +898,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
txn->output_plugin_private = NULL;
if (data->skip_empty_xacts && !xact_wrote_changes)
- return;
+ return false;
OutputPluginPrepareWrite(ctx, true);
@@ -906,6 +912,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -913,7 +920,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
* at a later point in time. We don't want users to see the changes until the
* transaction is committed.
*/
-static void
+static bool
pg_decode_stream_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
@@ -935,6 +942,7 @@ pg_decode_stream_change(LogicalDecodingContext *ctx,
else
appendStringInfoString(ctx->out, "streaming change for transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -981,7 +989,7 @@ pg_decode_stream_message(LogicalDecodingContext *ctx,
* In streaming mode, we don't display the detailed information of Truncate.
* See pg_decode_stream_change.
*/
-static void
+static bool
pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[],
ReorderBufferChange *change)
@@ -1001,4 +1009,5 @@ pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
else
appendStringInfoString(ctx->out, "streaming truncate for transaction");
OutputPluginWrite(ctx, true);
+ return true;
}
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index 6dc49108997..dc37545681c 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -1020,10 +1020,15 @@ typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
rows will have been called before this, if there have been any modified
rows.
<programlisting>
-typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
</programlisting>
+ If the callback outputs the transaction, it is expected to return true;
+ otherwise false. The return value is used to update the
+ <literal>sent_txns</literal> counter reported in <link
+ linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
</para>
</sect3>
@@ -1044,7 +1049,7 @@ typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
this very same transaction. In that case, the logical decoding of this
aborted transaction is stopped gracefully.
<programlisting>
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -1054,8 +1059,12 @@ typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
and <function>commit_cb</function> callbacks, but additionally the
relation descriptor <parameter>relation</parameter> points to the
relation the row belongs to and a struct
- <parameter>change</parameter> describing the row modification are passed
- in.
+ <parameter>change</parameter> describing the row modification are passed in.
+ If the output plugin decoded and output the change, it is expected
+ to return true; otherwise false. This return value is used to update the
+ <structfield>filtered_bytes</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
</para>
<note>
@@ -1075,18 +1084,18 @@ typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
The optional <function>truncate_cb</function> callback is called for a
<command>TRUNCATE</command> command.
<programlisting>
-typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
ReorderBufferChange *change);
</programlisting>
- The parameters are analogous to the <function>change_cb</function>
- callback. However, because <command>TRUNCATE</command> actions on
- tables connected by foreign keys need to be executed together, this
- callback receives an array of relations instead of just a single one.
- See the description of the <xref linkend="sql-truncate"/> statement for
- details.
+ The parameters and the expected return value are analogous to the
+ <function>change_cb</function> callback. However, because
+ <command>TRUNCATE</command> actions on tables connected by foreign keys
+ need to be executed together, this callback receives an array of relations
+ instead of just a single one. See the description of the <xref
+ linkend="sql-truncate"/> statement for details.
</para>
</sect3>
@@ -1219,8 +1228,18 @@ typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
rows will have been called before this, if there have been any modified
rows. The <parameter>gid</parameter> field, which is part of the
<parameter>txn</parameter> parameter, can be used in this callback.
+ If the callback outputs the prepared transaction, it is expected to return
+ true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view. Please
+ note that the return value of this callback suffices to determine
+ whether a prepared transaction was output or not; callbacks
+ <function>commit_prepared_cb</function> and
+ <function>rollback_prepared_cb</function> do not need to return this
+ status again.
<programlisting>
-typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
</programlisting>
@@ -1294,9 +1313,14 @@ typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
<title>Stream Abort Callback</title>
<para>
The required <function>stream_abort_cb</function> callback is called to
- abort a previously streamed transaction.
+ abort a previously streamed transaction. If the output plugin has output
+ the streamed transaction, the callback is expected to return true;
+ otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
<programlisting>
-typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
</programlisting>
@@ -1309,9 +1333,19 @@ typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
The <function>stream_prepare_cb</function> callback is called to prepare
a previously streamed transaction as part of a two-phase commit. This
callback is required when the output plugin supports both the streaming
- of large in-progress transactions and two-phase commits.
+ of large in-progress transactions and two-phase commits. If the output
+ plugin has output the streamed transaction, the callback is expected to
+ return true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view. Please
+ note that only the return value of this callback suffices to determine
+ whether a prepared transaction was output or not; callbacks
+ <function>commit_prepared_cb</function> and
+ <function>rollback_prepared_cb</function> do not need to return this
+ status again.
<programlisting>
-typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
</programlisting>
@@ -1322,9 +1356,14 @@ typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx
<title>Stream Commit Callback</title>
<para>
The required <function>stream_commit_cb</function> callback is called to
- commit a previously streamed transaction.
+ commit a previously streamed transaction. If the output plugin
+ has output the streamed transaction, the callback is expected to return
+ true; otherwise false. The return value is used to update the
+ <structfield>sent_txns</structfield> counter reported in
+ <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
<programlisting>
-typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
</programlisting>
@@ -1337,10 +1376,15 @@ typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
The required <function>stream_change_cb</function> callback is called
when sending a change in a block of streamed changes (demarcated by
<function>stream_start_cb</function> and <function>stream_stop_cb</function> calls).
+ If the output plugin decoded and output the change, it is expected to
+ return true. Otherwise it is expected to return false. This return value
+ is used to update the <structfield>filtered_bytes</structfield> counter
+ reported in <link linkend="monitoring-pg-stat-replication-slots-view">
+ <structname>pg_stat_replication_slots</structname></link> view.
The actual changes are not displayed as the transaction can abort at a later
point in time and we don't decode changes for aborted transactions.
<programlisting>
-typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -1377,18 +1421,18 @@ typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx
(demarcated by <function>stream_start_cb</function> and
<function>stream_stop_cb</function> calls).
<programlisting>
-typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
ReorderBufferChange *change);
</programlisting>
- The parameters are analogous to the <function>stream_change_cb</function>
- callback. However, because <command>TRUNCATE</command> actions on
- tables connected by foreign keys need to be executed together, this
- callback receives an array of relations instead of just a single one.
- See the description of the <xref linkend="sql-truncate"/> statement for
- details.
+ The parameters and the return value are analogous to the
+ <function>stream_change_cb</function> callback. However, because
+ <command>TRUNCATE</command> actions on tables connected by foreign keys
+ need to be executed together, this callback receives an array of relations
+ instead of just a single one. See the description of the <xref
+ linkend="sql-truncate"/> statement for details.
</para>
</sect3>
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index addf99e06e9..2c52d55fdf7 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1563,6 +1563,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>plugin</structfield> <type>text</type>
+ </para>
+ <para>
+ The base name of the shared object containing the output plugin this
+ logical slot is using. This column is same as the one in
+ <structname>pg_replication_slots</structname>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>spill_txns</structfield> <type>bigint</type>
@@ -1673,6 +1684,31 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>filtered_bytes</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Amount of changes, from <structfield>total_bytes</structfield>, filtered
+ out by the output plugin and not sent downstream. Please note that it
+ does not include the changes filtered before a change is sent to
+ the output plugin, e.g. the changes filtered by origin.
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>sent_txns</structfield> <type>bigint</type>
+ </para>
+ <para>
+ Number of decoded transactions sent downstream for this slot. This
+ counts top-level transactions only, and is not incremented for
+ subtransactions. These transactions are subset of transactions sent to
+ the decoding plugin. Hence this count is expected to be less than or
+ equal to <structfield>total_txns</structfield>.
+ </para></entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>sent_bytes</structfield><type>bigint</type>
@@ -1726,6 +1762,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</tgroup>
</table>
+ <note>
+ <para>
+ The accuracy of columns <structfield>filtered_bytes</structfield>, and
+ <structfield>sent_txns</structfield> depends upon the accuracy of return values
+ from respective callbacks associated with those counts as mentioned in <xref
+ linkend="logicaldecoding-output-plugin-callbacks"/>. A descripancy in those
+ counts may be result of incorrect implementation of those callbacks in the
+ output plugin given by column <structfield>plugin</structfield>.
+ </para>
+ </note>
+
</sect2>
<sect2 id="monitoring-pg-stat-wal-receiver-view">
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 6e8e6147761..da6a2e3d058 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1096,6 +1096,7 @@ CREATE VIEW pg_replication_slots AS
CREATE VIEW pg_stat_replication_slots AS
SELECT
s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -1105,6 +1106,8 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.filtered_bytes,
+ s.sent_txns,
s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 73338959851..c07653a53ab 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -879,7 +879,8 @@ commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = true;
/* do the actual work: call callback */
- ctx->callbacks.commit_cb(ctx, txn, commit_lsn);
+ if (ctx->callbacks.commit_cb(ctx, txn, commit_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -975,7 +976,8 @@ prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
"prepare_cb")));
/* do the actual work: call callback */
- ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1106,7 +1108,8 @@ change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1148,7 +1151,8 @@ truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1387,7 +1391,8 @@ stream_abort_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_abort_cb")));
- ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn);
+ if (ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1432,7 +1437,8 @@ stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming at prepare time requires a %s callback",
"stream_prepare_cb")));
- ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn);
+ if (ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1473,7 +1479,8 @@ stream_commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_commit_cb")));
- ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn);
+ if (ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn))
+ cache->sentTxns++;
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1522,7 +1529,8 @@ stream_change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
errmsg("logical streaming requires a %s callback",
"stream_change_cb")));
- ctx->callbacks.stream_change_cb(ctx, txn, relation, change);
+ if (!ctx->callbacks.stream_change_cb(ctx, txn, relation, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1610,7 +1618,8 @@ stream_truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
ctx->end_xact = false;
- ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change);
+ if (!ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change))
+ cache->filteredBytes += ReorderBufferChangeSize(change);
/* Pop the error context stack */
error_context_stack = errcallback.previous;
@@ -1950,7 +1959,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1961,6 +1970,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount,
rb->totalTxns,
rb->totalBytes,
+ rb->filteredBytes,
+ rb->sentTxns,
rb->sentBytes);
repSlotStat.spill_txns = rb->spillTxns;
@@ -1972,6 +1983,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.filtered_bytes = rb->filteredBytes;
+ repSlotStat.sent_txns = rb->sentTxns;
repSlotStat.sent_bytes = rb->sentBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1985,6 +1998,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->filteredBytes = 0;
+ rb->sentTxns = 0;
rb->sentBytes = 0;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 33df98541b3..d53227216d3 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -311,7 +311,6 @@ static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *t
* memory accounting
* ---------------------------------------
*/
-static Size ReorderBufferChangeSize(ReorderBufferChange *change);
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
ReorderBufferChange *change,
ReorderBufferTXN *txn,
@@ -394,7 +393,9 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentTxns = 0;
buffer->sentBytes = 0;
+ buffer->filteredBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
@@ -4454,7 +4455,7 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/*
* Size of a change in memory.
*/
-static Size
+Size
ReorderBufferChangeSize(ReorderBufferChange *change)
{
Size sz = sizeof(ReorderBufferChange);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 4ecfcbff7ab..1897a5697a8 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -46,12 +46,12 @@ static void pgoutput_startup(LogicalDecodingContext *ctx,
static void pgoutput_shutdown(LogicalDecodingContext *ctx);
static void pgoutput_begin_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_commit_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_commit_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
-static void pgoutput_change(LogicalDecodingContext *ctx,
+static bool pgoutput_change(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, Relation relation,
ReorderBufferChange *change);
-static void pgoutput_truncate(LogicalDecodingContext *ctx,
+static bool pgoutput_truncate(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, int nrelations, Relation relations[],
ReorderBufferChange *change);
static void pgoutput_message(LogicalDecodingContext *ctx,
@@ -62,7 +62,7 @@ static bool pgoutput_origin_filter(LogicalDecodingContext *ctx,
ReplOriginId origin_id);
static void pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_prepare_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr prepare_lsn);
static void pgoutput_commit_prepared_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr commit_lsn);
@@ -74,13 +74,13 @@ static void pgoutput_stream_start(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
static void pgoutput_stream_stop(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
-static void pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
+static bool pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
-static void pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
+static bool pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
-static void pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
+static bool pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn, XLogRecPtr prepare_lsn);
static bool publications_valid;
@@ -628,7 +628,7 @@ pgoutput_send_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
/*
* COMMIT callback
*/
-static void
+static bool
pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
{
@@ -649,12 +649,13 @@ pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!sent_begin_txn)
{
elog(DEBUG1, "skipped replication of an empty transaction with XID: %u", txn->xid);
- return;
+ return false;
}
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_commit(ctx->out, txn, commit_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -677,7 +678,7 @@ pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
/*
* PREPARE callback
*/
-static void
+static bool
pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
{
@@ -686,6 +687,7 @@ pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_prepare(ctx->out, txn, prepare_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
@@ -1480,7 +1482,7 @@ pgoutput_row_filter(Relation relation, TupleTableSlot *old_slot,
*
* This is called both in streaming and non-streaming modes.
*/
-static void
+static bool
pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
Relation relation, ReorderBufferChange *change)
{
@@ -1494,9 +1496,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
ReorderBufferChangeType action = change->action;
TupleTableSlot *old_slot = NULL;
TupleTableSlot *new_slot = NULL;
+ bool result;
if (!is_publishable_relation(relation))
- return;
+ return false;
/*
* Remember the xid for the change in streaming mode. We need to send xid
@@ -1514,15 +1517,15 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
{
case REORDER_BUFFER_CHANGE_INSERT:
if (!relentry->pubactions.pubinsert)
- return;
+ return false;
break;
case REORDER_BUFFER_CHANGE_UPDATE:
if (!relentry->pubactions.pubupdate)
- return;
+ return false;
break;
case REORDER_BUFFER_CHANGE_DELETE:
if (!relentry->pubactions.pubdelete)
- return;
+ return false;
/*
* This is only possible if deletes are allowed even when replica
@@ -1532,7 +1535,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (!change->data.tp.oldtuple)
{
elog(DEBUG1, "didn't send DELETE change because of missing oldtuple");
- return;
+ return false;
}
break;
default:
@@ -1587,7 +1590,16 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
* of the row filter for old and new tuple.
*/
if (!pgoutput_row_filter(targetrel, old_slot, &new_slot, relentry, &action))
+ {
+ result = false;
goto cleanup;
+ }
+
+ /*
+ * Even if we filter some columns while sending the message we are not
+ * filtering the change as a whole. Hence we will return true.
+ */
+ result = true;
/*
* Send BEGIN if we haven't yet.
@@ -1650,9 +1662,10 @@ cleanup:
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
+ return result;
}
-static void
+static bool
pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelations, Relation relations[], ReorderBufferChange *change)
{
@@ -1664,6 +1677,7 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
int nrelids;
Oid *relids;
TransactionId xid = InvalidTransactionId;
+ bool result = false;
/* Remember the xid for the change in streaming mode. See pgoutput_change. */
if (data->in_streaming)
@@ -1714,10 +1728,18 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
change->data.truncate.cascade,
change->data.truncate.restart_seqs);
OutputPluginWrite(ctx, true);
+
+ /*
+ * Even if we filtered out some relations, we still send a TRUNCATE
+ * message for the remaining relations. Since the change, as a whole,
+ * is not filtered out we return true.
+ */
+ result = true;
}
MemoryContextSwitchTo(old);
MemoryContextReset(data->context);
+ return result;
}
static void
@@ -1890,7 +1912,7 @@ pgoutput_stream_stop(struct LogicalDecodingContext *ctx,
* Notify downstream to discard the streamed transaction (along with all
* its subtransactions, if it's a toplevel transaction).
*/
-static void
+static bool
pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn)
@@ -1917,13 +1939,14 @@ pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
cleanup_rel_sync_cache(toptxn->xid, false);
+ return true;
}
/*
* Notify downstream to apply the streamed transaction (along with all
* its subtransactions).
*/
-static void
+static bool
pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn)
@@ -1944,6 +1967,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
OutputPluginWrite(ctx, true);
cleanup_rel_sync_cache(txn->xid, true);
+ return true;
}
/*
@@ -1951,7 +1975,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx,
*
* Notify the downstream to prepare the transaction.
*/
-static void
+static bool
pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn)
@@ -1962,6 +1986,7 @@ pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx,
OutputPluginPrepareWrite(ctx, true);
logicalrep_write_stream_prepare(ctx->out, txn, prepare_lsn);
OutputPluginWrite(ctx, true);
+ return true;
}
/*
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index e324e1d20bd..8d0ad730ff3 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,8 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(filtered_bytes);
+ REPLSLOT_ACC(sent_txns);
REPLSLOT_ACC(sent_bytes);
#undef REPLSLOT_ACC
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 4b6b31ae002..4c61a00d6c7 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2145,7 +2145,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 16
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2176,13 +2176,17 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "sent_bytes",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "filtered_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "sent_txns",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "sent_bytes",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 15, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 16, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2209,18 +2213,20 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->sent_bytes);
- values[11] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->filtered_bytes);
+ values[11] = Int64GetDatum(slotent->sent_txns);
+ values[12] = Int64GetDatum(slotent->sent_bytes);
+ values[13] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[12] = true;
+ nulls[14] = true;
else
- values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[14] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[13] = true;
+ nulls[15] = true;
else
- values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[15] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 1e94aa2825e..e6fd972e33f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5711,9 +5711,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,filtered_bytes,sent_txns,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index ca0bb599a1a..d25646378b3 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -403,6 +403,8 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter filtered_bytes;
+ PgStat_Counter sent_txns;
PgStat_Counter sent_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 842fcde67f9..622e806145d 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -56,17 +56,19 @@ typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
/*
- * Callback for every individual change in a successful transaction.
+ * Callback for every individual change in a successful transaction. Should
+ * return true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
/*
- * Callback for every TRUNCATE in a successful transaction.
+ * Callback for every TRUNCATE in a successful transaction. Should return true if
+ * the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
@@ -74,8 +76,9 @@ typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
/*
* Called for every (explicit or implicit) COMMIT of a successful transaction.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
@@ -118,10 +121,10 @@ typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn);
/*
- * Called for PREPARE record unless it was filtered by filter_prepare()
- * callback.
+ * Called for PREPARE record unless it was filtered by filter_prepare() callback.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
@@ -159,32 +162,35 @@ typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
/*
* Called to discard changes streamed to remote node from in-progress
- * transaction.
+ * transaction. Should return true if the transaction is output, false
+ * otherwise.
*/
-typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr abort_lsn);
/*
* Called to prepare changes streamed to remote node from in-progress
- * transaction. This is called as part of a two-phase commit.
+ * transaction. This is called as part of a two-phase commit. Should return true
+ * if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr prepare_lsn);
/*
- * Called to apply changes streamed to remote node from in-progress
- * transaction.
+ * Called to apply changes streamed to remote node from in-progress transaction.
+ * Should return true if the transaction is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
XLogRecPtr commit_lsn);
/*
* Callback for streaming individual changes from in-progress transactions.
+ * Should return true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
Relation relation,
ReorderBufferChange *change);
@@ -202,9 +208,10 @@ typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx
const char *message);
/*
- * Callback for streaming truncates from in-progress transactions.
+ * Callback for streaming truncates from in-progress transactions. Should return
+ * true if the change is output, false otherwise.
*/
-typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
+typedef bool (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
ReorderBufferTXN *txn,
int nrelations,
Relation relations[],
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index d3a6c7cd85b..982af1ce2ae 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,10 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 filteredBytes; /* amount of data filtered out by output
+ * plugin */
+ int64 sentTxns; /* number of transactions decoded and sent
+ * downstream */
int64 sentBytes; /* amount of data decoded and sent downstream */
};
@@ -719,6 +723,7 @@ extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
XLogRecPtr lsn, ReorderBufferChange *change,
bool toast_insert);
+extern Size ReorderBufferChangeSize(ReorderBufferChange *change);
extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
Snapshot snap, XLogRecPtr lsn,
bool transactional, const char *prefix,
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 7b84a6d79ad..7bb85d10517 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2192,6 +2192,7 @@ pg_stat_replication| SELECT s.pid,
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name,
+ r.plugin,
s.spill_txns,
s.spill_count,
s.spill_bytes,
@@ -2201,12 +2202,14 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.filtered_bytes,
+ s.sent_txns,
s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, filtered_bytes, sent_txns, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index 7d41715ed81..9ef44b7fe3c 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -124,6 +124,9 @@ $result =
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins");
is($result, qq(1002), 'check initial data was copied to subscriber');
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_ins SELECT generate_series(1,50)");
$node_publisher->safe_psql('postgres', "DELETE FROM tab_ins WHERE a > 20");
@@ -157,6 +160,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup('tap_sub');
+# Verify that filtered_bytes increased due to filtered update and delete
+# operations on tab_ins. We cannot test the exact value since it may include
+# changes from other concurrent transactions.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after DML filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins");
is($result, qq(1052|1|1002), 'check replicated inserts on subscriber');
diff --git a/src/test/subscription/t/010_truncate.pl b/src/test/subscription/t/010_truncate.pl
index 945505d0239..9d58db467b1 100644
--- a/src/test/subscription/t/010_truncate.pl
+++ b/src/test/subscription/t/010_truncate.pl
@@ -69,6 +69,9 @@ $node_subscriber->safe_psql('postgres',
# Wait for initial sync of all subscriptions
$node_subscriber->wait_for_subscription_sync;
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+
# insert data to truncate
$node_subscriber->safe_psql('postgres',
@@ -98,6 +101,16 @@ $node_publisher->wait_for_catchup('sub1');
$result = $node_subscriber->safe_psql('postgres', "SELECT nextval('seq1')");
is($result, qq(101), 'truncate restarted identities');
+# All the DMLs above happen on tables that are subscribed to by sub1 and not
+# sub2. filtered_bytes should get incremented for replication slot
+# corresponding to the subscription sub2. We can not test the exact value of
+# filtered_bytes because the counter is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after publication level filtering');
+$initial_filtered_bytes = $final_filtered_bytes;
+
# test publication that does not replicate truncate
$node_subscriber->safe_psql('postgres',
@@ -107,6 +120,13 @@ $node_publisher->safe_psql('postgres', "TRUNCATE tab2");
$node_publisher->wait_for_catchup('sub2');
+# Truncate changes are filtered out at publication level itself. Make sure that
+# the filtered_bytes is incremented.
+$final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'sub2'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after truncate filtering');
+
$result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab2");
is($result, qq(3|1|3), 'truncate not replicated');
diff --git a/src/test/subscription/t/028_row_filter.pl b/src/test/subscription/t/028_row_filter.pl
index c666ae00483..f15373f55bb 100644
--- a/src/test/subscription/t/028_row_filter.pl
+++ b/src/test/subscription/t/028_row_filter.pl
@@ -579,6 +579,9 @@ is($result, qq(3|6),
# commands are for testing normal logical replication behavior.
#
# test row filter (INSERT, UPDATE, DELETE)
+my $initial_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+
$node_publisher->safe_psql('postgres',
"INSERT INTO tab_rowfilter_1 (a, b) VALUES (800, 'test 800')");
$node_publisher->safe_psql('postgres',
@@ -612,6 +615,14 @@ $node_publisher->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname);
+# The changes which do not pass the row filter will be filtered. Make sure that
+# the filtered_bytes reflects that. We can not test the exact value of
+# filtered_bytes since it is affected by background activity.
+my $final_filtered_bytes = $node_publisher->safe_psql('postgres',
+ "SELECT filtered_bytes FROM pg_stat_replication_slots WHERE slot_name = 'tap_sub'");
+cmp_ok($final_filtered_bytes, '>', $initial_filtered_bytes,
+ 'filtered_bytes increased after row filtering');
+
# Check expected replicated rows for tab_rowfilter_2
# tap_pub_1 filter is: (c % 2 = 0)
# tap_pub_2 filter is: (c % 3 = 0)
--
2.43.0
v20260316-0001-Report-downstream-sent-bytes-in-pg_stat_replication_.patch (application/octet-stream, 26.4K) download
From 1305433d20466eddfeacdc218bdae4fe084dadbe Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Mon, 16 Mar 2026 06:48:35 +0000
Subject: [PATCH 1/2] Report downstream sent bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes sent to downstream consumers.
Add sent_bytes to expose that metric and help diagnose replication
throughput issues caused by a slow or stalled downstream consumer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 +++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 13 ++---
doc/src/sgml/monitoring.sgml | 17 +++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 7 ++-
.../replication/logical/logicalfuncs.c | 8 ++++
.../replication/logical/reorderbuffer.c | 1 +
src/backend/replication/walsender.c | 3 ++
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 ++++----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 1 +
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 3 +-
16 files changed, 96 insertions(+), 54 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..2dd45460317 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..9f85455bce1 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..88899824bae 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ sent_bytes > 0 AS sent_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 9c5c6dc490f..addf99e06e9 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1673,6 +1673,23 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <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. After applying filters,
+ the amount of data that gets converted is less than
+ <structfield>total_bytes</structfield>. But the format of data before
+ and after the conversion is different. Hence the value of
+ <structfield>sent_bytes</structfield> is not directly related to the
+ value of <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 90d48bc9c80..6e8e6147761 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1105,6 +1105,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 603a2b94d05..73338959851 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1950,7 +1950,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1960,7 +1960,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->sentBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1971,6 +1972,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.sent_bytes = rb->sentBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1983,6 +1985,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->sentBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 9760818941d..b8a9209c300 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 sentBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ sentBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ sentBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,8 +90,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ sentBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += sentBytes;
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 682d13c9f22..33df98541b3 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -394,6 +394,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 376ff46340d..0c015406023 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1599,6 +1599,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 168ef8f8f45..e324e1d20bd 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(sent_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index bad5642d9c9..4b6b31ae002 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2145,7 +2145,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2176,11 +2176,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "sent_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2207,17 +2209,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->sent_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 361e2cfffeb..1e94aa2825e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5711,9 +5711,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 216b93492ba..ca0bb599a1a 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -403,6 +403,7 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter sent_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 2d717a9e152..d3a6c7cd85b 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..5354322e196 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, sent_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and sent_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 71d7262049e..7b84a6d79ad 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2201,11 +2201,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-03-16 11:10 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 11:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 13:48 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 2 replies; 123+ messages in thread
From: Amit Kapila @ 2026-03-16 11:10 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 1:21 PM Ashutosh Sharma <ashu.coek88@gmail.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.
* We also send keep_alive kind of messages via wal_sender, those are
not counted in sent_bytes. If we don't want to include those then does
that need a mention?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-03-16 11:54 ` Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Amit Kapila @ 2026-03-16 11:54 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 4:40 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Mar 16, 2026 at 1:21 PM Ashutosh Sharma <ashu.coek88@gmail.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.
>
> * We also send keep_alive kind of messages via wal_sender, those are
> not counted in sent_bytes.
>
I think the other one to consider in the same category is the
PqMsg_CopyDone message.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-03-16 13:48 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-17 04:45 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-03-16 13:48 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
Hi,
On Mon, Mar 16, 2026 at 4:40 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Mar 16, 2026 at 1:21 PM Ashutosh Sharma <ashu.coek88@gmail.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.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 13:48 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-03-17 04:45 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 06:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2026-03-17 04:45 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 7:18 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> On Mon, Mar 16, 2026 at 4:40 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Mon, Mar 16, 2026 at 1:21 PM Ashutosh Sharma <ashu.coek88@gmail.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.
>
I think that is probably a bug. I see that ReorderBufferQueueMessage()
queues messages for transactional messages and which would then
probably be sent later along with commit, so its data will be counted
by UpdateDecodingStats. But the question is shouldn't we consider the
data for non-transactional messages as well?
>
> Please correct me in case my understanding was wrong and I should have
> checked for something else to verify this.
>
It doesn't seem to be related to this patch, so we can fix that
separately if we agree that it is a bug.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 13:48 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-17 04:45 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-03-17 06:02 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-17 06:42 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-03-17 06:02 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Michael Paquier <michael@paquier.xyz>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Tue, Mar 17, 2026 at 10:15 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > Observation: I do not see UpdateDecodingStats() being triggered for
> > this non-transactional message.
> >
>
> I think that is probably a bug. I see that ReorderBufferQueueMessage()
> queues messages for transactional messages and which would then
> probably be sent later along with commit, so its data will be counted
> by UpdateDecodingStats. But the question is shouldn't we consider the
> data for non-transactional messages as well?
>
I am also replying to your earlier comment
> BTW, this also contains changes from pgoutput_message() which could be
> non-transactional. So, saying transaction changes may not be
> appropriate.
>
We should consider the non-transactional messages as well in
sent_bytes, since that amount of data is sent. Whether we can use the
term "transaction changes" in the description of sent_bytes if we
include non-transactional messages is questionable. I used
"transactional changes" in the description of "sent_bytes" to be
consistent with the description of total_bytes. Looks like you are
suggesting that not accounting for non-transaction messages in
total_bytes is a bug, if we fix that, are we going to fix the
description of "total_bytes"? If yes, it makes sense to mention
non-transactional messages separately in sent_bytes description. We
can modify my previous suggestion as
Amount of transaction changes and non-transactional messages sent
downstream in the output plugin
format for this slot. The output plugin may filter the changes it
receives. Hence the amount of data that it converts to the output
plugin format is less than the <structfield>total_bytes</structfield>.
But the format of data before and after the conversion is different.
Hence the value of <structfield>sent_bytes</structfield> is not
directly related to the value of
<structfield>total_bytes</structfield>.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 13:48 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-17 04:45 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 06:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-03-17 06:42 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 08:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2026-03-17 06:42 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Michael Paquier <michael@paquier.xyz>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Tue, Mar 17, 2026 at 11:32 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Tue, Mar 17, 2026 at 10:15 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > > Observation: I do not see UpdateDecodingStats() being triggered for
> > > this non-transactional message.
> > >
> >
> > I think that is probably a bug. I see that ReorderBufferQueueMessage()
> > queues messages for transactional messages and which would then
> > probably be sent later along with commit, so its data will be counted
> > by UpdateDecodingStats. But the question is shouldn't we consider the
> > data for non-transactional messages as well?
> >
>
> I am also replying to your earlier comment
>
> > BTW, this also contains changes from pgoutput_message() which could be
> > non-transactional. So, saying transaction changes may not be
> > appropriate.
> >
>
> We should consider the non-transactional messages as well in
> sent_bytes, since that amount of data is sent. Whether we can use the
> term "transaction changes" in the description of sent_bytes if we
> include non-transactional messages is questionable. I used
> "transactional changes" in the description of "sent_bytes" to be
> consistent with the description of total_bytes. Looks like you are
> suggesting that not accounting for non-transaction messages in
> total_bytes is a bug, if we fix that, are we going to fix the
> description of "total_bytes"?
>
Yes, we should do that.
> If yes, it makes sense to mention
> non-transactional messages separately in sent_bytes description. We
> can modify my previous suggestion as
>
> Amount of transaction changes and non-transactional messages sent
> downstream in the output plugin
>
Isn't it better to use something on the lines of what Michael is
proposing in his last email [1]?
[1] - https://www.postgresql.org/message-id/abiQe4fxR2fp317F%40paquier.xyz
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 13:48 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-17 04:45 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 06:02 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-17 06:42 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-03-17 08:40 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2026-03-17 08:40 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Michael Paquier <michael@paquier.xyz>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Tue, Mar 17, 2026 at 12:12 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> > If yes, it makes sense to mention
> > non-transactional messages separately in sent_bytes description. We
> > can modify my previous suggestion as
> >
> > Amount of transaction changes and non-transactional messages sent
> > downstream in the output plugin
> >
>
> Isn't it better to use something on the lines of what Michael is
> proposing in his last email [1]?
I missed his version in criss-cross emails. Copied here for completeness:
"Amount of bytes decoded and sent downstream by the output
plugin. This accounts for the output plugin filters, if any, and for
the conversion into the output plugin format."
Everywhere else, total_bytes, spill_bytes, we use the term "data"
instead of "bytes". The "decoded" in the description of those two
fields has a different meaning than what "decoded" means here. It's
going to be confusing if we use the same term. I think we need to be
consistent with other descriptions. But I agree with Michael's intent
to make it less fancy. Following version covers it all
Amount of transaction changes and non-transactional messages sent
downstream in the output plugin
format for this slot. The output plugin may filter the changes it
receives. Hence the amount of data that it converts to the output
plugin format is less than the <structfield>total_bytes</structfield>.
But the format of data before and after the conversion is different.
Hence the value of <structfield>sent_bytes</structfield> is not
directly related to the value of
<structfield>total_bytes</structfield>.
It tells what exactly is counted. It's less fancy (though a bit
verbose). Once we add non-transactional messages part to total_bytes,
both the descriptions will be consistent. It also explains why
sent_bytes and total_bytes can not be compared. Since streamed_bytes
and spilled_bytes never contain non-transactional messages, we don't
need to modify those descriptions. What do you think?
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-03-16 23:21 ` Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Michael Paquier @ 2026-03-16 23:21 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; Amit Kapila <amit.kapila16@gmail.com>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Mon, Mar 16, 2026 at 01:20:57PM +0530, Ashutosh Sharma 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.
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 "
%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
" %" PRId64 " %" PRId64 " %" PRId64,
This was already unreadable before the patch, and it makes the
situation worse. Could it be possible to append the names of each
field here?
+ qq(Check that reset timestamp is later after the second reset of
stats for slot '$stats_test_slot1' and confirm total_bytes and
sent_bytes were set to 0.)
Not your fault here as well, but I would replace that by a comment at
the top of the test. Still your patch makes things harder to read.
+ 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.
Do we need to be that fancy here? The concept relates to the number
of bytes sent downstream. Here is a suggestion:
"Amount of bytes decoded and sent downstream by the output
plugin. This accounts for the output plugin filters, if any, and for
the conversion into the output plugin format."
Perhaps we had better document at the top of LogicalOutputWrite() that
"sentBytes" ought to be updated for all the fields we are sending part
of the tuplestore?
Why are you not counting the "now" timestamp in WalSndWriteData()?
This is appended to the stream of data with a separate pq_send*()
call. Perhaps the reason why this is not appended is worth a comment?
The trick with this patch is to make sure that all the relevant places
where data is sent downstream are correctly incremented. As far as I
can see, things seem to be covered, but I cannot help but wonder if we
are missing one or more places. @Amit, do you feel a hole somewhere?
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-17 05:02 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2026-03-17 05:02 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Tue, Mar 17, 2026 at 4:51 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> The trick with this patch is to make sure that all the relevant places
> where data is sent downstream are correctly incremented.
>
Right.
> As far as I
> can see, things seem to be covered, but I cannot help but wonder if we
> are missing one or more places. @Amit, do you feel a hole somewhere?
>
Yesterday, I raised a point related to this which is whether we want
to count messages like keep_alive, copy_done, or
PqReplMsg_PrimaryStatusUpdate? These don't contain the user decoded
data from WAL but some additional information between
publisher-subscriber required to ensure data is being applied.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-03-17 05:25 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-03-17 05:25 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Ashutosh Sharma <ashu.coek88@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Tue, Mar 17, 2026 at 10:32 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Mar 17, 2026 at 4:51 AM Michael Paquier <michael@paquier.xyz> wrote:
> >
> > The trick with this patch is to make sure that all the relevant places
> > where data is sent downstream are correctly incremented.
> >
>
> Right.
>
> > As far as I
> > can see, things seem to be covered, but I cannot help but wonder if we
> > are missing one or more places. @Amit, do you feel a hole somewhere?
> >
>
> Yesterday, I raised a point related to this which is whether we want
> to count messages like keep_alive, copy_done, or
> PqReplMsg_PrimaryStatusUpdate? These don't contain the user decoded
> data from WAL but some additional information between
> publisher-subscriber required to ensure data is being applied.
I think sent_bytes should count the logically decoded data - the data
that the output plugin produces in logical form. This is the amount of
data that the downstream has to process for data replication. So, the
protocol related data shouldn't be counted here, IMO. Compare this
with the total_bytes which does not account for the memory used by the
reorder buffer metadata itself - it just accounts for the size of the
changes. If we describe the sent_bytes as below, we are explicitly
mentioning what sent_bytes is. So anything which is not data in the
output format is excluded including the protocol data. If you think we
need to clarify that we are excluding protocol data, we can add a
line. But that may confuse readers who are unaware of the protocol
data.
Amount of transaction changes sent downstream in the output plugin
format for this slot. The output plugin may filter the changes it
receives. Hence the amount of data that it converts to the output
plugin format is less than the <structfield>total_bytes</structfield>.
But the format of data before and after the conversion is different.
Hence the value of <structfield>sent_bytes</structfield> is not
directly related to the value of
<structfield>total_bytes</structfield>.
The phrase "transaction changes" is being debated in a separate
sub-thread, I will reply there.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-03-18 02:38 ` Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Michael Paquier @ 2026-03-18 02:38 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Tue, Mar 17, 2026 at 10:55:51AM +0530, Ashutosh Bapat wrote:
> On Tue, Mar 17, 2026 at 10:32 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>> Yesterday, I raised a point related to this which is whether we want
>> to count messages like keep_alive, copy_done, or
>> PqReplMsg_PrimaryStatusUpdate? These don't contain the user decoded
>> data from WAL but some additional information between
>> publisher-subscriber required to ensure data is being applied.
>
> I think sent_bytes should count the logically decoded data - the data
> that the output plugin produces in logical form. This is the amount of
> data that the downstream has to process for data replication. So, the
> protocol related data shouldn't be counted here, IMO. Compare this
> with the total_bytes which does not account for the memory used by the
> reorder buffer metadata itself - it just accounts for the size of the
> changes. If we describe the sent_bytes as below, we are explicitly
> mentioning what sent_bytes is. So anything which is not data in the
> output format is excluded including the protocol data. If you think we
> need to clarify that we are excluding protocol data, we can add a
> line. But that may confuse readers who are unaware of the protocol
> data.
As we aim to count how many bytes are sent over the wire, including
the amount of bytes related to the messages sent as part of the
protocol exchanged, sounds like an important property that we should
have in the implementation because these bytes are required for the
exchanges to work. If an output plugin decodes few changes and has a
lot of messages (unlikely in most cases, still imagine it's the case),
sent_bytes could be misleading if we only include the transactional
changes, couldn't it?
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-18 04:28 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-03-18 04:28 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
Hi,
On Wed, Mar 18, 2026 at 8:08 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Tue, Mar 17, 2026 at 10:55:51AM +0530, Ashutosh Bapat wrote:
> > On Tue, Mar 17, 2026 at 10:32 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >> Yesterday, I raised a point related to this which is whether we want
> >> to count messages like keep_alive, copy_done, or
> >> PqReplMsg_PrimaryStatusUpdate? These don't contain the user decoded
> >> data from WAL but some additional information between
> >> publisher-subscriber required to ensure data is being applied.
> >
> > I think sent_bytes should count the logically decoded data - the data
> > that the output plugin produces in logical form. This is the amount of
> > data that the downstream has to process for data replication. So, the
> > protocol related data shouldn't be counted here, IMO. Compare this
> > with the total_bytes which does not account for the memory used by the
> > reorder buffer metadata itself - it just accounts for the size of the
> > changes. If we describe the sent_bytes as below, we are explicitly
> > mentioning what sent_bytes is. So anything which is not data in the
> > output format is excluded including the protocol data. If you think we
> > need to clarify that we are excluding protocol data, we can add a
> > line. But that may confuse readers who are unaware of the protocol
> > data.
>
> As we aim to count how many bytes are sent over the wire, including
> the amount of bytes related to the messages sent as part of the
> protocol exchanged, sounds like an important property that we should
> have in the implementation because these bytes are required for the
> exchanges to work. If an output plugin decodes few changes and has a
> lot of messages (unlikely in most cases, still imagine it's the case),
> sent_bytes could be misleading if we only include the transactional
> changes, couldn't it?
Here is my understanding and perspective:
1) For transactional changes, logical decoding accumulates the changes
and then sends them downstream either at commit time or while
streaming an in-progress transaction. The sent bytes are accounted for
when the formatted output is actually written by the decoding output
write path, and the slot stats are then reported through the normal
decoding stats update path.
2) For non-transactional logical messages, the behavior is different
in that they are not queued as reorder buffer changes. They are
processed immediately when read from WAL. However, they still go
through logical decoding and can still produce output that is written
downstream, so their sent bytes should be accounted for as well.
For non-transactional messages, we are currently (with the patch)
updating the sent bytes but not reporting it.
3) Messages such as keepalives are sent on the replication connection,
but they are not logical decoding output. Since no logical decoding
payload is being produced there, they should not be included in
sent_bytes.
So the right boundary for sent_bytes is according to me would be:
a) include logical decoding payload sent downstream (or via SQL
decoding path), whether it came from transactional changes or
non-transactional logical messages
b) exclude auxiliary replication protocol traffic such as keepalives
If this makes sense then the revised documentation shared by Ashutosh
Bapat in his last email looks good to me, which is:
Amount of transaction changes and non-transactional messages sent
downstream in the output plugin
format for this slot. The output plugin may filter the changes it
receives. Hence the amount of data that it converts to the output
plugin format is less than the <structfield>total_bytes</structfield>.
But the format of data before and after the conversion is different.
Hence the value of <structfield>sent_bytes</structfield> is not
directly related to the value of
<structfield>total_bytes</structfield>.
If you all agree with this, I will first prepare a patch to fix the
missing part in #2 which is about reporting stats for
non-transactional messages that goes via logical decoding process and
then on top of that share the ongoing 0001 patch with above doc
change.
Let me know your thoughts. thanks
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-03-25 06:55 ` Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Michael Paquier @ 2026-03-25 06:55 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Wed, Mar 18, 2026 at 09:58:58AM +0530, Ashutosh Sharma wrote:
> So the right boundary for sent_bytes is according to me would be:
>
> a) include logical decoding payload sent downstream (or via SQL
> decoding path), whether it came from transactional changes or
> non-transactional logical messages
> b) exclude auxiliary replication protocol traffic such as keepalives
>
> If this makes sense then the revised documentation shared by Ashutosh
> Bapat in his last email looks good to me, which is:
>
> Amount of transaction changes and non-transactional messages sent
> downstream in the output plugin
> format for this slot. The output plugin may filter the changes it
> receives. Hence the amount of data that it converts to the output
> plugin format is less than the <structfield>total_bytes</structfield>.
> But the format of data before and after the conversion is different.
> Hence the value of <structfield>sent_bytes</structfield> is not
> directly related to the value of
> <structfield>total_bytes</structfield>.
>
> If you all agree with this, I will first prepare a patch to fix the
> missing part in #2 which is about reporting stats for
> non-transactional messages that goes via logical decoding process and
> then on top of that share the ongoing 0001 patch with above doc
> change.
Amit Kapila and I have both mentioned that the definition you are
putting behind the sent_bytes field, as in "not accounting for the
protocol messages required in the publisher-subscriber exchange"
mentioned in b), feels strange, because these messages are sent over
the wire and part of the exchanges, like the decoded data. This could
be relevant if the exchanges consist of short decoded data and mostly
of protocol data. Of course you are free to send an updated patch
based on the definition you see fit. Whether one agrees or not with
the definition implemented in the patch is a different matter.
Anybody is also free to disagree or overwrite our opinions on the
matter, of course, that's how consensus is driven.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-06-11 08:17 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-11 08:17 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
Hi Michael,
On Wed, Mar 25, 2026 at 12:25 PM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Wed, Mar 18, 2026 at 09:58:58AM +0530, Ashutosh Sharma wrote:
> > So the right boundary for sent_bytes is according to me would be:
> >
> > a) include logical decoding payload sent downstream (or via SQL
> > decoding path), whether it came from transactional changes or
> > non-transactional logical messages
> > b) exclude auxiliary replication protocol traffic such as keepalives
> >
> > If this makes sense then the revised documentation shared by Ashutosh
> > Bapat in his last email looks good to me, which is:
> >
> > Amount of transaction changes and non-transactional messages sent
> > downstream in the output plugin
> > format for this slot. The output plugin may filter the changes it
> > receives. Hence the amount of data that it converts to the output
> > plugin format is less than the <structfield>total_bytes</structfield>.
> > But the format of data before and after the conversion is different.
> > Hence the value of <structfield>sent_bytes</structfield> is not
> > directly related to the value of
> > <structfield>total_bytes</structfield>.
> >
> > If you all agree with this, I will first prepare a patch to fix the
> > missing part in #2 which is about reporting stats for
> > non-transactional messages that goes via logical decoding process and
> > then on top of that share the ongoing 0001 patch with above doc
> > change.
>
> Amit Kapila and I have both mentioned that the definition you are
> putting behind the sent_bytes field, as in "not accounting for the
> protocol messages required in the publisher-subscriber exchange"
> mentioned in b), feels strange, because these messages are sent over
> the wire and part of the exchanges, like the decoded data.
If we start including protocol messages such as keepalives in
sent_bytes, we may end up in situations where sent_bytes exceeds
total_bytes. All byte-related columns in the pg_stat_replication_slots
catalog currently refer specifically to decoded transactional data -
none of them account for non-transactional data or data that didn't go
through logical decoding. Including keepalive data in sent_bytes could
therefore cause it to exceed total_bytes, which would likely add
confusion and make the data harder for users to interpret.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-06-12 06:59 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-12 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Kyotaro Horiguchi @ 2026-06-12 06:59 UTC (permalink / raw)
To: ashu.coek88@gmail.com; +Cc: michael@paquier.xyz; ashutosh.bapat.oss@gmail.com; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Let me go back to the original motivation.
As I understand it, the problem was that, among several subscribers
connected through different slots, one slot was lagging behind. The
total_txns and total_bytes values for that slot appeared smaller, and
you wanted to know where the bottleneck was.
I wonder if part of the confusion comes from the fact that it is not
yet clear what conclusions a user is expected to draw from these new
values.
What I am still not quite sure about is how the proposed sent_bytes
value would be used to make that distinction. It sounds like the idea
is not necessarily to look at its rate over time, but perhaps to
compare total_bytes with the proposed sent_bytes. However, as has
been discussed, these two values seem to measure different things, so
I am not sure that such a comparison would be straightforward.
I think it would help move the discussion forward if you could explain
more concretely how these new values would be used to identify the
bottleneck in the case you described.
Personally, in such a situation, I would first add some temporary
instrumentation at a few likely points and print the values with
elog() or similar, just to see which value actually distinguishes the
bottleneck. Once we know that, it should be easier to decide whether
that measurement is generally useful enough to expose in a statistics
view, and where it should be measured.
Regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-06-12 08:36 ` Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-12 08:36 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: michael@paquier.xyz; ashutosh.bapat.oss@gmail.com; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
On Fri, Jun 12, 2026 at 12:32 PM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
>
> Let me go back to the original motivation.
>
> As I understand it, the problem was that, among several subscribers
> connected through different slots, one slot was lagging behind. The
> total_txns and total_bytes values for that slot appeared smaller, and
> you wanted to know where the bottleneck was.
>
> I wonder if part of the confusion comes from the fact that it is not
> yet clear what conclusions a user is expected to draw from these new
> values.
>
> What I am still not quite sure about is how the proposed sent_bytes
> value would be used to make that distinction. It sounds like the idea
> is not necessarily to look at its rate over time, but perhaps to
> compare total_bytes with the proposed sent_bytes. However, as has
> been discussed, these two values seem to measure different things, so
> I am not sure that such a comparison would be straightforward.
>
> I think it would help move the discussion forward if you could explain
> more concretely how these new values would be used to identify the
> bottleneck in the case you described.
>
Regarding the use case of this new metric, this is my understanding,
although Ashutosh Bapat would be in a better position to comment on
its intended value and use cases. I'll wait for his perspective as
well.
My understanding is as follows:
During logical decoding, ReorderBufferProcessTXN() iterates through
the decoded changes belonging to a top-level transaction and its
subtransactions in LSN order, invoking the output plugin callbacks for
each change. For large transactions, it may be useful to expose
progress while this processing is still in progress. For example, the
system could track logical changes as they are processed and sent
downstream, periodically publishing progress to shared memory so that
users can understand how far the walsender has progressed through a
large transaction.
By contrast, total_bytes is essentially an end-of-transaction metric.
It becomes available only after processing has completed and therefore
does not provide visibility into the walsender's progress while a
large transaction is actively being decoded and streamed.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-06-15 04:18 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Ashutosh Bapat @ 2026-06-15 04:18 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: ashu.coek88@gmail.com; michael@paquier.xyz; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Fri, Jun 12, 2026 at 12:32 PM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
>
> Let me go back to the original motivation.
>
> As I understand it, the problem was that, among several subscribers
> connected through different slots, one slot was lagging behind. The
> total_txns and total_bytes values for that slot appeared smaller, and
> you wanted to know where the bottleneck was.
>
> I wonder if part of the confusion comes from the fact that it is not
> yet clear what conclusions a user is expected to draw from these new
> values.
>
> What I am still not quite sure about is how the proposed sent_bytes
> value would be used to make that distinction. It sounds like the idea
> is not necessarily to look at its rate over time, but perhaps to
> compare total_bytes with the proposed sent_bytes. However, as has
> been discussed, these two values seem to measure different things, so
> I am not sure that such a comparison would be straightforward.
>
> I think it would help move the discussion forward if you could explain
> more concretely how these new values would be used to identify the
> bottleneck in the case you described.
As I have explained in [1], total_bytes indicates the amount of data
added to the reorder buffer. It does not indicate the amount of data
in logical form sent downstream. The system which triggered this issue
used Debezium as the downstream. The customer wanted to configure
Debezium so that it can consume the logical changes in real time. But
they had no clue about the amount of logical changes they received
from upstream. total_bytes does not help since it's the amount of WAL
added to reorder buffer; not the amount of logical changes sent
downstream. Hence proposal to add new column sent_bytes.
I hope this helps.
[1] https://www.postgresql.org/message-id/flat/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2%2BAnTgYGAzo%3DQv61wA%4...
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-06-15 06:19 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Kyotaro Horiguchi @ 2026-06-15 06:19 UTC (permalink / raw)
To: ashutosh.bapat.oss@gmail.com; +Cc: ashu.coek88@gmail.com; michael@paquier.xyz; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
At Mon, 15 Jun 2026 09:48:51 +0530, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote in
> As I have explained in [1], total_bytes indicates the amount of data
> added to the reorder buffer. It does not indicate the amount of data
> in logical form sent downstream. The system which triggered this issue
> used Debezium as the downstream. The customer wanted to configure
> Debezium so that it can consume the logical changes in real time. But
> they had no clue about the amount of logical changes they received
> from upstream. total_bytes does not help since it's the amount of WAL
> added to reorder buffer; not the amount of logical changes sent
> downstream. Hence proposal to add new column sent_bytes.
>
> I hope this helps.
>
> [1] https://www.postgresql.org/message-id/flat/CAExHW5s6KntzUyUoMbKR5dgwRmd=
> V2Ay_2%2BAnTgYGAzo%3DQv61wA%40mail.gmail.com
Thanks, that clarifies the use case.
If the goal is to estimate the volume of data that downstream
consumers such as Debezium need to process, I'm still not sure why
this necessarily needs to be the amount of logical change data rather
than the amount of data actually sent over the replication connection.
For monitoring or capacity-planning purposes, wire bytes seem like
they would provide a very similar signal. The protocol overhead is
relatively small, especially when the traffic volume is high, and the
definition is somewhat more straightforward since it corresponds
directly to the amount of data transmitted downstream.
Also, I'm not sure that the logical-change size is necessarily a more
accurate representation of the amount of change being processed.
Since the amount of logical change data is itself influenced by how
the output plugin represents changes, it still seems somewhat
dependent on representation, just in a different way.
Could you explain a bit more about why the logical-change size is the
important metric here, rather than the number of bytes actually sent?
Regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-06-15 08:22 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-15 08:22 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: ashutosh.bapat.oss@gmail.com; michael@paquier.xyz; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
On Mon, Jun 15, 2026 at 11:49 AM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
>
> At Mon, 15 Jun 2026 09:48:51 +0530, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote in
> > As I have explained in [1], total_bytes indicates the amount of data
> > added to the reorder buffer. It does not indicate the amount of data
> > in logical form sent downstream. The system which triggered this issue
> > used Debezium as the downstream. The customer wanted to configure
> > Debezium so that it can consume the logical changes in real time. But
> > they had no clue about the amount of logical changes they received
> > from upstream. total_bytes does not help since it's the amount of WAL
> > added to reorder buffer; not the amount of logical changes sent
> > downstream. Hence proposal to add new column sent_bytes.
> >
> > I hope this helps.
> >
> > [1] https://www.postgresql.org/message-id/flat/CAExHW5s6KntzUyUoMbKR5dgwRmd=
> > V2Ay_2%2BAnTgYGAzo%3DQv61wA%40mail.gmail.com
>
> Thanks, that clarifies the use case.
>
> If the goal is to estimate the volume of data that downstream
> consumers such as Debezium need to process, I'm still not sure why
> this necessarily needs to be the amount of logical change data rather
> than the amount of data actually sent over the replication connection.
> For monitoring or capacity-planning purposes, wire bytes seem like
> they would provide a very similar signal. The protocol overhead is
> relatively small, especially when the traffic volume is high, and the
> definition is somewhat more straightforward since it corresponds
> directly to the amount of data transmitted downstream.
>
> Also, I'm not sure that the logical-change size is necessarily a more
> accurate representation of the amount of change being processed.
> Since the amount of logical change data is itself influenced by how
> the output plugin represents changes, it still seems somewhat
> dependent on representation, just in a different way.
>
> Could you explain a bit more about why the logical-change size is the
> important metric here, rather than the number of bytes actually sent?
>
Sorry for chiming in - I may well be misunderstanding this, but here's
how I'm currently thinking about it:
Total transaction bytes refers to the size of decoded transactional
data accumulated in the reorder buffer for a given transaction.
Sent bytes (as I understand from the patch) refers to the size of the
downstream output that the output plugin produces from that decoded
data, after any filtering and format conversion.
To illustrate: if a transaction's decoded changes occupy 550 bytes in
the reorder buffer, but the output plugin filters some out and emits
only 300 bytes downstream, then total transaction bytes = 550 and sent
bytes = 300. Conversely, if all 550 bytes are converted into a more
verbose format and emitted as 700 bytes, total transaction bytes
remains 550 while sent bytes becomes 700.
If I'm reading this right, since total bytes for a transaction is the
baseline from which transaction-derived downstream output is produced,
I wonder whether sent bytes should include only that
transaction-derived downstream output, or also downstream protocol
traffic such as keepalive messages, which are sent downstream but are
not derived from transaction bytes in the reorder buffer.
My instinct is that if sent bytes are meant to measure
transaction-output throughput, keepalive messages probably shouldn't
be included, since they have no basis in transaction data and might
distort any comparison with total bytes. But I could be wrong - happy
to be corrected!
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-06-15 09:04 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 09:16 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Kyotaro Horiguchi @ 2026-06-15 09:04 UTC (permalink / raw)
To: ashu.coek88@gmail.com; +Cc: ashutosh.bapat.oss@gmail.com; michael@paquier.xyz; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hello.
At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> Sorry for chiming in - I may well be misunderstanding this, but here's
> how I'm currently thinking about it:
>
> Total transaction bytes refers to the size of decoded transactional
> data accumulated in the reorder buffer for a given transaction.
>
> Sent bytes (as I understand from the patch) refers to the size of the
> downstream output that the output plugin produces from that decoded
> data, after any filtering and format conversion.
>
> To illustrate: if a transaction's decoded changes occupy 550 bytes in
> the reorder buffer, but the output plugin filters some out and emits
> only 300 bytes downstream, then total transaction bytes = 550 and sent
> bytes = 300. Conversely, if all 550 bytes are converted into a more
> verbose format and emitted as 700 bytes, total transaction bytes
> remains 550 while sent bytes becomes 700.
>
> If I'm reading this right, since total bytes for a transaction is the
> baseline from which transaction-derived downstream output is produced,
> I wonder whether sent bytes should include only that
> transaction-derived downstream output, or also downstream protocol
> traffic such as keepalive messages, which are sent downstream but are
> not derived from transaction bytes in the reorder buffer.
>
> My instinct is that if sent bytes are meant to measure
> transaction-output throughput, keepalive messages probably shouldn't
> be included, since they have no basis in transaction data and might
> distort any comparison with total bytes. But I could be wrong - happy
> to be corrected!
Thank you for the explanation.
I think I understand the distinction you are making. However, my
question is one step earlier than the keepalive-message question. I am
wondering whether the new metric needs to be defined in terms of
logical-change output in the first place.
If I understand the use case correctly, I think the discussion here is
primarily about relatively high-volume logical replication
workloads. My point is that, in that situation, I would expect the
amount of logical-change output and the amount of data actually sent
over the replication connection to show broadly similar trends.
The latter seems easier to interpret, while still providing a useful
signal for monitoring and capacity-planning purposes. It also seems
more intuitive, since it corresponds directly to the amount of data
sent over the replication connection.
Regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-06-15 09:16 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2026-06-15 09:16 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: ashu.coek88@gmail.com; michael@paquier.xyz; amit.kapila16@gmail.com; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Mon, Jun 15, 2026 at 2:34 PM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
>
> Hello.
>
> At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> > Sorry for chiming in - I may well be misunderstanding this, but here's
> > how I'm currently thinking about it:
> >
> > Total transaction bytes refers to the size of decoded transactional
> > data accumulated in the reorder buffer for a given transaction.
> >
> > Sent bytes (as I understand from the patch) refers to the size of the
> > downstream output that the output plugin produces from that decoded
> > data, after any filtering and format conversion.
> >
> > To illustrate: if a transaction's decoded changes occupy 550 bytes in
> > the reorder buffer, but the output plugin filters some out and emits
> > only 300 bytes downstream, then total transaction bytes = 550 and sent
> > bytes = 300. Conversely, if all 550 bytes are converted into a more
> > verbose format and emitted as 700 bytes, total transaction bytes
> > remains 550 while sent bytes becomes 700.
> >
> > If I'm reading this right, since total bytes for a transaction is the
> > baseline from which transaction-derived downstream output is produced,
> > I wonder whether sent bytes should include only that
> > transaction-derived downstream output, or also downstream protocol
> > traffic such as keepalive messages, which are sent downstream but are
> > not derived from transaction bytes in the reorder buffer.
> >
> > My instinct is that if sent bytes are meant to measure
> > transaction-output throughput, keepalive messages probably shouldn't
> > be included, since they have no basis in transaction data and might
> > distort any comparison with total bytes. But I could be wrong - happy
> > to be corrected!
>
> Thank you for the explanation.
>
> I think I understand the distinction you are making. However, my
> question is one step earlier than the keepalive-message question. I am
> wondering whether the new metric needs to be defined in terms of
> logical-change output in the first place.
>
> If I understand the use case correctly, I think the discussion here is
> primarily about relatively high-volume logical replication
> workloads. My point is that, in that situation, I would expect the
> amount of logical-change output and the amount of data actually sent
> over the replication connection to show broadly similar trends.
>
> The latter seems easier to interpret, while still providing a useful
> signal for monitoring and capacity-planning purposes. It also seems
> more intuitive, since it corresponds directly to the amount of data
> sent over the replication connection.
The total data (bytes) sent over the network are available from
network monitoring systems. That includes both protocol messages and
logical change data. Out of these two logical change data is processed
through a pipeline which actually loads the downstream. The protocol
messages are usually processed and responded to quickly. They are not
passed further down the pipeline that consumes the logical changes.
Hence amount of logical change data is important; not so much the
amount of protocol messages. Protocol messages form a small amount
usually when there is high volume of data processed, but that need not
be true generally. total_bytes is no indicator of high or low volume.
The system may be generating huge amounts of WAL but publication may
be filtering most of it and sending only a small amount downstream.
Amount of only logical changes is accurate measure of load that is
being created on the downstream pipeline.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-06-15 13:53 ` Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2026-06-15 13:53 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: ashu.coek88@gmail.com; ashutosh.bapat.oss@gmail.com; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Mon, Jun 15, 2026 at 2:34 PM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
>
> At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> > Sorry for chiming in - I may well be misunderstanding this, but here's
> > how I'm currently thinking about it:
> >
> > Total transaction bytes refers to the size of decoded transactional
> > data accumulated in the reorder buffer for a given transaction.
> >
> > Sent bytes (as I understand from the patch) refers to the size of the
> > downstream output that the output plugin produces from that decoded
> > data, after any filtering and format conversion.
> >
> > To illustrate: if a transaction's decoded changes occupy 550 bytes in
> > the reorder buffer, but the output plugin filters some out and emits
> > only 300 bytes downstream, then total transaction bytes = 550 and sent
> > bytes = 300. Conversely, if all 550 bytes are converted into a more
> > verbose format and emitted as 700 bytes, total transaction bytes
> > remains 550 while sent bytes becomes 700.
> >
> > If I'm reading this right, since total bytes for a transaction is the
> > baseline from which transaction-derived downstream output is produced,
> > I wonder whether sent bytes should include only that
> > transaction-derived downstream output, or also downstream protocol
> > traffic such as keepalive messages, which are sent downstream but are
> > not derived from transaction bytes in the reorder buffer.
> >
> > My instinct is that if sent bytes are meant to measure
> > transaction-output throughput, keepalive messages probably shouldn't
> > be included, since they have no basis in transaction data and might
> > distort any comparison with total bytes. But I could be wrong - happy
> > to be corrected!
>
> Thank you for the explanation.
>
> I think I understand the distinction you are making. However, my
> question is one step earlier than the keepalive-message question. I am
> wondering whether the new metric needs to be defined in terms of
> logical-change output in the first place.
>
> If I understand the use case correctly, I think the discussion here is
> primarily about relatively high-volume logical replication
> workloads. My point is that, in that situation, I would expect the
> amount of logical-change output and the amount of data actually sent
> over the replication connection to show broadly similar trends.
>
> The latter seems easier to interpret, while still providing a useful
> signal for monitoring and capacity-planning purposes. It also seems
> more intuitive, since it corresponds directly to the amount of data
> sent over the replication connection.
>
BTW, the patch internally counts other protocol messages like START
STREAM/STOP STREAM, BEGIN/END, and quite a few others that help apply
workers to understand transaction boundaries and messages. So, I feel
in that sense we are already counting protocol bytes as part of patch,
so why leave the additional messages that are being discussed here.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-06-16 09:05 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-16 11:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Ashutosh Bapat @ 2026-06-16 09:05 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; ashu.coek88@gmail.com; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Mon, Jun 15, 2026 at 7:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Jun 15, 2026 at 2:34 PM Kyotaro Horiguchi
> <horikyota.ntt@gmail.com> wrote:
> >
> > At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> > > Sorry for chiming in - I may well be misunderstanding this, but here's
> > > how I'm currently thinking about it:
> > >
> > > Total transaction bytes refers to the size of decoded transactional
> > > data accumulated in the reorder buffer for a given transaction.
> > >
> > > Sent bytes (as I understand from the patch) refers to the size of the
> > > downstream output that the output plugin produces from that decoded
> > > data, after any filtering and format conversion.
> > >
> > > To illustrate: if a transaction's decoded changes occupy 550 bytes in
> > > the reorder buffer, but the output plugin filters some out and emits
> > > only 300 bytes downstream, then total transaction bytes = 550 and sent
> > > bytes = 300. Conversely, if all 550 bytes are converted into a more
> > > verbose format and emitted as 700 bytes, total transaction bytes
> > > remains 550 while sent bytes becomes 700.
> > >
> > > If I'm reading this right, since total bytes for a transaction is the
> > > baseline from which transaction-derived downstream output is produced,
> > > I wonder whether sent bytes should include only that
> > > transaction-derived downstream output, or also downstream protocol
> > > traffic such as keepalive messages, which are sent downstream but are
> > > not derived from transaction bytes in the reorder buffer.
> > >
> > > My instinct is that if sent bytes are meant to measure
> > > transaction-output throughput, keepalive messages probably shouldn't
> > > be included, since they have no basis in transaction data and might
> > > distort any comparison with total bytes. But I could be wrong - happy
> > > to be corrected!
> >
> > Thank you for the explanation.
> >
> > I think I understand the distinction you are making. However, my
> > question is one step earlier than the keepalive-message question. I am
> > wondering whether the new metric needs to be defined in terms of
> > logical-change output in the first place.
> >
> > If I understand the use case correctly, I think the discussion here is
> > primarily about relatively high-volume logical replication
> > workloads. My point is that, in that situation, I would expect the
> > amount of logical-change output and the amount of data actually sent
> > over the replication connection to show broadly similar trends.
> >
> > The latter seems easier to interpret, while still providing a useful
> > signal for monitoring and capacity-planning purposes. It also seems
> > more intuitive, since it corresponds directly to the amount of data
> > sent over the replication connection.
> >
>
> BTW, the patch internally counts other protocol messages like START
> STREAM/STOP STREAM, BEGIN/END, and quite a few others that help apply
> workers to understand transaction boundaries and messages. So, I feel
> in that sense we are already counting protocol bytes as part of patch,
> so why leave the additional messages that are being discussed here.
Those are logical message types which are part of the logical change
data - without those messages it's not possible to process the logical
change data. So they are included. But the keepalive messages, for
example, aren't part of the logical change data.
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-06-16 11:25 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-22 11:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-16 11:25 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Tue, Jun 16, 2026 at 2:36 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Mon, Jun 15, 2026 at 7:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Mon, Jun 15, 2026 at 2:34 PM Kyotaro Horiguchi
> > <horikyota.ntt@gmail.com> wrote:
> > >
> > > At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> > > > Sorry for chiming in - I may well be misunderstanding this, but here's
> > > > how I'm currently thinking about it:
> > > >
> > > > Total transaction bytes refers to the size of decoded transactional
> > > > data accumulated in the reorder buffer for a given transaction.
> > > >
> > > > Sent bytes (as I understand from the patch) refers to the size of the
> > > > downstream output that the output plugin produces from that decoded
> > > > data, after any filtering and format conversion.
> > > >
> > > > To illustrate: if a transaction's decoded changes occupy 550 bytes in
> > > > the reorder buffer, but the output plugin filters some out and emits
> > > > only 300 bytes downstream, then total transaction bytes = 550 and sent
> > > > bytes = 300. Conversely, if all 550 bytes are converted into a more
> > > > verbose format and emitted as 700 bytes, total transaction bytes
> > > > remains 550 while sent bytes becomes 700.
> > > >
> > > > If I'm reading this right, since total bytes for a transaction is the
> > > > baseline from which transaction-derived downstream output is produced,
> > > > I wonder whether sent bytes should include only that
> > > > transaction-derived downstream output, or also downstream protocol
> > > > traffic such as keepalive messages, which are sent downstream but are
> > > > not derived from transaction bytes in the reorder buffer.
> > > >
> > > > My instinct is that if sent bytes are meant to measure
> > > > transaction-output throughput, keepalive messages probably shouldn't
> > > > be included, since they have no basis in transaction data and might
> > > > distort any comparison with total bytes. But I could be wrong - happy
> > > > to be corrected!
> > >
> > > Thank you for the explanation.
> > >
> > > I think I understand the distinction you are making. However, my
> > > question is one step earlier than the keepalive-message question. I am
> > > wondering whether the new metric needs to be defined in terms of
> > > logical-change output in the first place.
> > >
> > > If I understand the use case correctly, I think the discussion here is
> > > primarily about relatively high-volume logical replication
> > > workloads. My point is that, in that situation, I would expect the
> > > amount of logical-change output and the amount of data actually sent
> > > over the replication connection to show broadly similar trends.
> > >
> > > The latter seems easier to interpret, while still providing a useful
> > > signal for monitoring and capacity-planning purposes. It also seems
> > > more intuitive, since it corresponds directly to the amount of data
> > > sent over the replication connection.
> > >
> >
> > BTW, the patch internally counts other protocol messages like START
> > STREAM/STOP STREAM, BEGIN/END, and quite a few others that help apply
> > workers to understand transaction boundaries and messages. So, I feel
> > in that sense we are already counting protocol bytes as part of patch,
> > so why leave the additional messages that are being discussed here.
>
> Those are logical message types which are part of the logical change
> data - without those messages it's not possible to process the logical
> change data. So they are included. But the keepalive messages, for
> example, aren't part of the logical change data.
>
I think it would be worth capturing this distinction clearly in the
user documentation. Thanks Amit for raising this point.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-16 11:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-06-22 11:54 ` Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 0 replies; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-22 11:54 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
On Tue, Jun 16, 2026 at 4:55 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> On Tue, Jun 16, 2026 at 2:36 PM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> > On Mon, Jun 15, 2026 at 7:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > > On Mon, Jun 15, 2026 at 2:34 PM Kyotaro Horiguchi
> > > <horikyota.ntt@gmail.com> wrote:
> > > >
> > > > At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> > > > > Sorry for chiming in - I may well be misunderstanding this, but here's
> > > > > how I'm currently thinking about it:
> > > > >
> > > > > Total transaction bytes refers to the size of decoded transactional
> > > > > data accumulated in the reorder buffer for a given transaction.
> > > > >
> > > > > Sent bytes (as I understand from the patch) refers to the size of the
> > > > > downstream output that the output plugin produces from that decoded
> > > > > data, after any filtering and format conversion.
> > > > >
> > > > > To illustrate: if a transaction's decoded changes occupy 550 bytes in
> > > > > the reorder buffer, but the output plugin filters some out and emits
> > > > > only 300 bytes downstream, then total transaction bytes = 550 and sent
> > > > > bytes = 300. Conversely, if all 550 bytes are converted into a more
> > > > > verbose format and emitted as 700 bytes, total transaction bytes
> > > > > remains 550 while sent bytes becomes 700.
> > > > >
> > > > > If I'm reading this right, since total bytes for a transaction is the
> > > > > baseline from which transaction-derived downstream output is produced,
> > > > > I wonder whether sent bytes should include only that
> > > > > transaction-derived downstream output, or also downstream protocol
> > > > > traffic such as keepalive messages, which are sent downstream but are
> > > > > not derived from transaction bytes in the reorder buffer.
> > > > >
> > > > > My instinct is that if sent bytes are meant to measure
> > > > > transaction-output throughput, keepalive messages probably shouldn't
> > > > > be included, since they have no basis in transaction data and might
> > > > > distort any comparison with total bytes. But I could be wrong - happy
> > > > > to be corrected!
> > > >
> > > > Thank you for the explanation.
> > > >
> > > > I think I understand the distinction you are making. However, my
> > > > question is one step earlier than the keepalive-message question. I am
> > > > wondering whether the new metric needs to be defined in terms of
> > > > logical-change output in the first place.
> > > >
> > > > If I understand the use case correctly, I think the discussion here is
> > > > primarily about relatively high-volume logical replication
> > > > workloads. My point is that, in that situation, I would expect the
> > > > amount of logical-change output and the amount of data actually sent
> > > > over the replication connection to show broadly similar trends.
> > > >
> > > > The latter seems easier to interpret, while still providing a useful
> > > > signal for monitoring and capacity-planning purposes. It also seems
> > > > more intuitive, since it corresponds directly to the amount of data
> > > > sent over the replication connection.
> > > >
> > >
> > > BTW, the patch internally counts other protocol messages like START
> > > STREAM/STOP STREAM, BEGIN/END, and quite a few others that help apply
> > > workers to understand transaction boundaries and messages. So, I feel
> > > in that sense we are already counting protocol bytes as part of patch,
> > > so why leave the additional messages that are being discussed here.
> >
> > Those are logical message types which are part of the logical change
> > data - without those messages it's not possible to process the logical
> > change data. So they are included. But the keepalive messages, for
> > example, aren't part of the logical change data.
> >
>
> I think it would be worth capturing this distinction clearly in the
> user documentation. Thanks Amit for raising this point.
>
PFA a patch rebased on HEAD. It also includes a small documentation
correction based on our recent discussion, clarifying that total_bytes
is not necessarily greater than sent_bytes.
--
With Regards,
Ashutosh Sharma.
Attachments:
v20260622-0001-Report-downstream-sent-bytes-in-pg_stat_replication_.patch (application/octet-stream, 26.4K) download
From d7cd565c3b37c346ef7f8574fb190664672ba28b Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Mon, 22 Jun 2026 11:01:13 +0000
Subject: [PATCH 1/2] Report downstream sent bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes sent to downstream consumers.
Add sent_bytes to expose that metric and help diagnose replication
throughput issues caused by a slow or stalled downstream consumer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 +++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 13 ++---
doc/src/sgml/monitoring.sgml | 17 +++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 7 ++-
.../replication/logical/logicalfuncs.c | 8 ++++
.../replication/logical/reorderbuffer.c | 1 +
src/backend/replication/walsender.c | 3 ++
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 ++++----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 1 +
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 3 +-
16 files changed, 96 insertions(+), 54 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..2dd45460317 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | sent_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | sent_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..9f85455bce1 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes > 0 AS sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, sent_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..88899824bae 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ sent_bytes > 0 AS sent_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 08d5b824552..72a7c85ea46 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1692,6 +1692,23 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <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 the changes into the output plugin's format. This can
+ differ from <structfield>total_bytes</structfield> because filtered
+ changes are not sent and because the output plugin's format can have
+ a different size than the decoded changes. Therefore,
+ <structfield>sent_bytes</structfield> is not directly comparable to
+ <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8f129baec90..02fdb607961 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1139,6 +1139,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3541fc793e4..613e208cbae 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1958,7 +1958,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1968,7 +1968,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->sentBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1979,6 +1980,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.sent_bytes = rb->sentBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1991,6 +1993,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->sentBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 71fbaf72269..60f3092d666 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 sentBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ sentBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ sentBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,8 +90,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ sentBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += sentBytes;
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 059ed860314..7b1fb0fd473 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -394,6 +394,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->sentBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index c931d9b4fa8..6fa8a7bb89f 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1650,6 +1650,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->sentBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index a32b70a0373..6a787ccef04 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(sent_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 6f9c9c72de5..b11d17b2ccd 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2181,7 +2181,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2212,11 +2212,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "sent_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2243,17 +2245,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->sent_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index be157a5fbe9..3f677e903d7 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5735,9 +5735,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,sent_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index dfa2e837638..bf5d8b0f23f 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -422,6 +422,7 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter sent_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index ff825e4b7b2..9be3e0453ba 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 sentBytes; /* amount of data decoded and sent downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..5354322e196 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, sent_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, sent_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and sent_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index a65a5bf0c4f..1390fb3a264 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2260,11 +2260,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.sent_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, sent_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2026-06-24 23:07 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-25 07:31 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 2 replies; 123+ messages in thread
From: Masahiko Sawada @ 2026-06-24 23:07 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; ashu.coek88@gmail.com; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Tue, Jun 16, 2026 at 2:06 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Mon, Jun 15, 2026 at 7:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Mon, Jun 15, 2026 at 2:34 PM Kyotaro Horiguchi
> > <horikyota.ntt@gmail.com> wrote:
> > >
> > > At Mon, 15 Jun 2026 13:52:36 +0530, Ashutosh Sharma <ashu.coek88@gmail.com> wrote in
> > > > Sorry for chiming in - I may well be misunderstanding this, but here's
> > > > how I'm currently thinking about it:
> > > >
> > > > Total transaction bytes refers to the size of decoded transactional
> > > > data accumulated in the reorder buffer for a given transaction.
> > > >
> > > > Sent bytes (as I understand from the patch) refers to the size of the
> > > > downstream output that the output plugin produces from that decoded
> > > > data, after any filtering and format conversion.
> > > >
> > > > To illustrate: if a transaction's decoded changes occupy 550 bytes in
> > > > the reorder buffer, but the output plugin filters some out and emits
> > > > only 300 bytes downstream, then total transaction bytes = 550 and sent
> > > > bytes = 300. Conversely, if all 550 bytes are converted into a more
> > > > verbose format and emitted as 700 bytes, total transaction bytes
> > > > remains 550 while sent bytes becomes 700.
> > > >
> > > > If I'm reading this right, since total bytes for a transaction is the
> > > > baseline from which transaction-derived downstream output is produced,
> > > > I wonder whether sent bytes should include only that
> > > > transaction-derived downstream output, or also downstream protocol
> > > > traffic such as keepalive messages, which are sent downstream but are
> > > > not derived from transaction bytes in the reorder buffer.
> > > >
> > > > My instinct is that if sent bytes are meant to measure
> > > > transaction-output throughput, keepalive messages probably shouldn't
> > > > be included, since they have no basis in transaction data and might
> > > > distort any comparison with total bytes. But I could be wrong - happy
> > > > to be corrected!
> > >
> > > Thank you for the explanation.
> > >
> > > I think I understand the distinction you are making. However, my
> > > question is one step earlier than the keepalive-message question. I am
> > > wondering whether the new metric needs to be defined in terms of
> > > logical-change output in the first place.
> > >
> > > If I understand the use case correctly, I think the discussion here is
> > > primarily about relatively high-volume logical replication
> > > workloads. My point is that, in that situation, I would expect the
> > > amount of logical-change output and the amount of data actually sent
> > > over the replication connection to show broadly similar trends.
> > >
> > > The latter seems easier to interpret, while still providing a useful
> > > signal for monitoring and capacity-planning purposes. It also seems
> > > more intuitive, since it corresponds directly to the amount of data
> > > sent over the replication connection.
> > >
> >
> > BTW, the patch internally counts other protocol messages like START
> > STREAM/STOP STREAM, BEGIN/END, and quite a few others that help apply
> > workers to understand transaction boundaries and messages. So, I feel
> > in that sense we are already counting protocol bytes as part of patch,
> > so why leave the additional messages that are being discussed here.
>
> Those are logical message types which are part of the logical change
> data - without those messages it's not possible to process the logical
> change data. So they are included. But the keepalive messages, for
> example, aren't part of the logical change data.
I think logical replication messages like STREAM START/STREAM STOP and
BEGIN/END, versus messages like keepalive and standby/primary status
updates, operate at different layers. The former are the contents of
the logical output and seem to belong naturally to the replication
slot's statistics. I'm not sure the latter should be included as well
-- I'm concerned that counting those bytes would become noise when
analyzing the statistics over time, since they have no relation to the
volume of logical changes.
If we do want a statistic showing the literal total bytes sent
downstream including protocol messages, ISTM that should be available
for both logical and physical replication: physical replication also
uses keepalive messages and adds a header to each message. In other
words, that kind of "bytes on the wire" metric isn't really specific
to a logical replication slot, so the slot's statistics don't seem
like the right place for it.
The proposed column name 'sent_bytes' is also confusing to me, because
I don't think we can call it "total bytes actually sent" in the
logical decoding SQL API case. A name like 'plugin_total_bytes' seems
more straightforward and conveys the intent that protocol messages are
not included.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-06-25 07:31 ` Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-25 07:31 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
On Thu, Jun 25, 2026 at 4:37 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> The proposed column name 'sent_bytes' is also confusing to me, because
> I don't think we can call it "total bytes actually sent" in the
> logical decoding SQL API case. A name like 'plugin_total_bytes' seems
> more straightforward and conveys the intent that protocol messages are
> not included.
>
Thank you for sharing your perspective. I agree that sent bytes
doesn't entirely reflect the bytes transmitted over the wire, rather,
it represents the total bytes emitted during the output plugin write
cycle.
In the walsender path, currently sent bytes = ctx->out->len + 1, which includes:
- plugin output
- 25-byte WALData header added by OutputPluginPrepareWrite()
- 1-byte CopyData message type
In the SQL path, sent bytes = ctx->out->len + 12, which includes:
- plugin output
- XLogRecPtr
- XID tuple column payloads
With this in mind, it may be worth considering a rename for sent bytes
to plugin_total_bytes, or maybe plugin_output_bytes, or simply
output_bytes. That said, it would be great to hear what others think
before making a decision.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-06-28 06:56 ` Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 1 reply; 123+ messages in thread
From: Amit Kapila @ 2026-06-28 06:56 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; ashu.coek88@gmail.com; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Thu, Jun 25, 2026 at 4:37 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> On Tue, Jun 16, 2026 at 2:06 AM Ashutosh Bapat
> <ashutosh.bapat.oss@gmail.com> wrote:
> >
> >
> > Those are logical message types which are part of the logical change
> > data - without those messages it's not possible to process the logical
> > change data. So they are included. But the keepalive messages, for
> > example, aren't part of the logical change data.
>
> I think logical replication messages like STREAM START/STREAM STOP and
> BEGIN/END, versus messages like keepalive and standby/primary status
> updates, operate at different layers. The former are the contents of
> the logical output and seem to belong naturally to the replication
> slot's statistics. I'm not sure the latter should be included as well
> -- I'm concerned that counting those bytes would become noise when
> analyzing the statistics over time, since they have no relation to the
> volume of logical changes.
>
Both you and Ashutosh seem to make the similar points and sound
reasonable, so let's do it that way.
> If we do want a statistic showing the literal total bytes sent
> downstream including protocol messages, ISTM that should be available
> for both logical and physical replication: physical replication also
> uses keepalive messages and adds a header to each message. In other
> words, that kind of "bytes on the wire" metric isn't really specific
> to a logical replication slot, so the slot's statistics don't seem
> like the right place for it.
>
> The proposed column name 'sent_bytes' is also confusing to me, because
> I don't think we can call it "total bytes actually sent" in the
> logical decoding SQL API case. A name like 'plugin_total_bytes' seems
> more straightforward and conveys the intent that protocol messages are
> not included.
>
The SQL API point is genuine and if we display sent_bytes via SQL API
then pg_logical_slot_get_changes() will show nonzero sent_bytes even
though nothing was ever sent anywhere. OTOH, adding plugin_* prefix
also starts to make it sound like stats are plugin specific, how about
calling it as 'output_bytes'? It pairs cleanly with the existing
column: total_bytes = decoded into the reorder buffer, output_bytes =
decoded and handed to the consumer.
If we use output_bytes, then we can describe the new stats on the
lines of following text in the docs:
<para>
Amount of decoded data produced for this slot's consumer by the output
plugin, after applying any output plugin filters and converting the
changes into the output plugin's format. This counts the transaction
changes together with the messages that delimit them (such as the
begin and commit messages), but not connection-management messages
such as keepalives, which are generated by the server rather than the
output plugin and are therefore not included.
</para>
<para>
This value can differ from <structfield>total_bytes</structfield>: it
may be smaller because filtered changes are not output, or larger
because the output plugin's format can be more verbose than the
decoded changes. For these reasons
<structfield>output_bytes</structfield> is not directly comparable to
<structfield>total_bytes</structfield>.
</para>
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
@ 2026-06-29 09:08 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-29 09:08 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Masahiko Sawada <sawada.mshk@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi Amit,
On Sun, Jun 28, 2026 at 12:26 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Thu, Jun 25, 2026 at 4:37 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> >
> > On Tue, Jun 16, 2026 at 2:06 AM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > >
> > > Those are logical message types which are part of the logical change
> > > data - without those messages it's not possible to process the logical
> > > change data. So they are included. But the keepalive messages, for
> > > example, aren't part of the logical change data.
> >
> > I think logical replication messages like STREAM START/STREAM STOP and
> > BEGIN/END, versus messages like keepalive and standby/primary status
> > updates, operate at different layers. The former are the contents of
> > the logical output and seem to belong naturally to the replication
> > slot's statistics. I'm not sure the latter should be included as well
> > -- I'm concerned that counting those bytes would become noise when
> > analyzing the statistics over time, since they have no relation to the
> > volume of logical changes.
> >
>
> Both you and Ashutosh seem to make the similar points and sound
> reasonable, so let's do it that way.
>
> > If we do want a statistic showing the literal total bytes sent
> > downstream including protocol messages, ISTM that should be available
> > for both logical and physical replication: physical replication also
> > uses keepalive messages and adds a header to each message. In other
> > words, that kind of "bytes on the wire" metric isn't really specific
> > to a logical replication slot, so the slot's statistics don't seem
> > like the right place for it.
> >
> > The proposed column name 'sent_bytes' is also confusing to me, because
> > I don't think we can call it "total bytes actually sent" in the
> > logical decoding SQL API case. A name like 'plugin_total_bytes' seems
> > more straightforward and conveys the intent that protocol messages are
> > not included.
> >
>
> The SQL API point is genuine and if we display sent_bytes via SQL API
> then pg_logical_slot_get_changes() will show nonzero sent_bytes even
> though nothing was ever sent anywhere. OTOH, adding plugin_* prefix
> also starts to make it sound like stats are plugin specific, how about
> calling it as 'output_bytes'? It pairs cleanly with the existing
> column: total_bytes = decoded into the reorder buffer, output_bytes =
> decoded and handed to the consumer.
>
> If we use output_bytes, then we can describe the new stats on the
> lines of following text in the docs:
> <para>
> Amount of decoded data produced for this slot's consumer by the output
> plugin, after applying any output plugin filters and converting the
> changes into the output plugin's format. This counts the transaction
> changes together with the messages that delimit them (such as the
> begin and commit messages), but not connection-management messages
> such as keepalives, which are generated by the server rather than the
> output plugin and are therefore not included.
> </para>
> <para>
> This value can differ from <structfield>total_bytes</structfield>: it
> may be smaller because filtered changes are not output, or larger
> because the output plugin's format can be more verbose than the
> decoded changes. For these reasons
> <structfield>output_bytes</structfield> is not directly comparable to
> <structfield>total_bytes</structfield>.
> </para>
>
Please find the attached patch that renames sent_bytes to
output_bytes. Kindly have a look and feel free to share any comments
or suggestions.
--
With Regards,
Ashutosh Sharma.
Attachments:
v20260629-0001-Report-output-bytes-in-pg_stat_replication_slots.patch (application/octet-stream, 26.9K) download
From 82a3f4c6ced148c19d77d1acb3119d4f0b158b00 Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Mon, 22 Jun 2026 11:01:13 +0000
Subject: [PATCH] Report output bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes produced by the output plugin for
downstream consumers. Add output_bytes to expose that metric and help
diagnose replication throughput issues caused by a slow or stalled
downstream consumer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 +++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 13 ++---
doc/src/sgml/monitoring.sgml | 24 ++++++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 7 ++-
.../replication/logical/logicalfuncs.c | 8 ++++
.../replication/logical/reorderbuffer.c | 1 +
src/backend/replication/walsender.c | 3 ++
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 ++++----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 1 +
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 3 +-
16 files changed, 103 insertions(+), 54 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..98748841905 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..2f95cadf7c5 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..f081cf8417a 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ output_bytes > 0 AS output_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 08d5b824552..a5eed73693b 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1692,6 +1692,30 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>output_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of decoded data produced for this slot's consumer by the output
+ plugin, after applying any output plugin filters and converting the
+ changes into the output plugin's format. This counts the transaction
+ changes together with the messages that delimit them (such as the
+ begin and commit messages), but not connection-management messages
+ such as keepalives, which are generated by the server rather than the
+ output plugin and are therefore not included.
+ </para>
+ <para>
+ This value can differ from <structfield>total_bytes</structfield>: it
+ may be smaller because filtered changes are not output, or larger
+ because the output plugin's format can be more verbose than the
+ decoded changes. For these reasons
+ <structfield>output_bytes</structfield> is not directly comparable to
+ <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8f129baec90..9943706ca80 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1139,6 +1139,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3541fc793e4..1638c336929 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1958,7 +1958,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1968,7 +1968,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->outputBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1979,6 +1980,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.output_bytes = rb->outputBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1991,6 +1993,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->outputBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 71fbaf72269..3cad69de782 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
Datum values[3];
bool nulls[3];
DecodingOutputState *p;
+ int64 outputBytes = 0;
/* SQL Datums can only be of a limited length... */
if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ outputBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ outputBytes += sizeof(TransactionId);
/*
* Assert ctx->out is in database encoding when we're writing textual
@@ -87,8 +90,13 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+ outputBytes += ctx->out->len;
tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
+
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->outputBytes += outputBytes;
+
p->returned_rows++;
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 059ed860314..e735bf63f10 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -394,6 +394,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->outputBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index c931d9b4fa8..1382dd2ad7f 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1650,6 +1650,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock(PqMsg_CopyData, ctx->out->data, ctx->out->len);
+ /* Update the amount of data sent downstream. */
+ ctx->reorder->outputBytes += ctx->out->len + 1; /* +1 for the 'd' */
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index a32b70a0373..d5ffc1a7f36 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(output_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 6f9c9c72de5..ef0016cb35e 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2181,7 +2181,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2212,11 +2212,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "output_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2243,17 +2245,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->output_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 402d869710b..34fe893361c 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5735,9 +5735,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,output_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index dfa2e837638..cb48d37418a 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -422,6 +422,7 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter output_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index ff825e4b7b2..79a8afb8006 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 outputBytes; /* amount of data produced for downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..812bdd2b9ed 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, output_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, output_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and output_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index a65a5bf0c4f..ed61b20cb5c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2260,11 +2260,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, output_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-06-29 23:01 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Masahiko Sawada @ 2026-06-29 23:01 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Mon, Jun 29, 2026 at 2:08 AM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> Hi Amit,
>
> On Sun, Jun 28, 2026 at 12:26 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Thu, Jun 25, 2026 at 4:37 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> > >
> > > On Tue, Jun 16, 2026 at 2:06 AM Ashutosh Bapat
> > > <ashutosh.bapat.oss@gmail.com> wrote:
> > > >
> > > >
> > > > Those are logical message types which are part of the logical change
> > > > data - without those messages it's not possible to process the logical
> > > > change data. So they are included. But the keepalive messages, for
> > > > example, aren't part of the logical change data.
> > >
> > > I think logical replication messages like STREAM START/STREAM STOP and
> > > BEGIN/END, versus messages like keepalive and standby/primary status
> > > updates, operate at different layers. The former are the contents of
> > > the logical output and seem to belong naturally to the replication
> > > slot's statistics. I'm not sure the latter should be included as well
> > > -- I'm concerned that counting those bytes would become noise when
> > > analyzing the statistics over time, since they have no relation to the
> > > volume of logical changes.
> > >
> >
> > Both you and Ashutosh seem to make the similar points and sound
> > reasonable, so let's do it that way.
> >
> > > If we do want a statistic showing the literal total bytes sent
> > > downstream including protocol messages, ISTM that should be available
> > > for both logical and physical replication: physical replication also
> > > uses keepalive messages and adds a header to each message. In other
> > > words, that kind of "bytes on the wire" metric isn't really specific
> > > to a logical replication slot, so the slot's statistics don't seem
> > > like the right place for it.
> > >
> > > The proposed column name 'sent_bytes' is also confusing to me, because
> > > I don't think we can call it "total bytes actually sent" in the
> > > logical decoding SQL API case. A name like 'plugin_total_bytes' seems
> > > more straightforward and conveys the intent that protocol messages are
> > > not included.
> > >
> >
> > The SQL API point is genuine and if we display sent_bytes via SQL API
> > then pg_logical_slot_get_changes() will show nonzero sent_bytes even
> > though nothing was ever sent anywhere. OTOH, adding plugin_* prefix
> > also starts to make it sound like stats are plugin specific, how about
> > calling it as 'output_bytes'? It pairs cleanly with the existing
> > column: total_bytes = decoded into the reorder buffer, output_bytes =
> > decoded and handed to the consumer.
> >
> > If we use output_bytes, then we can describe the new stats on the
> > lines of following text in the docs:
> > <para>
> > Amount of decoded data produced for this slot's consumer by the output
> > plugin, after applying any output plugin filters and converting the
> > changes into the output plugin's format. This counts the transaction
> > changes together with the messages that delimit them (such as the
> > begin and commit messages), but not connection-management messages
> > such as keepalives, which are generated by the server rather than the
> > output plugin and are therefore not included.
> > </para>
> > <para>
> > This value can differ from <structfield>total_bytes</structfield>: it
> > may be smaller because filtered changes are not output, or larger
> > because the output plugin's format can be more verbose than the
> > decoded changes. For these reasons
> > <structfield>output_bytes</structfield> is not directly comparable to
> > <structfield>total_bytes</structfield>.
> > </para>
> >
>
> Please find the attached patch that renames sent_bytes to
> output_bytes. Kindly have a look and feel free to share any comments
> or suggestions.
Thank you for updating the patch! The new column name output_bytes
looks good to me.
Here are some comments:
memset(nulls, 0, sizeof(nulls));
values[0] = LSNGetDatum(lsn);
+ outputBytes += sizeof(XLogRecPtr);
values[1] = TransactionIdGetDatum(xid);
+ outputBytes += sizeof(TransactionId);
:
:
/* ick, but cstring_to_text_with_len works for bytea perfectly
fine */ values[2] =
PointerGetDatum(cstring_to_text_with_len(ctx->out->data,
ctx->out->len));
+ outputBytes += ctx->out->len;
I'm not sure that we should include these values to the new statistics
since they are not the data produced by output plugins. I think it's
better to collect the amount of data output plugins produced and get
it in OutputPluginWrite(). What do you think?
---
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 "
%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
" %" PRId64 " %" PRId64,
+ elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 "
%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
" %" PRId64 " %" PRId64 " %" PRId64,
This log message is already quite hard to read, and I'm concerned that
simply dumping ten unlabeled numbers is no longer helpful for
debugging. If all of these metrics are indeed still useful, I would
propose adding explicit labels for each one. Otherwise, we might as
well remove this elog() entirely.
---
@@ -1979,6 +1980,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.output_bytes = rb->outputBytes;
Since output_bytes is now the tenth field we accumulate for
replication slot statistics, it seems like a good opportunity to
improve its maintainability. Instead of adding fields individually, we
could define a common structure for these shared metrics so that both
PgStat_StatReplSlotEntry and ReorderBuffer can embed it. This way,
UpdateDecodingStats() could simply assign the collected struct and
clear it using MemSet().
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-06-30 07:01 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-30 07:01 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Thank you, Masahiko-san, for your review comments. Please find my
responses inline below:
On Tue, Jun 30, 2026 at 4:32 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> On Mon, Jun 29, 2026 at 2:08 AM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> >
> Thank you for updating the patch! The new column name output_bytes
> looks good to me.
>
> Here are some comments:
>
> memset(nulls, 0, sizeof(nulls));
> values[0] = LSNGetDatum(lsn);
> + outputBytes += sizeof(XLogRecPtr);
> values[1] = TransactionIdGetDatum(xid);
> + outputBytes += sizeof(TransactionId);
> :
> :
> /* ick, but cstring_to_text_with_len works for bytea perfectly
> fine */ values[2] =
> PointerGetDatum(cstring_to_text_with_len(ctx->out->data,
> ctx->out->len));
> + outputBytes += ctx->out->len;
>
> I'm not sure that we should include these values to the new statistics
> since they are not the data produced by output plugins. I think it's
> better to collect the amount of data output plugins produced and get
> it in OutputPluginWrite(). What do you think?
>
Agreed. The values added by the SQL interface, such as the LSN and XID
columns, are not produced by the output plugin, so they should not be
counted as output bytes.
I also agree that output_bytes should be incremented in
OutputPluginWrite(), since that is the common path for both the SQL
and walsender consumers and ctx->out contains the data produced by the
output plugin there.
I have implemented these changes in the attached patch, please have a
look and let me know your thoughts.
> ---
> - elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 "
> %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
> " %" PRId64 " %" PRId64,
> + elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 "
> %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
> " %" PRId64 " %" PRId64 " %" PRId64,
>
> This log message is already quite hard to read, and I'm concerned that
> simply dumping ten unlabeled numbers is no longer helpful for
> debugging. If all of these metrics are indeed still useful, I would
> propose adding explicit labels for each one. Otherwise, we might as
> well remove this elog() entirely.
>
I have added labels for each field emitted by this debug message, as I
am not quite sure that removing it completely would be a good idea.
> ---
> @@ -1979,6 +1980,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
> repSlotStat.mem_exceeded_count = rb->memExceededCount;
> repSlotStat.total_txns = rb->totalTxns;
> repSlotStat.total_bytes = rb->totalBytes;
> + repSlotStat.output_bytes = rb->outputBytes;
>
> Since output_bytes is now the tenth field we accumulate for
> replication slot statistics, it seems like a good opportunity to
> improve its maintainability. Instead of adding fields individually, we
> could define a common structure for these shared metrics so that both
> PgStat_StatReplSlotEntry and ReorderBuffer can embed it. This way,
> UpdateDecodingStats() could simply assign the collected struct and
> clear it using MemSet().
>
I agree that this would improve maintainability.
PgStat_StatReplSlotEntry now has 13 fields, and 10 of them are the
decoding counters that are also tracked in ReorderBuffer, so a common
counter-only structure sounds like the right direction.
That said, this is not specific to the output_bytes field being added
here. It is more of a refactoring of the boundary between logical
decoding and pgstat statistics. To keep this patch focused, I think it
would be better to handle that as a separate follow-up patch, possibly
with a new thread once this work is done. Please let me know your
thoughts on this?
--
With Regards,
Ashutosh Sharma.
Attachments:
v20260630-0001-Report-output-bytes-in-pg_stat_replication_slots.patch (application/octet-stream, 25.4K) download
From 798ff3f59cb6e74c430dd0b3cafabccad16d7cf5 Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Tue, 30 Jun 2026 06:32:50 +0000
Subject: [PATCH] Report output bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes produced by the output plugin for
downstream consumers. Add output_bytes to expose that metric and help
diagnose replication throughput issues caused by a slow or stalled
downstream consumer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 +++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 13 ++---
doc/src/sgml/monitoring.sgml | 24 ++++++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 18 ++++++-
.../replication/logical/reorderbuffer.c | 1 +
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 ++++----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 1 +
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 3 +-
14 files changed, 103 insertions(+), 54 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..98748841905 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..2f95cadf7c5 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..f081cf8417a 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ output_bytes > 0 AS output_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 6dcf05eb702..98eb2b2e579 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1692,6 +1692,30 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>output_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of decoded data produced for this slot's consumer by the output
+ plugin, after applying any output plugin filters and converting the
+ changes into the output plugin's format. This counts the transaction
+ changes together with the messages that delimit them (such as the
+ begin and commit messages), but not connection-management messages
+ such as keepalives, which are generated by the server rather than the
+ output plugin and are therefore not included.
+ </para>
+ <para>
+ This value can differ from <structfield>total_bytes</structfield>: it
+ may be smaller because filtered changes are not output, or larger
+ because the output plugin's format can be more verbose than the
+ decoded changes. For these reasons
+ <structfield>output_bytes</structfield> is not directly comparable to
+ <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8f129baec90..9943706ca80 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1139,6 +1139,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3541fc793e4..8435f4128e8 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -697,10 +697,15 @@ OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
void
OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
{
+ int64 outputBytes;
+
if (!ctx->prepared_write)
elog(ERROR, "OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
+ outputBytes = ctx->out->len;
+
ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
+ ctx->reorder->outputBytes += outputBytes;
ctx->prepared_write = false;
}
@@ -1958,7 +1963,13 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2,
+ "UpdateDecodingStats: updating stats %p spill_txns=%" PRId64
+ " spill_count=%" PRId64 " spill_bytes=%" PRId64
+ " stream_txns=%" PRId64 " stream_count=%" PRId64
+ " stream_bytes=%" PRId64 " mem_exceeded_count=%" PRId64
+ " total_txns=%" PRId64 " total_bytes=%" PRId64
+ " output_bytes=%" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1968,7 +1979,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->outputBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1979,6 +1991,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.output_bytes = rb->outputBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1991,6 +2004,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->outputBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 059ed860314..e735bf63f10 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -394,6 +394,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->outputBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index a32b70a0373..d5ffc1a7f36 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(output_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 0c59df17901..7f153743205 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2181,7 +2181,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2212,11 +2212,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "output_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2243,17 +2245,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->output_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index efe13b7866a..b0fcfbc7088 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5735,9 +5735,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,output_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 72496695999..45f15bb5357 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -422,6 +422,7 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter output_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index ff825e4b7b2..79a8afb8006 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 outputBytes; /* amount of data produced for downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..812bdd2b9ed 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, output_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, output_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and output_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index a65a5bf0c4f..ed61b20cb5c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2260,11 +2260,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, output_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-06-30 12:39 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-07-02 21:49 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-06-30 12:39 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
On Tue, Jun 30, 2026 at 12:31 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> Thank you, Masahiko-san, for your review comments. Please find my
> responses inline below:
>
> On Tue, Jun 30, 2026 at 4:32 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> >
> > ---
> > @@ -1979,6 +1980,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
> > repSlotStat.mem_exceeded_count = rb->memExceededCount;
> > repSlotStat.total_txns = rb->totalTxns;
> > repSlotStat.total_bytes = rb->totalBytes;
> > + repSlotStat.output_bytes = rb->outputBytes;
> >
> > Since output_bytes is now the tenth field we accumulate for
> > replication slot statistics, it seems like a good opportunity to
> > improve its maintainability. Instead of adding fields individually, we
> > could define a common structure for these shared metrics so that both
> > PgStat_StatReplSlotEntry and ReorderBuffer can embed it. This way,
> > UpdateDecodingStats() could simply assign the collected struct and
> > clear it using MemSet().
> >
>
> I agree that this would improve maintainability.
> PgStat_StatReplSlotEntry now has 13 fields, and 10 of them are the
> decoding counters that are also tracked in ReorderBuffer, so a common
> counter-only structure sounds like the right direction.
>
> That said, this is not specific to the output_bytes field being added
> here. It is more of a refactoring of the boundary between logical
> decoding and pgstat statistics. To keep this patch focused, I think it
> would be better to handle that as a separate follow-up patch, possibly
> with a new thread once this work is done. Please let me know your
> thoughts on this?
>
In case you'd prefer to have the refactoring done as part of this
effort, I'm attaching a patch that performs the refactoring described
above, with the patch for reporting output_bytes built on top of it.
Please have a look and let me know your feedback.
--
With Regards,
Ashutosh Sharma.
Attachments: download all (2 files, .tar.gz)
v20260630-0002-Report-output-bytes-in-pg_stat_replication_slots.patch (application/octet-stream, 24.0K) download
From 4fb2f984e47b729ed22a07851ce4d41aec722aeb Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Tue, 30 Jun 2026 12:25:59 +0000
Subject: [PATCH 2/2] Report output bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes produced by the output plugin for
downstream consumers. Add output_bytes to expose that metric and help
diagnose replication throughput issues caused by a slow or stalled
downstream consumer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 ++++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 13 +++---
doc/src/sgml/monitoring.sgml | 24 ++++++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 16 ++++++-
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 +++++----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 3 +-
12 files changed, 99 insertions(+), 54 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..98748841905 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..2f95cadf7c5 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..f081cf8417a 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ output_bytes > 0 AS output_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 05bd501c682..d7703673430 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1692,6 +1692,30 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>output_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of decoded data produced for this slot's consumer by the output
+ plugin, after applying any output plugin filters and converting the
+ changes into the output plugin's format. This counts the transaction
+ changes together with the messages that delimit them (such as the
+ begin and commit messages), but not connection-management messages
+ such as keepalives, which are generated by the server rather than the
+ output plugin and are therefore not included.
+ </para>
+ <para>
+ This value can differ from <structfield>total_bytes</structfield>: it
+ may be smaller because filtered changes are not output, or larger
+ because the output plugin's format can be more verbose than the
+ decoded changes. For these reasons
+ <structfield>output_bytes</structfield> is not directly comparable to
+ <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8f129baec90..9943706ca80 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1139,6 +1139,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 87d1303d6c9..8f3893f7eff 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -697,10 +697,15 @@ OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
void
OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
{
+ int64 output_bytes;
+
if (!ctx->prepared_write)
elog(ERROR, "OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
+ output_bytes = ctx->out->len;
+
ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
+ ctx->reorder->stats.output_bytes += output_bytes;
ctx->prepared_write = false;
}
@@ -1957,7 +1962,13 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->stats.total_bytes <= 0 && rb->stats.mem_exceeded_count <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2,
+ "UpdateDecodingStats: updating stats %p spill_txns=%" PRId64
+ " spill_count=%" PRId64 " spill_bytes=%" PRId64
+ " stream_txns=%" PRId64 " stream_count=%" PRId64
+ " stream_bytes=%" PRId64 " mem_exceeded_count=%" PRId64
+ " total_txns=%" PRId64 " total_bytes=%" PRId64
+ " output_bytes=%" PRId64,
rb,
rb->stats.spill_txns,
rb->stats.spill_count,
@@ -1967,7 +1978,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->stats.stream_bytes,
rb->stats.mem_exceeded_count,
rb->stats.total_txns,
- rb->stats.total_bytes);
+ rb->stats.total_bytes,
+ rb->stats.output_bytes);
pgstat_report_replslot(ctx->slot, &rb->stats);
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 5283dfe6344..9e42d05c70b 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlo
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(output_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 06ad40f2907..46fb03a8ad3 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2221,7 +2221,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2252,11 +2252,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "output_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2283,17 +2285,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->decoding_stats.mem_exceeded_count);
values[8] = Int64GetDatum(slotent->decoding_stats.total_txns);
values[9] = Int64GetDatum(slotent->decoding_stats.total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->decoding_stats.output_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 73bb7fbb430..bdd61b54a15 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5735,9 +5735,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,output_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 0410cf649b0..beab75585c9 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -422,6 +422,7 @@ typedef struct PgStat_ReplSlotStats
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter output_bytes;
} PgStat_ReplSlotStats;
typedef struct PgStat_StatReplSlotEntry
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..e55a61374e8 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, output_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and output bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, output_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and output_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index a65a5bf0c4f..ed61b20cb5c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2260,11 +2260,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, output_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
v20260630-0001-Refactor-replication-slot-decoding-stats-handling.patch (application/octet-stream, 13.2K) download
From 2bfa6de147aecac125883c23413f0e82614223ea Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Tue, 30 Jun 2026 11:56:03 +0000
Subject: [PATCH 1/2] Refactor replication slot decoding stats handling
The logical decoding stats reported for replication slots already use
several closely-related counters. ReorderBuffer collected those
values as separate fields, while PgStat_StatReplSlotEntry stored the
same set again, requiring UpdateDecodingStats() to copy and clear
every field individually.
Introduce PgStat_ReplSlotStats as the common structure for these
logical decoding counters. Embed it in ReorderBuffer for collection
and in PgStat_StatReplSlotEntry for storage, keeping slot
synchronization and reset metadata outside the shared struct because
those fields are not collected by logical decoding.
With the counters grouped this way, UpdateDecodingStats() can pass the
collected struct directly to pgstat_report_replslot() and clear
it with a single MemSet(). The pgstat reporting path now accumulates
only the shared counter struct, and pg_stat_get_replication_slot()
reads the same counters from the nested decoding_stats member.
This makes future additions to the logical decoding replication slot
counters less error-prone by keeping the collection, reporting, and
reset paths tied to a single shared type.
Per suggestion from Masahiko Sawada
---
src/backend/replication/logical/logical.c | 49 ++++++-------------
.../replication/logical/reorderbuffer.c | 32 +++++-------
src/backend/utils/activity/pgstat_replslot.c | 6 +--
src/backend/utils/adt/pgstatfuncs.c | 18 +++----
src/include/pgstat.h | 9 +++-
src/include/replication/reorderbuffer.h | 28 ++---------
src/tools/pgindent/typedefs.list | 1 +
7 files changed, 50 insertions(+), 93 deletions(-)
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3541fc793e4..87d1303d6c9 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1951,46 +1951,27 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
- PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
- if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0 &&
- rb->memExceededCount <= 0)
+ if (rb->stats.spill_bytes <= 0 && rb->stats.stream_bytes <= 0 &&
+ rb->stats.total_bytes <= 0 && rb->stats.mem_exceeded_count <= 0)
return;
elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
rb,
- rb->spillTxns,
- rb->spillCount,
- rb->spillBytes,
- rb->streamTxns,
- rb->streamCount,
- rb->streamBytes,
- rb->memExceededCount,
- rb->totalTxns,
- rb->totalBytes);
-
- repSlotStat.spill_txns = rb->spillTxns;
- repSlotStat.spill_count = rb->spillCount;
- repSlotStat.spill_bytes = rb->spillBytes;
- repSlotStat.stream_txns = rb->streamTxns;
- repSlotStat.stream_count = rb->streamCount;
- repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
-
- pgstat_report_replslot(ctx->slot, &repSlotStat);
-
- rb->spillTxns = 0;
- rb->spillCount = 0;
- rb->spillBytes = 0;
- rb->streamTxns = 0;
- rb->streamCount = 0;
- rb->streamBytes = 0;
- rb->memExceededCount = 0;
- rb->totalTxns = 0;
- rb->totalBytes = 0;
+ rb->stats.spill_txns,
+ rb->stats.spill_count,
+ rb->stats.spill_bytes,
+ rb->stats.stream_txns,
+ rb->stats.stream_count,
+ rb->stats.stream_bytes,
+ rb->stats.mem_exceeded_count,
+ rb->stats.total_txns,
+ rb->stats.total_bytes);
+
+ pgstat_report_replslot(ctx->slot, &rb->stats);
+
+ MemSet(&rb->stats, 0, sizeof(PgStat_ReplSlotStats));
}
/*
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 059ed860314..36e5dc767b8 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -385,15 +385,7 @@ ReorderBufferAllocate(void)
/* txn_heap is ordered by transaction size */
buffer->txn_heap = pairingheap_allocate(ReorderBufferTXNSizeCompare, NULL);
- buffer->spillTxns = 0;
- buffer->spillCount = 0;
- buffer->spillBytes = 0;
- buffer->streamTxns = 0;
- buffer->streamCount = 0;
- buffer->streamBytes = 0;
- buffer->memExceededCount = 0;
- buffer->totalTxns = 0;
- buffer->totalBytes = 0;
+ MemSet(&buffer->stats, 0, sizeof(PgStat_ReplSlotStats));
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
@@ -1469,7 +1461,7 @@ ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state)
* releasing the current set of changes and restoring the new set of
* changes.
*/
- rb->totalBytes += entry->txn->size;
+ rb->stats.total_bytes += entry->txn->size;
if (ReorderBufferRestoreChanges(rb, entry->txn, &entry->file,
&state->entries[off].segno))
{
@@ -2613,9 +2605,9 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
* which we have already accounted in ReorderBufferIterTXNNext.
*/
if (!rbtxn_is_streamed(txn))
- rb->totalTxns++;
+ rb->stats.total_txns++;
- rb->totalBytes += txn->total_size;
+ rb->stats.total_bytes += txn->total_size;
/*
* Done with current changes, send the last message for this set of
@@ -3902,7 +3894,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
* update the slot statistics altogether while streaming or
* serializing transactions in most cases.
*/
- rb->memExceededCount += 1;
+ rb->stats.mem_exceeded_count += 1;
}
else if (debug_logical_replication_streaming == DEBUG_LOGICAL_REP_STREAMING_BUFFERED)
{
@@ -3973,7 +3965,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
Assert(txn->nentries_mem == 0);
/*
- * We've reported the memExceededCount update while streaming or
+ * We've reported the mem_exceeded_count update while streaming or
* serializing the transaction.
*/
update_stats = false;
@@ -4062,11 +4054,11 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/* update the statistics iff we have spilled anything */
if (spilled)
{
- rb->spillCount += 1;
- rb->spillBytes += size;
+ rb->stats.spill_count += 1;
+ rb->stats.spill_bytes += size;
/* don't consider already serialized transactions */
- rb->spillTxns += (rbtxn_is_serialized(txn) || rbtxn_is_serialized_clear(txn)) ? 0 : 1;
+ rb->stats.spill_txns += (rbtxn_is_serialized(txn) || rbtxn_is_serialized_clear(txn)) ? 0 : 1;
/* update the decoding stats */
UpdateDecodingStats((LogicalDecodingContext *) rb->private_data);
@@ -4434,11 +4426,11 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
ReorderBufferProcessTXN(rb, txn, InvalidXLogRecPtr, snapshot_now,
command_id, true);
- rb->streamCount += 1;
- rb->streamBytes += stream_bytes;
+ rb->stats.stream_count += 1;
+ rb->stats.stream_bytes += stream_bytes;
/* Don't consider already streamed transaction. */
- rb->streamTxns += (txn_is_streamed) ? 0 : 1;
+ rb->stats.stream_txns += (txn_is_streamed) ? 0 : 1;
/* update the decoding stats */
UpdateDecodingStats((LogicalDecodingContext *) rb->private_data);
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index a32b70a0373..5283dfe6344 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -74,16 +74,16 @@ pgstat_reset_replslot(const char *name)
* pgstat_acquire_replslot() have already been called.
*/
void
-pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
+pgstat_report_replslot(ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlotStat)
{
PgStat_EntryRef *entry_ref;
PgStatShared_ReplSlot *shstatent;
- PgStat_StatReplSlotEntry *statent;
+ PgStat_ReplSlotStats *statent;
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_REPLSLOT, InvalidOid,
ReplicationSlotIndex(slot), false);
shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
- statent = &shstatent->stats;
+ statent = &shstatent->stats.decoding_stats;
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 0c6a20843a5..06ad40f2907 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2274,15 +2274,15 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
}
values[0] = CStringGetTextDatum(NameStr(slotname));
- values[1] = Int64GetDatum(slotent->spill_txns);
- values[2] = Int64GetDatum(slotent->spill_count);
- values[3] = Int64GetDatum(slotent->spill_bytes);
- values[4] = Int64GetDatum(slotent->stream_txns);
- values[5] = Int64GetDatum(slotent->stream_count);
- values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
+ values[1] = Int64GetDatum(slotent->decoding_stats.spill_txns);
+ values[2] = Int64GetDatum(slotent->decoding_stats.spill_count);
+ values[3] = Int64GetDatum(slotent->decoding_stats.spill_bytes);
+ values[4] = Int64GetDatum(slotent->decoding_stats.stream_txns);
+ values[5] = Int64GetDatum(slotent->decoding_stats.stream_count);
+ values[6] = Int64GetDatum(slotent->decoding_stats.stream_bytes);
+ values[7] = Int64GetDatum(slotent->decoding_stats.mem_exceeded_count);
+ values[8] = Int64GetDatum(slotent->decoding_stats.total_txns);
+ values[9] = Int64GetDatum(slotent->decoding_stats.total_bytes);
values[10] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 58a44857f13..0410cf649b0 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -411,7 +411,7 @@ typedef struct PgStat_StatFuncEntry
TimestampTz stat_reset_timestamp;
} PgStat_StatFuncEntry;
-typedef struct PgStat_StatReplSlotEntry
+typedef struct PgStat_ReplSlotStats
{
PgStat_Counter spill_txns;
PgStat_Counter spill_count;
@@ -422,6 +422,11 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+} PgStat_ReplSlotStats;
+
+typedef struct PgStat_StatReplSlotEntry
+{
+ PgStat_ReplSlotStats decoding_stats;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
@@ -787,7 +792,7 @@ extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
extern void pgstat_reset_replslot(const char *name);
struct ReplicationSlot;
-extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
+extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlotStat);
extern void pgstat_report_replslotsync(struct ReplicationSlot *slot);
extern void pgstat_create_replslot(struct ReplicationSlot *slot);
extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index ff825e4b7b2..3a84b8c46e8 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -12,6 +12,7 @@
#include "access/htup_details.h"
#include "lib/ilist.h"
#include "lib/pairingheap.h"
+#include "pgstat.h"
#include "storage/sinval.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
@@ -674,31 +675,8 @@ struct ReorderBuffer
/* Max-heap for sizes of all top-level and sub transactions */
pairingheap *txn_heap;
- /*
- * Statistics about transactions spilled to disk.
- *
- * A single transaction may be spilled repeatedly, which is why we keep
- * two different counters. For spilling, the transaction counter includes
- * both toplevel transactions and subtransactions.
- */
- int64 spillTxns; /* number of transactions spilled to disk */
- int64 spillCount; /* spill-to-disk invocation counter */
- int64 spillBytes; /* amount of data spilled to disk */
-
- /* Statistics about transactions streamed to the decoding output plugin */
- int64 streamTxns; /* number of transactions streamed */
- int64 streamCount; /* streaming invocation counter */
- int64 streamBytes; /* amount of data decoded */
-
- /* Number of times the logical_decoding_work_mem limit has been reached */
- int64 memExceededCount;
-
- /*
- * Statistics about all the transactions sent to the decoding output
- * plugin
- */
- int64 totalTxns; /* total number of transactions sent */
- int64 totalBytes; /* total amount of data decoded */
+ /* Replication slot statistics collected by logical decoding. */
+ PgStat_ReplSlotStats stats;
};
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 3a2720fb5f9..07e4dcc94c3 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2348,6 +2348,7 @@ PgStat_LockEntry
PgStat_PendingDroppedStatsItem
PgStat_PendingIO
PgStat_PendingLock
+PgStat_ReplSlotStats
PgStat_SLRUStats
PgStat_ShmemControl
PgStat_Snapshot
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-07-02 21:49 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-07-03 05:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Masahiko Sawada @ 2026-07-02 21:49 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On Tue, Jun 30, 2026 at 5:39 AM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> Hi,
>
> On Tue, Jun 30, 2026 at 12:31 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> >
> > Thank you, Masahiko-san, for your review comments. Please find my
> > responses inline below:
> >
> > On Tue, Jun 30, 2026 at 4:32 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> > >
> > > ---
> > > @@ -1979,6 +1980,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
> > > repSlotStat.mem_exceeded_count = rb->memExceededCount;
> > > repSlotStat.total_txns = rb->totalTxns;
> > > repSlotStat.total_bytes = rb->totalBytes;
> > > + repSlotStat.output_bytes = rb->outputBytes;
> > >
> > > Since output_bytes is now the tenth field we accumulate for
> > > replication slot statistics, it seems like a good opportunity to
> > > improve its maintainability. Instead of adding fields individually, we
> > > could define a common structure for these shared metrics so that both
> > > PgStat_StatReplSlotEntry and ReorderBuffer can embed it. This way,
> > > UpdateDecodingStats() could simply assign the collected struct and
> > > clear it using MemSet().
> > >
> >
> > I agree that this would improve maintainability.
> > PgStat_StatReplSlotEntry now has 13 fields, and 10 of them are the
> > decoding counters that are also tracked in ReorderBuffer, so a common
> > counter-only structure sounds like the right direction.
> >
> > That said, this is not specific to the output_bytes field being added
> > here. It is more of a refactoring of the boundary between logical
> > decoding and pgstat statistics. To keep this patch focused, I think it
> > would be better to handle that as a separate follow-up patch, possibly
> > with a new thread once this work is done. Please let me know your
> > thoughts on this?
> >
>
> In case you'd prefer to have the refactoring done as part of this
> effort, I'm attaching a patch that performs the refactoring described
> above, with the patch for reporting output_bytes built on top of it.
> Please have a look and let me know your feedback.
Thank you for updating the patch.
I agree that the refactoring part should be done in a separate patch.
Could you swap these patches' order? I think that these patches are
independent of each other and while we have an agreement on the new
statistics, we still need discussion for the refactoring part
(particularly I guess it's better to avoid including pgstatt.h in
reorderbuffer.h)
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-07-02 21:49 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-07-03 05:44 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-08-20 03:01 ` Re: Report bytes and transactions actually sent downtream Aditya Gollamudi <adigollamudi@gmail.com>
0 siblings, 1 reply; 123+ messages in thread
From: Ashutosh Sharma @ 2026-07-03 05:44 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi Masahiko-san,
On Fri, Jul 3, 2026 at 3:20 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> Could you swap these patches' order? I think that these patches are
> independent of each other and while we have an agreement on the new
> statistics, we still need discussion for the refactoring part
> (particularly I guess it's better to avoid including pgstatt.h in
> reorderbuffer.h)
>
Thank you for your review comments.
I have swapped the patch order - please see attached.
In the refactoring patch, I also ensured that reorderbuffer.h does not
depend on pgstat.h. To make that possible, I introduced a shared
header, src/include/replication/replslot_stats.h, where
PgStat_ReplSlotStats is defined. Both pgstat.h and reorderbuffer.h
include that header. Hope that helps!
--
With Regards,
Ashutosh Sharma.
Attachments: download all (2 files, .tar.gz)
v20260703-0001-Report-output-bytes-in-pg_stat_replication_slots.patch (application/octet-stream, 25.4K) download
From 74e9d40d1f7e0804c9bc48de1a07d4f4c6218aca Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Tue, 30 Jun 2026 06:32:50 +0000
Subject: [PATCH 1/2] Report output bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes produced by the output plugin for
downstream consumers. Add output_bytes to expose that metric and help
diagnose replication throughput issues caused by a slow or stalled
downstream consumer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 48 +++++++++----------
contrib/test_decoding/sql/stats.sql | 7 +--
contrib/test_decoding/t/001_repl_stats.pl | 13 ++---
doc/src/sgml/monitoring.sgml | 24 ++++++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 18 ++++++-
.../replication/logical/reorderbuffer.c | 1 +
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 ++++----
src/include/catalog/pg_proc.dat | 6 +--
src/include/pgstat.h | 1 +
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 ++---
src/test/regress/expected/rules.out | 3 +-
14 files changed, 103 insertions(+), 54 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..98748841905 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -37,12 +37,12 @@ SELECT pg_stat_force_next_flush();
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +53,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +68,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..2f95cadf7c5 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -15,16 +15,17 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL,
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..f081cf8417a 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ output_bytes > 0 AS output_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 12b9ee20d4a..86d60923bf6 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1702,6 +1702,30 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>output_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of decoded data produced for this slot's consumer by the output
+ plugin, after applying any output plugin filters and converting the
+ changes into the output plugin's format. This counts the transaction
+ changes together with the messages that delimit them (such as the
+ begin and commit messages), but not connection-management messages
+ such as keepalives, which are generated by the server rather than the
+ output plugin and are therefore not included.
+ </para>
+ <para>
+ This value can differ from <structfield>total_bytes</structfield>: it
+ may be smaller because filtered changes are not output, or larger
+ because the output plugin's format can be more verbose than the
+ decoded changes. For these reasons
+ <structfield>output_bytes</structfield> is not directly comparable to
+ <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 6c1c5545cb5..3191627d775 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1139,6 +1139,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3541fc793e4..8435f4128e8 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -697,10 +697,15 @@ OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
void
OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
{
+ int64 outputBytes;
+
if (!ctx->prepared_write)
elog(ERROR, "OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
+ outputBytes = ctx->out->len;
+
ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
+ ctx->reorder->outputBytes += outputBytes;
ctx->prepared_write = false;
}
@@ -1958,7 +1963,13 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2,
+ "UpdateDecodingStats: updating stats %p spill_txns=%" PRId64
+ " spill_count=%" PRId64 " spill_bytes=%" PRId64
+ " stream_txns=%" PRId64 " stream_count=%" PRId64
+ " stream_bytes=%" PRId64 " mem_exceeded_count=%" PRId64
+ " total_txns=%" PRId64 " total_bytes=%" PRId64
+ " output_bytes=%" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -1968,7 +1979,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->outputBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -1979,6 +1991,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.output_bytes = rb->outputBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -1991,6 +2004,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->outputBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 059ed860314..e735bf63f10 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -394,6 +394,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->outputBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index a32b70a0373..d5ffc1a7f36 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(output_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 565d0e70768..6ea59f44749 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2221,7 +2221,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2252,11 +2252,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "output_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2283,17 +2285,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->output_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 3cb84359adf..f6512c59c0a 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5735,9 +5735,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,output_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 58a44857f13..c90f19b547c 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -422,6 +422,7 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter output_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index ff825e4b7b2..79a8afb8006 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 outputBytes; /* amount of data produced for downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..812bdd2b9ed 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, output_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, output_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and output_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index e266f501d87..af6fd862029 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2268,11 +2268,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, output_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
v20260703-0002-Refactor-replication-slot-decoding-stats-handling.patch (application/octet-stream, 15.2K) download
From 02cf5b9566a0887b8f86955c14789502f76e755a Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Fri, 3 Jul 2026 05:25:17 +0000
Subject: [PATCH 2/2] Refactor replication slot decoding stats handling
Replication slot decoding stats use several related counters.
Previously, ReorderBuffer collected them as separate fields,
while PgStat_StatReplSlotEntry stored the same set again.
UpdateDecodingStats() then had to copy and clear each field by
hand.
Introduce PgStat_ReplSlotStats as the common structure for
these logical decoding counters. Embed it in ReorderBuffer for
collection and in PgStat_StatReplSlotEntry for storage, while
keeping slot synchronization and reset metadata outside it.
With the counters grouped, UpdateDecodingStats() can pass the
collected struct directly to pgstat_report_replslot() and clear
it with a single MemSet(). The pgstat reporting path now
accumulates the shared struct, and pg_stat_get_replication_slot()
reads counters from the nested decoding_stats member.
Keep the shared type in a small replication header, so
reorderbuffer.h does not need to include pgstat.h.
This makes future logical decoding replication slot counters
less error-prone to add by tying collection, reporting, and
reset paths to one shared type.
Per suggestion from Masahiko Sawada
---
src/backend/replication/logical/logical.c | 55 ++++++-------------
.../replication/logical/reorderbuffer.c | 33 ++++-------
src/backend/utils/activity/pgstat_replslot.c | 6 +-
src/backend/utils/adt/pgstatfuncs.c | 20 +++----
src/include/pgstat.h | 14 +----
src/include/replication/reorderbuffer.h | 29 +---------
src/include/replication/replslot_stats.h | 29 ++++++++++
src/tools/pgindent/typedefs.list | 1 +
8 files changed, 78 insertions(+), 109 deletions(-)
create mode 100644 src/include/replication/replslot_stats.h
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 8435f4128e8..c83f0b9056f 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -705,7 +705,7 @@ OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
outputBytes = ctx->out->len;
ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
- ctx->reorder->outputBytes += outputBytes;
+ ctx->reorder->stats.output_bytes += outputBytes;
ctx->prepared_write = false;
}
@@ -1956,11 +1956,10 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
- PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
- if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0 &&
- rb->memExceededCount <= 0)
+ if (rb->stats.spill_bytes <= 0 && rb->stats.stream_bytes <= 0 &&
+ rb->stats.total_bytes <= 0 && rb->stats.mem_exceeded_count <= 0)
return;
elog(DEBUG2,
@@ -1971,40 +1970,20 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
" total_txns=%" PRId64 " total_bytes=%" PRId64
" output_bytes=%" PRId64,
rb,
- rb->spillTxns,
- rb->spillCount,
- rb->spillBytes,
- rb->streamTxns,
- rb->streamCount,
- rb->streamBytes,
- rb->memExceededCount,
- rb->totalTxns,
- rb->totalBytes,
- rb->outputBytes);
-
- repSlotStat.spill_txns = rb->spillTxns;
- repSlotStat.spill_count = rb->spillCount;
- repSlotStat.spill_bytes = rb->spillBytes;
- repSlotStat.stream_txns = rb->streamTxns;
- repSlotStat.stream_count = rb->streamCount;
- repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
- repSlotStat.output_bytes = rb->outputBytes;
-
- pgstat_report_replslot(ctx->slot, &repSlotStat);
-
- rb->spillTxns = 0;
- rb->spillCount = 0;
- rb->spillBytes = 0;
- rb->streamTxns = 0;
- rb->streamCount = 0;
- rb->streamBytes = 0;
- rb->memExceededCount = 0;
- rb->totalTxns = 0;
- rb->totalBytes = 0;
- rb->outputBytes = 0;
+ rb->stats.spill_txns,
+ rb->stats.spill_count,
+ rb->stats.spill_bytes,
+ rb->stats.stream_txns,
+ rb->stats.stream_count,
+ rb->stats.stream_bytes,
+ rb->stats.mem_exceeded_count,
+ rb->stats.total_txns,
+ rb->stats.total_bytes,
+ rb->stats.output_bytes);
+
+ pgstat_report_replslot(ctx->slot, &rb->stats);
+
+ MemSet(&rb->stats, 0, sizeof(PgStat_ReplSlotStats));
}
/*
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index e735bf63f10..36e5dc767b8 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -385,16 +385,7 @@ ReorderBufferAllocate(void)
/* txn_heap is ordered by transaction size */
buffer->txn_heap = pairingheap_allocate(ReorderBufferTXNSizeCompare, NULL);
- buffer->spillTxns = 0;
- buffer->spillCount = 0;
- buffer->spillBytes = 0;
- buffer->streamTxns = 0;
- buffer->streamCount = 0;
- buffer->streamBytes = 0;
- buffer->memExceededCount = 0;
- buffer->totalTxns = 0;
- buffer->totalBytes = 0;
- buffer->outputBytes = 0;
+ MemSet(&buffer->stats, 0, sizeof(PgStat_ReplSlotStats));
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
@@ -1470,7 +1461,7 @@ ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state)
* releasing the current set of changes and restoring the new set of
* changes.
*/
- rb->totalBytes += entry->txn->size;
+ rb->stats.total_bytes += entry->txn->size;
if (ReorderBufferRestoreChanges(rb, entry->txn, &entry->file,
&state->entries[off].segno))
{
@@ -2614,9 +2605,9 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
* which we have already accounted in ReorderBufferIterTXNNext.
*/
if (!rbtxn_is_streamed(txn))
- rb->totalTxns++;
+ rb->stats.total_txns++;
- rb->totalBytes += txn->total_size;
+ rb->stats.total_bytes += txn->total_size;
/*
* Done with current changes, send the last message for this set of
@@ -3903,7 +3894,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
* update the slot statistics altogether while streaming or
* serializing transactions in most cases.
*/
- rb->memExceededCount += 1;
+ rb->stats.mem_exceeded_count += 1;
}
else if (debug_logical_replication_streaming == DEBUG_LOGICAL_REP_STREAMING_BUFFERED)
{
@@ -3974,7 +3965,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
Assert(txn->nentries_mem == 0);
/*
- * We've reported the memExceededCount update while streaming or
+ * We've reported the mem_exceeded_count update while streaming or
* serializing the transaction.
*/
update_stats = false;
@@ -4063,11 +4054,11 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/* update the statistics iff we have spilled anything */
if (spilled)
{
- rb->spillCount += 1;
- rb->spillBytes += size;
+ rb->stats.spill_count += 1;
+ rb->stats.spill_bytes += size;
/* don't consider already serialized transactions */
- rb->spillTxns += (rbtxn_is_serialized(txn) || rbtxn_is_serialized_clear(txn)) ? 0 : 1;
+ rb->stats.spill_txns += (rbtxn_is_serialized(txn) || rbtxn_is_serialized_clear(txn)) ? 0 : 1;
/* update the decoding stats */
UpdateDecodingStats((LogicalDecodingContext *) rb->private_data);
@@ -4435,11 +4426,11 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
ReorderBufferProcessTXN(rb, txn, InvalidXLogRecPtr, snapshot_now,
command_id, true);
- rb->streamCount += 1;
- rb->streamBytes += stream_bytes;
+ rb->stats.stream_count += 1;
+ rb->stats.stream_bytes += stream_bytes;
/* Don't consider already streamed transaction. */
- rb->streamTxns += (txn_is_streamed) ? 0 : 1;
+ rb->stats.stream_txns += (txn_is_streamed) ? 0 : 1;
/* update the decoding stats */
UpdateDecodingStats((LogicalDecodingContext *) rb->private_data);
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index d5ffc1a7f36..9e42d05c70b 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -74,16 +74,16 @@ pgstat_reset_replslot(const char *name)
* pgstat_acquire_replslot() have already been called.
*/
void
-pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
+pgstat_report_replslot(ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlotStat)
{
PgStat_EntryRef *entry_ref;
PgStatShared_ReplSlot *shstatent;
- PgStat_StatReplSlotEntry *statent;
+ PgStat_ReplSlotStats *statent;
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_REPLSLOT, InvalidOid,
ReplicationSlotIndex(slot), false);
shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
- statent = &shstatent->stats;
+ statent = &shstatent->stats.decoding_stats;
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 6ea59f44749..6c4b7a26bc8 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2276,16 +2276,16 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
}
values[0] = CStringGetTextDatum(NameStr(slotname));
- values[1] = Int64GetDatum(slotent->spill_txns);
- values[2] = Int64GetDatum(slotent->spill_count);
- values[3] = Int64GetDatum(slotent->spill_bytes);
- values[4] = Int64GetDatum(slotent->stream_txns);
- values[5] = Int64GetDatum(slotent->stream_count);
- values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->output_bytes);
+ values[1] = Int64GetDatum(slotent->decoding_stats.spill_txns);
+ values[2] = Int64GetDatum(slotent->decoding_stats.spill_count);
+ values[3] = Int64GetDatum(slotent->decoding_stats.spill_bytes);
+ values[4] = Int64GetDatum(slotent->decoding_stats.stream_txns);
+ values[5] = Int64GetDatum(slotent->decoding_stats.stream_count);
+ values[6] = Int64GetDatum(slotent->decoding_stats.stream_bytes);
+ values[7] = Int64GetDatum(slotent->decoding_stats.mem_exceeded_count);
+ values[8] = Int64GetDatum(slotent->decoding_stats.total_txns);
+ values[9] = Int64GetDatum(slotent->decoding_stats.total_bytes);
+ values[10] = Int64GetDatum(slotent->decoding_stats.output_bytes);
values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index c90f19b547c..f716872d198 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -15,6 +15,7 @@
#include "portability/instr_time.h"
#include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
#include "replication/conflict.h"
+#include "replication/replslot_stats.h"
#include "storage/locktag.h"
#include "utils/backend_progress.h" /* for backward compatibility */ /* IWYU pragma: export */
#include "utils/backend_status.h" /* for backward compatibility */ /* IWYU pragma: export */
@@ -413,16 +414,7 @@ typedef struct PgStat_StatFuncEntry
typedef struct PgStat_StatReplSlotEntry
{
- PgStat_Counter spill_txns;
- PgStat_Counter spill_count;
- PgStat_Counter spill_bytes;
- PgStat_Counter stream_txns;
- PgStat_Counter stream_count;
- PgStat_Counter stream_bytes;
- PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
- PgStat_Counter output_bytes;
+ PgStat_ReplSlotStats decoding_stats;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
@@ -788,7 +780,7 @@ extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
extern void pgstat_reset_replslot(const char *name);
struct ReplicationSlot;
-extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
+extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlotStat);
extern void pgstat_report_replslotsync(struct ReplicationSlot *slot);
extern void pgstat_create_replslot(struct ReplicationSlot *slot);
extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 79a8afb8006..a6f8cc4d100 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -12,6 +12,7 @@
#include "access/htup_details.h"
#include "lib/ilist.h"
#include "lib/pairingheap.h"
+#include "replication/replslot_stats.h"
#include "storage/sinval.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
@@ -674,32 +675,8 @@ struct ReorderBuffer
/* Max-heap for sizes of all top-level and sub transactions */
pairingheap *txn_heap;
- /*
- * Statistics about transactions spilled to disk.
- *
- * A single transaction may be spilled repeatedly, which is why we keep
- * two different counters. For spilling, the transaction counter includes
- * both toplevel transactions and subtransactions.
- */
- int64 spillTxns; /* number of transactions spilled to disk */
- int64 spillCount; /* spill-to-disk invocation counter */
- int64 spillBytes; /* amount of data spilled to disk */
-
- /* Statistics about transactions streamed to the decoding output plugin */
- int64 streamTxns; /* number of transactions streamed */
- int64 streamCount; /* streaming invocation counter */
- int64 streamBytes; /* amount of data decoded */
-
- /* Number of times the logical_decoding_work_mem limit has been reached */
- int64 memExceededCount;
-
- /*
- * Statistics about all the transactions sent to the decoding output
- * plugin
- */
- int64 totalTxns; /* total number of transactions sent */
- int64 totalBytes; /* total amount of data decoded */
- int64 outputBytes; /* amount of data produced for downstream */
+ /* Replication slot statistics collected by logical decoding. */
+ PgStat_ReplSlotStats stats;
};
diff --git a/src/include/replication/replslot_stats.h b/src/include/replication/replslot_stats.h
new file mode 100644
index 00000000000..a696d912caa
--- /dev/null
+++ b/src/include/replication/replslot_stats.h
@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ *
+ * replslot_stats.h
+ * Replication slot statistics shared definitions.
+ *
+ * Copyright (c) 2026, PostgreSQL Global Development Group
+ *
+ * src/include/replication/replslot_stats.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef REPLSLOT_STATS_H
+#define REPLSLOT_STATS_H
+
+typedef struct PgStat_ReplSlotStats
+{
+ int64 spill_txns;
+ int64 spill_count;
+ int64 spill_bytes;
+ int64 stream_txns;
+ int64 stream_count;
+ int64 stream_bytes;
+ int64 mem_exceeded_count;
+ int64 total_txns;
+ int64 total_bytes;
+ int64 output_bytes;
+} PgStat_ReplSlotStats;
+
+#endif /* REPLSLOT_STATS_H */
\ No newline at end of file
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 117e7379f10..3949f2dc5d0 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2351,6 +2351,7 @@ PgStat_LockEntry
PgStat_PendingDroppedStatsItem
PgStat_PendingIO
PgStat_PendingLock
+PgStat_ReplSlotStats
PgStat_SLRUStats
PgStat_ShmemControl
PgStat_Snapshot
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-07-02 21:49 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-07-03 05:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
@ 2026-08-20 03:01 ` Aditya Gollamudi <adigollamudi@gmail.com>
2026-08-20 12:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-08-24 09:45 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 2 replies; 123+ messages in thread
From: Aditya Gollamudi @ 2026-08-20 03:01 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
On 7/3/26 1:44 AM, Ashutosh Sharma wrote:
> Thank you for your review comments.
>
> I have swapped the patch order - please see attached.
>
> In the refactoring patch, I also ensured that reorderbuffer.h does not
> depend on pgstat.h. To make that possible, I introduced a shared
> header, src/include/replication/replslot_stats.h, where
> PgStat_ReplSlotStats is defined. Both pgstat.h and reorderbuffer.h
> include that header. Hope that helps!
>
> --
> With Regards,
> Ashutosh Sharma.
Hi Ashutosh!
Thanks for the updated patches. I reviewed the latest two as
part of the July patch review workshop:
First, I wasn't able to cleanly apply the refactoring patch against the
current tree. It could be an issue on my end, but it may need to be
checked again.
Secondly, this was mentioned earlier in the thread and handled for
the SQL API path but I believe an excess 25 bytes is still being
counted by output_bytes in the WALsender path because of an
unaccounted for header.
In WalSndPrepareWrite(), we call pq_sendbyte() and pq_sendint64()
twice in order to send some header data. In order to be consistent
with the renaming to "output_bytes" I think that should not
be included. One way this could be fixed is through an offset that
simply accounts for this header data, and subtracts it from output_bytes:
/* OutputPluginPrepareWrite */
ctx->prepare_write(ctx, ctx->write_location, ctx->write_xid, last_write);
ctx->prepared_write_offset = ctx->out->len;
/* OutputPluginWrite */
ctx->reorder->stats.output_bytes += ctx->out->len -
ctx->prepared_write_offset;
Finally, I wonder if the test coverage is sufficient. We only
assert that output_bytes is > 0 and that it is equal to 0 after a reset
happens. Should we also check that it is equal to the expected
number of bytes for the output_plugin?
From what I can tell, in the SQL API path, we know the data comes
from the buffer contents. So maybe additional verification
could do something along the lines of:
length output plugin produced data == output_bytes delta
I'm fairly new to patch reviews and the postgres community
so I'm curious what your thoughts are!
Is the new code I suggested to remove the 25 bytes and potentially
more tests worth it?
Best,
Adi Gollamudi
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-07-02 21:49 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-07-03 05:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-08-20 03:01 ` Re: Report bytes and transactions actually sent downtream Aditya Gollamudi <adigollamudi@gmail.com>
@ 2026-08-20 12:25 ` Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Ashutosh Sharma @ 2026-08-20 12:25 UTC (permalink / raw)
To: Aditya Gollamudi <adigollamudi@gmail.com>; +Cc: Masahiko Sawada <sawada.mshk@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
Thanks for reviewing the patch.
On Thu, Aug 20, 2026 at 8:32 AM Aditya Gollamudi <adigollamudi@gmail.com> wrote:
>
> Hi Ashutosh!
>
> Thanks for the updated patches. I reviewed the latest two as
> part of the July patch review workshop:
>
> First, I wasn't able to cleanly apply the refactoring patch against the
> current tree. It could be an issue on my end, but it may need to be
> checked again.
>
I'll rebase and share the updated patch.
> Secondly, this was mentioned earlier in the thread and handled for
> the SQL API path but I believe an excess 25 bytes is still being
> counted by output_bytes in the WALsender path because of an
> unaccounted for header.
>
> In WalSndPrepareWrite(), we call pq_sendbyte() and pq_sendint64()
> twice in order to send some header data. In order to be consistent
> with the renaming to "output_bytes" I think that should not
> be included. One way this could be fixed is through an offset that
> simply accounts for this header data, and subtracts it from output_bytes:
>
I think the difference is in how output_bytes is interpreted. It is
intended to represent the bytes prepared for the consumer, including
output-writer framing where applicable, rather than only the bytes
produced by the output plugin. Maybe we can clarify this in the
documentation so that it precisely matches the implementation.
Regarding test-cases, I will revisit and see if anything newer can be added.
--
With Regards,
Ashutosh Sharma.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-16 07:50 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 23:21 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 04:18 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Re: Report bytes and transactions actually sent downtream Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 13:53 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-24 23:07 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-28 06:56 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-07-02 21:49 ` Re: Report bytes and transactions actually sent downtream Masahiko Sawada <sawada.mshk@gmail.com>
2026-07-03 05:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-08-20 03:01 ` Re: Report bytes and transactions actually sent downtream Aditya Gollamudi <adigollamudi@gmail.com>
@ 2026-08-24 09:45 ` Ashutosh Sharma <ashu.coek88@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Ashutosh Sharma @ 2026-08-24 09:45 UTC (permalink / raw)
To: Aditya Gollamudi <adigollamudi@gmail.com>; +Cc: Masahiko Sawada <sawada.mshk@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Kyotaro Horiguchi <horikyota.ntt@gmail.com>; michael@paquier.xyz; bertranddrouvot.pg@gmail.com; andres@anarazel.de; shveta.malik@gmail.com; pgsql-hackers
Hi,
On Thu, Aug 20, 2026 at 8:32 AM Aditya Gollamudi <adigollamudi@gmail.com> wrote:
>
>
> Thanks for the updated patches. I reviewed the latest two as
> part of the July patch review workshop:
>
> First, I wasn't able to cleanly apply the refactoring patch against the
> current tree. It could be an issue on my end, but it may need to be
> checked again.
>
You were right, it needed a rebase. Please find the rebased
refactoring patch (0002*.patch) attached.
> Secondly, this was mentioned earlier in the thread and handled for
> the SQL API path but I believe an excess 25 bytes is still being
> counted by output_bytes in the WALsender path because of an
> unaccounted for header.
>
The patch is intended to track the total number of output bytes
produced by the logical decoding output path. This includes the
payload generated by the output plugin and any message header added by
the output writer. In the walsender path, the output writer always
prepends a WALData message header to each payload generated by the
output plugin. Therefore, the header is included because it forms part
of the complete output message passed to libpq for delivery to the
downstream consumer.
I have updated the documentation to clarify this point. Please let me
know if it remains unclear.
> Finally, I wonder if the test coverage is sufficient. We only
> assert that output_bytes is > 0 and that it is equal to 0 after a reset
> happens. Should we also check that it is equal to the expected
> number of bytes for the output_plugin?
>
Yes, it makes sense to add a test case verifying that the number of
bytes produced by the logical decoding output path matches the
output_bytes value recorded in pg_stat_replication_slots. I have added
one of such test-case in the attached 0001 patch.
Please have a look into the attached patches with above changes and
let me know for any other comments/suggestions.
--
With Regards,
Ashutosh Sharma.
Attachments: download all (2 files, .tar.gz)
v20260824-0002-Refactor-replication-slot-decoding-stats-handling.patch (application/octet-stream, 15.2K) download
From 33eb6944f9a30c4a97b19fd5293277d0df906c24 Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Mon, 24 Aug 2026 08:47:04 +0000
Subject: [PATCH 2/2] Refactor replication slot decoding stats handling
Replication slot decoding stats use several related counters.
Previously, ReorderBuffer collected them as separate fields,
while PgStat_StatReplSlotEntry stored the same set again.
UpdateDecodingStats() then had to copy and clear each field by
hand.
Introduce PgStat_ReplSlotStats as the common structure for
these logical decoding counters. Embed it in ReorderBuffer for
collection and in PgStat_StatReplSlotEntry for storage, while
keeping slot synchronization and reset metadata outside it.
With the counters grouped, UpdateDecodingStats() can pass the
collected struct directly to pgstat_report_replslot() and clear
it with a single MemSet(). The pgstat reporting path now
accumulates the shared struct, and pg_stat_get_replication_slot()
reads counters from the nested decoding_stats member.
Keep the shared type in a small replication header, so
reorderbuffer.h does not need to include pgstat.h.
This makes future logical decoding replication slot counters
less error-prone to add by tying collection, reporting, and
reset paths to one shared type.
Per suggestion from Masahiko Sawada
---
src/backend/replication/logical/logical.c | 55 ++++++-------------
.../replication/logical/reorderbuffer.c | 33 ++++-------
src/backend/utils/activity/pgstat_replslot.c | 6 +-
src/backend/utils/adt/pgstatfuncs.c | 20 +++----
src/include/pgstat.h | 14 +----
src/include/replication/reorderbuffer.h | 29 +---------
src/include/replication/replslot_stats.h | 29 ++++++++++
src/tools/pgindent/typedefs.list | 1 +
8 files changed, 78 insertions(+), 109 deletions(-)
create mode 100644 src/include/replication/replslot_stats.h
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index b78f1a70068..eaf628fc446 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -792,7 +792,7 @@ OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
outputBytes = ctx->out->len;
ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
- ctx->reorder->outputBytes += outputBytes;
+ ctx->reorder->stats.output_bytes += outputBytes;
ctx->prepared_write = false;
}
@@ -2045,11 +2045,10 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
- PgStat_StatReplSlotEntry repSlotStat;
/* Nothing to do if we don't have any replication stats to be sent. */
- if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0 &&
- rb->memExceededCount <= 0)
+ if (rb->stats.spill_bytes <= 0 && rb->stats.stream_bytes <= 0 &&
+ rb->stats.total_bytes <= 0 && rb->stats.mem_exceeded_count <= 0)
return;
elog(DEBUG2,
@@ -2060,40 +2059,20 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
" total_txns=%" PRId64 " total_bytes=%" PRId64
" output_bytes=%" PRId64,
rb,
- rb->spillTxns,
- rb->spillCount,
- rb->spillBytes,
- rb->streamTxns,
- rb->streamCount,
- rb->streamBytes,
- rb->memExceededCount,
- rb->totalTxns,
- rb->totalBytes,
- rb->outputBytes);
-
- repSlotStat.spill_txns = rb->spillTxns;
- repSlotStat.spill_count = rb->spillCount;
- repSlotStat.spill_bytes = rb->spillBytes;
- repSlotStat.stream_txns = rb->streamTxns;
- repSlotStat.stream_count = rb->streamCount;
- repSlotStat.stream_bytes = rb->streamBytes;
- repSlotStat.mem_exceeded_count = rb->memExceededCount;
- repSlotStat.total_txns = rb->totalTxns;
- repSlotStat.total_bytes = rb->totalBytes;
- repSlotStat.output_bytes = rb->outputBytes;
-
- pgstat_report_replslot(ctx->slot, &repSlotStat);
-
- rb->spillTxns = 0;
- rb->spillCount = 0;
- rb->spillBytes = 0;
- rb->streamTxns = 0;
- rb->streamCount = 0;
- rb->streamBytes = 0;
- rb->memExceededCount = 0;
- rb->totalTxns = 0;
- rb->totalBytes = 0;
- rb->outputBytes = 0;
+ rb->stats.spill_txns,
+ rb->stats.spill_count,
+ rb->stats.spill_bytes,
+ rb->stats.stream_txns,
+ rb->stats.stream_count,
+ rb->stats.stream_bytes,
+ rb->stats.mem_exceeded_count,
+ rb->stats.total_txns,
+ rb->stats.total_bytes,
+ rb->stats.output_bytes);
+
+ pgstat_report_replslot(ctx->slot, &rb->stats);
+
+ MemSet(&rb->stats, 0, sizeof(PgStat_ReplSlotStats));
}
/*
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index f6c1868a144..596a7992236 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -385,16 +385,7 @@ ReorderBufferAllocate(void)
/* txn_heap is ordered by transaction size */
buffer->txn_heap = pairingheap_allocate(ReorderBufferTXNSizeCompare, NULL);
- buffer->spillTxns = 0;
- buffer->spillCount = 0;
- buffer->spillBytes = 0;
- buffer->streamTxns = 0;
- buffer->streamCount = 0;
- buffer->streamBytes = 0;
- buffer->memExceededCount = 0;
- buffer->totalTxns = 0;
- buffer->totalBytes = 0;
- buffer->outputBytes = 0;
+ MemSet(&buffer->stats, 0, sizeof(PgStat_ReplSlotStats));
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
@@ -1470,7 +1461,7 @@ ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state)
* releasing the current set of changes and restoring the new set of
* changes.
*/
- rb->totalBytes += entry->txn->size;
+ rb->stats.total_bytes += entry->txn->size;
if (ReorderBufferRestoreChanges(rb, entry->txn, &entry->file,
&state->entries[off].segno))
{
@@ -2627,9 +2618,9 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
* which we have already accounted in ReorderBufferIterTXNNext.
*/
if (!rbtxn_is_streamed(txn))
- rb->totalTxns++;
+ rb->stats.total_txns++;
- rb->totalBytes += txn->total_size;
+ rb->stats.total_bytes += txn->total_size;
/*
* Done with current changes, send the last message for this set of
@@ -3939,7 +3930,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
* update the slot statistics altogether while streaming or
* serializing transactions in most cases.
*/
- rb->memExceededCount += 1;
+ rb->stats.mem_exceeded_count += 1;
}
else if (debug_logical_replication_streaming == DEBUG_LOGICAL_REP_STREAMING_BUFFERED)
{
@@ -4010,7 +4001,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
Assert(txn->nentries_mem == 0);
/*
- * We've reported the memExceededCount update while streaming or
+ * We've reported the mem_exceeded_count update while streaming or
* serializing the transaction.
*/
update_stats = false;
@@ -4099,11 +4090,11 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
/* update the statistics iff we have spilled anything */
if (spilled)
{
- rb->spillCount += 1;
- rb->spillBytes += size;
+ rb->stats.spill_count += 1;
+ rb->stats.spill_bytes += size;
/* don't consider already serialized transactions */
- rb->spillTxns += (rbtxn_is_serialized(txn) || rbtxn_is_serialized_clear(txn)) ? 0 : 1;
+ rb->stats.spill_txns += (rbtxn_is_serialized(txn) || rbtxn_is_serialized_clear(txn)) ? 0 : 1;
/* update the decoding stats */
UpdateDecodingStats((LogicalDecodingContext *) rb->private_data);
@@ -4471,11 +4462,11 @@ ReorderBufferStreamTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
ReorderBufferProcessTXN(rb, txn, InvalidXLogRecPtr, snapshot_now,
command_id, true);
- rb->streamCount += 1;
- rb->streamBytes += stream_bytes;
+ rb->stats.stream_count += 1;
+ rb->stats.stream_bytes += stream_bytes;
/* Don't consider already streamed transaction. */
- rb->streamTxns += (txn_is_streamed) ? 0 : 1;
+ rb->stats.stream_txns += (txn_is_streamed) ? 0 : 1;
/* update the decoding stats */
UpdateDecodingStats((LogicalDecodingContext *) rb->private_data);
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index d5ffc1a7f36..9e42d05c70b 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -74,16 +74,16 @@ pgstat_reset_replslot(const char *name)
* pgstat_acquire_replslot() have already been called.
*/
void
-pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
+pgstat_report_replslot(ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlotStat)
{
PgStat_EntryRef *entry_ref;
PgStatShared_ReplSlot *shstatent;
- PgStat_StatReplSlotEntry *statent;
+ PgStat_ReplSlotStats *statent;
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_REPLSLOT, InvalidOid,
ReplicationSlotIndex(slot), false);
shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
- statent = &shstatent->stats;
+ statent = &shstatent->stats.decoding_stats;
/* Update the replication slot statistics */
#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 028e67f1c85..98cfc9d6968 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2385,16 +2385,16 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
}
values[0] = CStringGetTextDatum(NameStr(slotname));
- values[1] = Int64GetDatum(slotent->spill_txns);
- values[2] = Int64GetDatum(slotent->spill_count);
- values[3] = Int64GetDatum(slotent->spill_bytes);
- values[4] = Int64GetDatum(slotent->stream_txns);
- values[5] = Int64GetDatum(slotent->stream_count);
- values[6] = Int64GetDatum(slotent->stream_bytes);
- values[7] = Int64GetDatum(slotent->mem_exceeded_count);
- values[8] = Int64GetDatum(slotent->total_txns);
- values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->output_bytes);
+ values[1] = Int64GetDatum(slotent->decoding_stats.spill_txns);
+ values[2] = Int64GetDatum(slotent->decoding_stats.spill_count);
+ values[3] = Int64GetDatum(slotent->decoding_stats.spill_bytes);
+ values[4] = Int64GetDatum(slotent->decoding_stats.stream_txns);
+ values[5] = Int64GetDatum(slotent->decoding_stats.stream_count);
+ values[6] = Int64GetDatum(slotent->decoding_stats.stream_bytes);
+ values[7] = Int64GetDatum(slotent->decoding_stats.mem_exceeded_count);
+ values[8] = Int64GetDatum(slotent->decoding_stats.total_txns);
+ values[9] = Int64GetDatum(slotent->decoding_stats.total_bytes);
+ values[10] = Int64GetDatum(slotent->decoding_stats.output_bytes);
values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index b1ec02918b2..5a21f5abea9 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -15,6 +15,7 @@
#include "portability/instr_time.h"
#include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
#include "replication/conflict.h"
+#include "replication/replslot_stats.h"
#include "storage/locktag.h"
#include "utils/backend_progress.h" /* for backward compatibility */ /* IWYU pragma: export */
#include "utils/backend_status.h" /* for backward compatibility */ /* IWYU pragma: export */
@@ -446,16 +447,7 @@ typedef struct PgStat_StatFuncEntry
typedef struct PgStat_StatReplSlotEntry
{
- PgStat_Counter spill_txns;
- PgStat_Counter spill_count;
- PgStat_Counter spill_bytes;
- PgStat_Counter stream_txns;
- PgStat_Counter stream_count;
- PgStat_Counter stream_bytes;
- PgStat_Counter mem_exceeded_count;
- PgStat_Counter total_txns;
- PgStat_Counter total_bytes;
- PgStat_Counter output_bytes;
+ PgStat_ReplSlotStats decoding_stats;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
@@ -868,7 +860,7 @@ extern PgStat_StatIdxEntry *pgstat_fetch_stat_idxentry_ext(bool shared,
extern void pgstat_reset_replslot(const char *name);
struct ReplicationSlot;
-extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
+extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_ReplSlotStats *repSlotStat);
extern void pgstat_report_replslotsync(struct ReplicationSlot *slot);
extern void pgstat_create_replslot(struct ReplicationSlot *slot);
extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index 79a8afb8006..a6f8cc4d100 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -12,6 +12,7 @@
#include "access/htup_details.h"
#include "lib/ilist.h"
#include "lib/pairingheap.h"
+#include "replication/replslot_stats.h"
#include "storage/sinval.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
@@ -674,32 +675,8 @@ struct ReorderBuffer
/* Max-heap for sizes of all top-level and sub transactions */
pairingheap *txn_heap;
- /*
- * Statistics about transactions spilled to disk.
- *
- * A single transaction may be spilled repeatedly, which is why we keep
- * two different counters. For spilling, the transaction counter includes
- * both toplevel transactions and subtransactions.
- */
- int64 spillTxns; /* number of transactions spilled to disk */
- int64 spillCount; /* spill-to-disk invocation counter */
- int64 spillBytes; /* amount of data spilled to disk */
-
- /* Statistics about transactions streamed to the decoding output plugin */
- int64 streamTxns; /* number of transactions streamed */
- int64 streamCount; /* streaming invocation counter */
- int64 streamBytes; /* amount of data decoded */
-
- /* Number of times the logical_decoding_work_mem limit has been reached */
- int64 memExceededCount;
-
- /*
- * Statistics about all the transactions sent to the decoding output
- * plugin
- */
- int64 totalTxns; /* total number of transactions sent */
- int64 totalBytes; /* total amount of data decoded */
- int64 outputBytes; /* amount of data produced for downstream */
+ /* Replication slot statistics collected by logical decoding. */
+ PgStat_ReplSlotStats stats;
};
diff --git a/src/include/replication/replslot_stats.h b/src/include/replication/replslot_stats.h
new file mode 100644
index 00000000000..a696d912caa
--- /dev/null
+++ b/src/include/replication/replslot_stats.h
@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ *
+ * replslot_stats.h
+ * Replication slot statistics shared definitions.
+ *
+ * Copyright (c) 2026, PostgreSQL Global Development Group
+ *
+ * src/include/replication/replslot_stats.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef REPLSLOT_STATS_H
+#define REPLSLOT_STATS_H
+
+typedef struct PgStat_ReplSlotStats
+{
+ int64 spill_txns;
+ int64 spill_count;
+ int64 spill_bytes;
+ int64 stream_txns;
+ int64 stream_count;
+ int64 stream_bytes;
+ int64 mem_exceeded_count;
+ int64 total_txns;
+ int64 total_bytes;
+ int64 output_bytes;
+} PgStat_ReplSlotStats;
+
+#endif /* REPLSLOT_STATS_H */
\ No newline at end of file
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 6c366d3a523..74c7b3c1420 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2356,6 +2356,7 @@ PgStat_PendingDroppedStatsItem
PgStat_PendingIO
PgStat_PendingLock
PgStat_RelationStatus
+PgStat_ReplSlotStats
PgStat_SLRUStats
PgStat_ShmemControl
PgStat_Snapshot
--
2.43.0
v20260824-0001-Report-output-bytes-in-pg_stat_replication_slots.patch (application/octet-stream, 27.9K) download
From 108ef6ed02f675399c0bf1ab8e145ae0845cae1c Mon Sep 17 00:00:00 2001
From: Ashutosh Sharma <ashu.coek88@gmail.com>
Date: Mon, 24 Aug 2026 07:03:15 +0000
Subject: [PATCH 1/2] Report output bytes in pg_stat_replication_slots
pg_stat_replication_slots currently tracks bytes added to the reorder
buffer, but it does not track bytes produced for downstream consumers.
Add output_bytes to report those bytes, including the payload generated
by the output plugin and any message header added by the output writer.
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Ashutosh Sharma <ashu.coek88@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Aditya Gollamudi <adigollamudi@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/CAExHW5s6KntzUyUoMbKR5dgwRmdV2Ay_2+AnTgYGAzo=Qv61wA@mail.gmail.com
---
contrib/test_decoding/expected/stats.out | 77 +++++++++----------
contrib/test_decoding/sql/stats.sql | 21 +++--
contrib/test_decoding/t/001_repl_stats.pl | 13 ++--
doc/src/sgml/monitoring.sgml | 25 ++++++
src/backend/catalog/system_views.sql | 1 +
src/backend/replication/logical/logical.c | 18 ++++-
.../replication/logical/reorderbuffer.c | 1 +
src/backend/utils/activity/pgstat_replslot.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 21 ++---
src/include/catalog/pg_proc.dat | 6 +-
src/include/pgstat.h | 1 +
src/include/replication/reorderbuffer.h | 1 +
src/test/recovery/t/006_logical_decoding.pl | 12 +--
src/test/regress/expected/rules.out | 3 +-
14 files changed, 126 insertions(+), 75 deletions(-)
diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out
index a9ead3c41aa..4249b5cc577 100644
--- a/contrib/test_decoding/expected/stats.out
+++ b/contrib/test_decoding/expected/stats.out
@@ -13,36 +13,29 @@ CREATE TABLE stats_test(data text);
-- non-spilled xact
SET logical_decoding_work_mem to '64MB';
INSERT INTO stats_test values(1);
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
- count
--------
- 3
-(1 row)
-
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
- count
--------
- 3
-(1 row)
-
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
- count
--------
- 3
-(1 row)
-
+-- The SQL output writer adds no header, so the returned payload is the exact
+-- number of output bytes.
+CREATE TEMP TABLE expected_output_bytes AS
+SELECT 'regression_slot_stats1' AS slot_name, sum(octet_length(data)) AS output_bytes
+FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
+INSERT INTO expected_output_bytes
+SELECT 'regression_slot_stats2', sum(octet_length(data))
+FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
+INSERT INTO expected_output_bytes
+SELECT 'regression_slot_stats3', sum(octet_length(data))
+FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
pg_stat_force_next_flush
--------------------------
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | t | t | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT s.slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, s.output_bytes = e.output_bytes AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots s JOIN expected_output_bytes e USING (slot_name) ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | t | t | t | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
RESET logical_decoding_work_mem;
@@ -53,12 +46,12 @@ SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | t | t | t
- regression_slot_stats3 | t | t | t | t | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | f | t
+ regression_slot_stats2 | t | t | t | t | t | t
+ regression_slot_stats3 | t | t | t | t | t | t
(3 rows)
-- reset stats for all slots
@@ -68,27 +61,27 @@ SELECT pg_stat_reset_replication_slot(NULL);
(1 row)
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
- slot_name | spill_txns | spill_count | total_txns | total_bytes | mem_exceeded_count
-------------------------+------------+-------------+------------+-------------+--------------------
- regression_slot_stats1 | t | t | f | f | t
- regression_slot_stats2 | t | t | f | f | t
- regression_slot_stats3 | t | t | f | f | t
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+ slot_name | spill_txns | spill_count | total_txns | total_bytes | output_bytes | mem_exceeded_count
+------------------------+------------+-------------+------------+-------------+--------------+--------------------
+ regression_slot_stats1 | t | t | f | f | 0 | t
+ regression_slot_stats2 | t | t | f | f | 0 | t
+ regression_slot_stats3 | t | t | f | f | 0 | t
(3 rows)
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
SELECT pg_stat_reset_replication_slot('do-not-exist');
ERROR: replication slot "do-not-exist" does not exist
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
- slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
---------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+---------------------+--------------------+-------------
- do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
+ slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | mem_exceeded_count | total_txns | total_bytes | output_bytes | slotsync_skip_count | slotsync_last_skip | stats_reset
+--------------+------------+-------------+-------------+-------------+--------------+--------------+--------------------+------------+-------------+--------------+---------------------+--------------------+-------------
+ do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
(1 row)
-- spilling the xact
diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql
index 6661dbcb85c..3c02400a5f6 100644
--- a/contrib/test_decoding/sql/stats.sql
+++ b/contrib/test_decoding/sql/stats.sql
@@ -11,20 +11,29 @@ CREATE TABLE stats_test(data text);
-- non-spilled xact
SET logical_decoding_work_mem to '64MB';
INSERT INTO stats_test values(1);
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
+-- The SQL output writer adds no header, so the returned payload is the exact
+-- number of output bytes.
+CREATE TEMP TABLE expected_output_bytes AS
+SELECT 'regression_slot_stats1' AS slot_name, sum(octet_length(data)) AS output_bytes
+FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
+INSERT INTO expected_output_bytes
+SELECT 'regression_slot_stats2', sum(octet_length(data))
+FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
+INSERT INTO expected_output_bytes
+SELECT 'regression_slot_stats3', sum(octet_length(data))
+FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
SELECT pg_stat_force_next_flush();
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+
+SELECT s.slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, s.output_bytes = e.output_bytes AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots s JOIN expected_output_bytes e USING (slot_name) ORDER BY slot_name;
RESET logical_decoding_work_mem;
-- reset stats for one slot, others should be unaffected
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes > 0 AS output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- reset stats for all slots
SELECT pg_stat_reset_replication_slot(NULL);
-SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
+SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes, output_bytes, mem_exceeded_count = 0 AS mem_exceeded_count FROM pg_stat_replication_slots ORDER BY slot_name;
-- verify accessing/resetting stats for non-existent slot does something reasonable
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
diff --git a/contrib/test_decoding/t/001_repl_stats.pl b/contrib/test_decoding/t/001_repl_stats.pl
index 6814c792e2b..f081cf8417a 100644
--- a/contrib/test_decoding/t/001_repl_stats.pl
+++ b/contrib/test_decoding/t/001_repl_stats.pl
@@ -26,7 +26,8 @@ sub test_slot_stats
my $result = $node->safe_psql(
'postgres', qq[
SELECT slot_name, total_txns > 0 AS total_txn,
- total_bytes > 0 AS total_bytes
+ total_bytes > 0 AS total_bytes,
+ output_bytes > 0 AS output_bytes
FROM pg_stat_replication_slots
ORDER BY slot_name]);
is($result, $expected, $msg);
@@ -80,9 +81,9 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t
-regression_slot3|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t
+regression_slot3|t|t|t),
'check replication statistics are updated');
# Test to remove one of the replication slots and adjust
@@ -104,8 +105,8 @@ $node->start;
# restart.
test_slot_stats(
$node,
- qq(regression_slot1|t|t
-regression_slot2|t|t),
+ qq(regression_slot1|t|t|t
+regression_slot2|t|t|t),
'check replication statistics after removing the slot file');
# cleanup
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 32cb6fdbd76..9641fe4f9a7 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1857,6 +1857,31 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>output_bytes</structfield><type>bigint</type>
+ </para>
+ <para>
+ Amount of decoded data produced for this slot's consumer, including
+ the output writer's message header and the data produced by the output
+ plugin after applying any output plugin filters and converting the
+ changes into the output plugin's format. This counts the transaction
+ changes together with the messages that delimit them (such as the
+ begin and commit messages), but not connection-management messages
+ such as keepalives, which are generated by the server rather than the
+ output plugin and are therefore not included.
+ </para>
+ <para>
+ This value can differ from <structfield>total_bytes</structfield>: it
+ may be smaller because filtered changes are not output, or larger
+ because the output plugin's format can be more verbose than the
+ decoded changes. For these reasons
+ <structfield>output_bytes</structfield> is not directly comparable to
+ <structfield>total_bytes</structfield>.
+ </para>
+ </entry>
+ </row>
+
<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>slotsync_skip_count</structfield><type>bigint</type>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8612d99a890..705e3069cb6 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1139,6 +1139,7 @@ CREATE VIEW pg_stat_replication_slots AS
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 98e5f1dd8f9..b78f1a70068 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -784,10 +784,15 @@ OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
void
OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
{
+ int64 outputBytes;
+
if (!ctx->prepared_write)
elog(ERROR, "OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
+ outputBytes = ctx->out->len;
+
ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
+ ctx->reorder->outputBytes += outputBytes;
ctx->prepared_write = false;
}
@@ -2047,7 +2052,13 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount <= 0)
return;
- elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+ elog(DEBUG2,
+ "UpdateDecodingStats: updating stats %p spill_txns=%" PRId64
+ " spill_count=%" PRId64 " spill_bytes=%" PRId64
+ " stream_txns=%" PRId64 " stream_count=%" PRId64
+ " stream_bytes=%" PRId64 " mem_exceeded_count=%" PRId64
+ " total_txns=%" PRId64 " total_bytes=%" PRId64
+ " output_bytes=%" PRId64,
rb,
rb->spillTxns,
rb->spillCount,
@@ -2057,7 +2068,8 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->streamBytes,
rb->memExceededCount,
rb->totalTxns,
- rb->totalBytes);
+ rb->totalBytes,
+ rb->outputBytes);
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
@@ -2068,6 +2080,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
repSlotStat.mem_exceeded_count = rb->memExceededCount;
repSlotStat.total_txns = rb->totalTxns;
repSlotStat.total_bytes = rb->totalBytes;
+ repSlotStat.output_bytes = rb->outputBytes;
pgstat_report_replslot(ctx->slot, &repSlotStat);
@@ -2080,6 +2093,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
rb->memExceededCount = 0;
rb->totalTxns = 0;
rb->totalBytes = 0;
+ rb->outputBytes = 0;
}
/*
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 900864afc6d..f6c1868a144 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -394,6 +394,7 @@ ReorderBufferAllocate(void)
buffer->memExceededCount = 0;
buffer->totalTxns = 0;
buffer->totalBytes = 0;
+ buffer->outputBytes = 0;
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index a32b70a0373..d5ffc1a7f36 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -96,6 +96,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re
REPLSLOT_ACC(mem_exceeded_count);
REPLSLOT_ACC(total_txns);
REPLSLOT_ACC(total_bytes);
+ REPLSLOT_ACC(output_bytes);
#undef REPLSLOT_ACC
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 0d47d745c18..028e67f1c85 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2330,7 +2330,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
{
-#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
+#define PG_STAT_GET_REPLICATION_SLOT_COLS 14
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
@@ -2361,11 +2361,13 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "output_bytes",
INT8OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_count",
+ INT8OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 13, "slotsync_last_skip",
TIMESTAMPTZOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 14, "stats_reset",
TIMESTAMPTZOID, -1, 0);
TupleDescFinalize(tupdesc);
BlessTupleDesc(tupdesc);
@@ -2392,17 +2394,18 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
values[7] = Int64GetDatum(slotent->mem_exceeded_count);
values[8] = Int64GetDatum(slotent->total_txns);
values[9] = Int64GetDatum(slotent->total_bytes);
- values[10] = Int64GetDatum(slotent->slotsync_skip_count);
+ values[10] = Int64GetDatum(slotent->output_bytes);
+ values[11] = Int64GetDatum(slotent->slotsync_skip_count);
if (slotent->slotsync_last_skip == 0)
- nulls[11] = true;
+ nulls[12] = true;
else
- values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
+ values[12] = TimestampTzGetDatum(slotent->slotsync_last_skip);
if (slotent->stat_reset_timestamp == 0)
- nulls[12] = true;
+ nulls[13] = true;
else
- values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
+ values[13] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 1d2a9db3262..5c9d0a60410 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5732,9 +5732,9 @@
{ oid => '6169', descr => 'statistics: information about replication slot',
proname => 'pg_stat_get_replication_slot', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => 'text',
- proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
- proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
+ proallargtypes => '{text,text,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz,timestamptz}',
+ proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,mem_exceeded_count,total_txns,total_bytes,output_bytes,slotsync_skip_count,slotsync_last_skip,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
{ oid => '6230', descr => 'statistics: check if a stats object exists',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 204782fd630..b1ec02918b2 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -455,6 +455,7 @@ typedef struct PgStat_StatReplSlotEntry
PgStat_Counter mem_exceeded_count;
PgStat_Counter total_txns;
PgStat_Counter total_bytes;
+ PgStat_Counter output_bytes;
PgStat_Counter slotsync_skip_count;
TimestampTz slotsync_last_skip;
TimestampTz stat_reset_timestamp;
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index ff825e4b7b2..79a8afb8006 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -699,6 +699,7 @@ struct ReorderBuffer
*/
int64 totalTxns; /* total number of transactions sent */
int64 totalBytes; /* total amount of data decoded */
+ int64 outputBytes; /* amount of data produced for downstream */
};
diff --git a/src/test/recovery/t/006_logical_decoding.pl b/src/test/recovery/t/006_logical_decoding.pl
index 97d11f98b59..812bdd2b9ed 100644
--- a/src/test/recovery/t/006_logical_decoding.pl
+++ b/src/test/recovery/t/006_logical_decoding.pl
@@ -214,10 +214,10 @@ my $stats_test_slot2 = 'logical_slot';
# Stats exist for stats test slot 1
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT total_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT total_bytes > 0, output_bytes > 0, stats_reset IS NULL FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Total bytes is > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
+ qq(t|t|t),
+ qq(Total bytes and sent bytes are both > 0 and stats_reset is NULL for slot '$stats_test_slot1'.)
);
# Do reset of stats for stats test slot 1
@@ -235,10 +235,10 @@ $node_primary->safe_psql('postgres',
is( $node_primary->safe_psql(
'postgres',
- qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
+ qq(SELECT stats_reset > '$reset1'::timestamptz, total_bytes = 0, output_bytes = 0 FROM pg_stat_replication_slots WHERE slot_name = '$stats_test_slot1')
),
- qq(t|t),
- qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes was set to 0.)
+ qq(t|t|t),
+ qq(Check that reset timestamp is later after the second reset of stats for slot '$stats_test_slot1' and confirm total_bytes and output_bytes were set to 0.)
);
# Check that test slot 2 has NULL in reset timestamp
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 1a29d46213e..4ef156b7b8a 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2271,11 +2271,12 @@ pg_stat_replication_slots| SELECT s.slot_name,
s.mem_exceeded_count,
s.total_txns,
s.total_bytes,
+ s.output_bytes,
s.slotsync_skip_count,
s.slotsync_last_skip,
s.stats_reset
FROM pg_replication_slots r,
- LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
+ LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, output_bytes, slotsync_skip_count, slotsync_last_skip, stats_reset)
WHERE (r.datoid IS NOT NULL);
pg_stat_slru| SELECT name,
blks_zeroed,
--
2.43.0
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-27 10:20 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Re: Report bytes and transactions actually sent downtream Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Re: Report bytes and transactions actually sent downtream Michael Paquier <michael@paquier.xyz>
@ 2026-03-14 10:01 ` Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: Amit Kapila @ 2026-03-14 10:01 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Andres Freund <andres@anarazel.de>; shveta malik <shveta.malik@gmail.com>; pgsql-hackers
On Fri, Mar 13, 2026 at 7:39 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Thu, Mar 12, 2026 at 06:13:33PM +0530, Ashutosh Sharma wrote:
> > Could you please share your thoughts on this? Your inputs would help
> > us determine the next steps - whether we should proceed with renaming,
> > and if so, what names you would suggest, or whether we should leave
> > things as they are.
>
> FWIW, I still find the use of _wal_ in these fields rather confusing,
> and they add more inconsistencies with the internal structures of
> reorderbuffer.c. The goal is to add a field to track the number of
> bytes sent downstream. Hence, I would suggest to give up on the
> rename, add the new field, perhaps consider improving the docs for the
> existing fields to tell to which context these numbers refer to, then
> call it a day.
>
+1.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 123+ messages in thread
* Re: Report bytes and transactions actually sent downtream
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Re: Report bytes and transactions actually sent downtream Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Re: Report bytes and transactions actually sent downtream Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` Re: Report bytes and transactions actually sent downtream shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Re: Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
@ 2025-09-25 03:59 ` shveta malik <shveta.malik@gmail.com>
1 sibling, 0 replies; 123+ messages in thread
From: shveta malik @ 2025-09-25 03:59 UTC (permalink / raw)
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers; shveta malik <shveta.malik@gmail.com>
On Wed, Sep 24, 2025 at 5:28 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> On Wed, Sep 24, 2025 at 2:38 PM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > On Wed, Sep 24, 2025 at 12:47 PM Ashutosh Bapat
> > <ashutosh.bapat.oss@gmail.com> wrote:
> > >
> > > On Wed, Sep 24, 2025 at 10:12 AM shveta malik <shveta.malik@gmail.com> wrote:
> > > >
> > > > I tested the flows with
> > > > a) logical replication slot and get-changes.
> > > > b) filtered data flows: pub-sub creation with row_filters, 'publish'
> > > > options. I tried to verify plugin fields as compared to total_wal*
> > > > fields.
> > > > c) reset flow.
> > > >
> > > > While tests for a and c are present already. I don't see tests for b
> > > > anywhere when it comes to stats. Do you think we shall add a test for
> > > > filtered data using row-filter somewhere?
> > >
> > > Added a test in 028_row_filter. Please find it in the attached
> > > patchset.
> >
> > Test looks good.
>
> Thanks. Added to three more files. I think we have covered all the
> cases where filtering can occur.
>
Yes. The test looks good now.
thanks
Shveta
^ permalink raw reply [nested|flat] 123+ messages in thread
end of thread, other threads:[~2026-08-24 09:45 UTC | newest]
Thread overview: 123+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-06-30 09:53 Report bytes and transactions actually sent downtream Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-01 10:52 ` Amit Kapila <amit.kapila16@gmail.com>
2025-07-01 14:05 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-13 11:04 ` Amit Kapila <amit.kapila16@gmail.com>
2025-07-14 05:24 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-07-14 10:00 ` Amit Kapila <amit.kapila16@gmail.com>
2025-07-24 06:54 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-08-27 13:43 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-18 05:21 ` shveta malik <shveta.malik@gmail.com>
2025-09-18 10:24 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-19 06:18 ` shveta malik <shveta.malik@gmail.com>
2025-09-19 14:41 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-22 05:14 ` shveta malik <shveta.malik@gmail.com>
2025-09-23 10:36 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 04:42 ` shveta malik <shveta.malik@gmail.com>
2025-09-23 06:44 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-23 10:45 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 07:02 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:21 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 08:25 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 10:07 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 13:13 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:23 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-23 12:58 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2025-09-24 05:38 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 06:08 ` shveta malik <shveta.malik@gmail.com>
2025-09-24 06:42 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-24 07:17 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 09:07 ` shveta malik <shveta.malik@gmail.com>
2025-09-24 11:58 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-24 14:41 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-25 04:46 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-25 13:01 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 11:13 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-26 12:44 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-26 16:58 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-09-29 07:24 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-09-30 06:52 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-03 06:52 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-03 13:47 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-06 05:02 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-24 09:53 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-24 12:40 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-27 10:20 ` shveta malik <shveta.malik@gmail.com>
2025-10-27 11:17 ` shveta malik <shveta.malik@gmail.com>
2025-10-28 07:15 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-29 03:43 ` shveta malik <shveta.malik@gmail.com>
2025-10-29 14:55 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-10-30 03:38 ` shveta malik <shveta.malik@gmail.com>
2025-11-03 06:53 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 09:54 ` shveta malik <shveta.malik@gmail.com>
2025-11-03 14:23 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-03 15:20 ` Andres Freund <andres@anarazel.de>
2025-11-04 10:58 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 09:54 ` Amit Kapila <amit.kapila16@gmail.com>
2025-11-18 10:35 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-11-18 10:44 ` Amit Kapila <amit.kapila16@gmail.com>
2025-12-11 04:59 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-11 09:38 ` Chao Li <li.evan.chao@gmail.com>
2025-12-17 05:55 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 02:25 ` Chao Li <li.evan.chao@gmail.com>
2025-12-18 12:52 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-19 01:53 ` Chao Li <li.evan.chao@gmail.com>
2025-12-19 08:53 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-17 08:42 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-18 12:52 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-18 18:22 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-12-19 07:02 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2025-12-19 07:51 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-01-12 05:11 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-01-27 17:38 ` Andres Freund <andres@anarazel.de>
2026-02-02 08:36 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-10 13:38 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-02-10 15:40 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-02-13 05:17 ` Michael Paquier <michael@paquier.xyz>
2026-02-13 12:58 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-12 12:43 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-13 02:09 ` Michael Paquier <michael@paquier.xyz>
2026-03-13 05:09 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-15 22:16 ` Michael Paquier <michael@paquier.xyz>
2026-03-16 03:25 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 06:50 ` Michael Paquier <michael@paquier.xyz>
2026-03-16 07:03 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 07:50 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-16 11:10 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 11:54 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-16 13:48 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-17 04:45 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 06:02 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-17 06:42 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 08:40 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-16 23:21 ` Michael Paquier <michael@paquier.xyz>
2026-03-17 05:02 ` Amit Kapila <amit.kapila16@gmail.com>
2026-03-17 05:25 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-03-18 02:38 ` Michael Paquier <michael@paquier.xyz>
2026-03-18 04:28 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-25 06:55 ` Michael Paquier <michael@paquier.xyz>
2026-06-11 08:17 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-12 06:59 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-12 08:36 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 04:18 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 06:19 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 08:22 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-15 09:04 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-06-15 09:16 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-15 13:53 ` Amit Kapila <amit.kapila16@gmail.com>
2026-06-16 09:05 ` Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
2026-06-16 11:25 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-22 11:54 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-24 23:07 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-25 07:31 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-28 06:56 ` Amit Kapila <amit.kapila16@gmail.com>
2026-06-29 09:08 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-29 23:01 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-06-30 07:01 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-06-30 12:39 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-07-02 21:49 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-07-03 05:44 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-08-20 03:01 ` Aditya Gollamudi <adigollamudi@gmail.com>
2026-08-20 12:25 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-08-24 09:45 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2026-03-14 10:01 ` Amit Kapila <amit.kapila16@gmail.com>
2025-09-25 03:59 ` shveta malik <shveta.malik@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox