Re: Add memory_limit_hits to pg_stat_replication_slots

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add memory_limit_hits to pg_stat_replication_slots
Date: 2025-10-03 16:26:28
Message-ID: CAExHW5uqhL8GymznMnu8xkJW4_dvOyfdu+erBHVkvqaA214t=w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 3, 2025 at 6:45 PM Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-10-03 16:42:31 Re: Add memory_limit_hits to pg_stat_replication_slots
Previous Message Andrew Dunstan 2025-10-03 15:47:21 Re: split func.sgml to separated individual sgml files