Re: Add memory_limit_hits to pg_stat_replication_slots

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Bertrand Drouvot <bertranddrouvot(dot)pg(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 11:49:42
Message-ID: CAExHW5tLswoF6U8JPnnV0_k0qfMgz6eFL7Ff06E+Rf9KJQneYQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 3, 2025 at 5:10 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> On Thu, Sep 25, 2025 at 10:26 PM Bertrand Drouvot
> <bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
> >
> > Hi,
> >
> > On Thu, Sep 25, 2025 at 12:14:04PM -0700, Masahiko Sawada wrote:
> > > On Thu, Sep 25, 2025 at 3:17 AM Bertrand Drouvot
> > > <bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
> > > >
> > > > That probably means that mem_exceeded_count would need to be increased.
> > > >
> > > > What do you think?
> > >
> > > Right. But one might argue that if we increment mem_exceeded_count
> > > only when serializing or streaming is actually performed,
> > > mem_exceeded_count would be 0 in the first example and therefore users
> > > would be able to simply check mem_exceeded_count without any
> > > computation.
> >
> > Right but we'd not be able to see when the memory limit has been reached for all
> > the cases (that would hide the aborted transactions case). I think that with
> > the current approach we have the best of both world (even if it requires some
> > computations).
>
> Agreed. It would be better to show a raw statistic so that users can
> use the number as they want.
>
> I've made a small comment change and added the commit message to the
> v5 patch. I'm going to push the attached patch barring any objection
> or review comments.

+ bool memory_limit_reached = (rb->size >= logical_decoding_work_mem *
(Size) 1024);
+
+ if (memory_limit_reached)
+ rb->memExceededCount += 1;

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.

-SELECT slot_name, spill_txns, spill_count FROM
pg_stat_replication_slots WHERE slot_name =
'regression_slot_stats4_twophase';
- slot_name | spill_txns | spill_count
----------------------------------+------------+-------------
- regression_slot_stats4_twophase | 0 | 0
+SELECT slot_name, spill_txns, spill_count, mem_exceeded_count FROM
pg_stat_replication_slots WHERE slot_name =
'regression_slot_stats4_twophase';
+ slot_name | spill_txns | spill_count |
mem_exceeded_count
+---------------------------------+------------+-------------+--------------------
+ regression_slot_stats4_twophase | 0 | 0 |
1
(1 row)

Are we sure that mem_exceeded_count will always be 1 in this case? Can
it be 2 or more because of background activity?

--
Best Wishes,
Ashutosh Bapat

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2025-10-03 12:11:10 Re: Support getrandom() for pg_strong_random() source
Previous Message Nazir Bilal Yavuz 2025-10-03 11:48:28 Re: split func.sgml to separated individual sgml files