Re: Add memory_limit_hits to pg_stat_replication_slots - Mailing list pgsql-hackers

From Ashutosh Bapat
Subject Re: Add memory_limit_hits to pg_stat_replication_slots
Date
Msg-id CAExHW5uqhL8GymznMnu8xkJW4_dvOyfdu+erBHVkvqaA214t=w@mail.gmail.com
Whole thread Raw
In response to Re: Add memory_limit_hits to pg_stat_replication_slots  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: Add memory_limit_hits to pg_stat_replication_slots
List pgsql-hackers
On Fri, Oct 3, 2025 at 6:45 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:
>
> Hi,
>
> On Fri, Oct 03, 2025 at 05:19:42PM +0530, Ashutosh Bapat wrote:
> > + bool memory_limit_reached = (rb->size >= logical_decoding_work_mem *
> > (Size) 1024);
> > +
> > + if (memory_limit_reached)
> > + rb->memExceededCount += 1;
>
> Thanks for looking at it!
>
> > If the memory limit is hit but no transaction was serialized, the
> > stats won't be updated since UpdateDecodingStats() won't be called. We
> > need to call UpdateDecodingStats() in ReorderBufferCheckMemoryLimit()
> > if no transaction was streamed or spilled.
>
> I did some testing and the stats are reported because UpdateDecodingStats() is
> also called in DecodeCommit(), DecodeAbort() and DecodePrepare() (in addition
> to ReorderBufferSerializeTXN() and ReorderBufferStreamTXN()). That's also why
> ,for example, total_txns is reported even if no transaction was streamed or
> spilled.

In a very pathological case, where all transactions happen to be
aborted while decoding and yet memory limit is hit many times, nothing
will be reported till first committed transaction after it is decoded.
Which may never happen. I didn't find a call stack where by
UpdateDecodingStats could be reached from
ReorderBufferCheckAndTruncateAbortedTXN().


--
Best Wishes,
Ashutosh Bapat



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: split func.sgml to separated individual sgml files
Next
From: Masahiko Sawada
Date:
Subject: Re: Add memory_limit_hits to pg_stat_replication_slots