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

From Bertrand Drouvot
Subject Re: Add memory_limit_hits to pg_stat_replication_slots
Date
Msg-id aN/MZF9zlhcIt4YK@ip-10-97-1-34.eu-west-3.compute.internal
Whole thread Raw
In response to Re: Add memory_limit_hits to pg_stat_replication_slots  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
Responses Re: Add memory_limit_hits to pg_stat_replication_slots
Re: Add memory_limit_hits to pg_stat_replication_slots
List pgsql-hackers
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.

> -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?

I think that the question could be the same for spill_txns and spill_count. It
seems to have been working fine (that way) since this test exists (added in 
072ee847ad4c) but I think that you raised a good point.

Sawada-San, what do you think about this particular test, is it safe to rely
on the exact values here?

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com



pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: sql/json query function JsonBehavior default expression's collation may differ from returning type's collation
Next
From: Greg Burd
Date:
Subject: Re: Fixing a few minor misusages of bms_union()