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