Add aborted_txns and aborted_bytes to pg_stat_replication_slots

From: Rajesh Kumar Thandapani <rajeshkumarth(at)google(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Add aborted_txns and aborted_bytes to pg_stat_replication_slots
Date: 2026-12-01 15:24:13
Message-ID: CAJoZ81syOn8p7ZkCPcSGkW3FGGXPXsd0XTpoY89rB5EK=a_rxg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

Logical decoding has to read and buffer WAL changes for in-progress
transactions before knowing whether they will commit or abort. Right now
pg_stat_replication_slots only reports transactions sent to the output
plugin (total_txns and total_bytes), so aborted transactions are invisible.
With commit 072ee847ad4 discarding already-aborted transactions at
logical_decoding_work_mem and commit d3b6183dd98 adding mem_exceeded_count,
users can see mem_exceeded_count going up while spill_txns, stream_txns,
and total_txns stay at zero, or see spill and stream counters inflated by
transactions that later rolled back.

Attached is a v1 patch that adds aborted_txns and aborted_bytes to
pg_stat_replication_slots (and pg_stat_get_replication_slot). It tracks
decoded changes for transactions that roll back normally, abort at
logical_decoding_work_mem, abort concurrently during streaming or prepare,
roll back via ROLLBACK PREPARED, or are cleaned up after a crash via
ReorderBufferAbortOld.

A couple of design choices I would appreciate feedback on:

1. aborted_txns counts both top-level transactions and subtransactions
(matching spill_txns), since rolled-back savepoints inside a committed
transaction also do decoding work. Let me know if people prefer counting
top-level transactions only (like total_txns).

2. aborted_bytes currently counts only streamable DML and message changes
(excluding internal snapshot and invalidation changes) so that empty
transactions receiving distributed snapshots are not counted. This does
mean pure-DDL aborts are excluded, and aborted_bytes can be slightly
smaller than spill_bytes if a transaction mixed DDL and DML. Happy to
adjust if folks prefer counting all non-snapshot queued changes instead.

3. Aborts encountered before reaching a consistent snapshot or
start_decoding_at are skipped so slot creation and restarts do not pollute
or re-count stats.

The patch includes docs and tests in contrib/test_decoding (including
persistence across restart in 001_repl_stats.pl) and passes make check and
contrib/test_decoding checks.

Feedback and review comments are welcome.

Regards,
Rajesh Kumar Thandapani

Attachment Content-Type Size
v1-0001-Add-aborted_txns-and-aborted_bytes-to-pg_stat_rep.patch application/x-patch 46.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Burd 2026-12-01 15:27:09 Re: nbtree: opt-in leaf key prefix compression
Previous Message Nathan Bossart 2026-12-01 15:09:25 Re: Should we add timing output to pg_upgrade?