| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> | 
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org | 
| Subject: | Add memory_limit_hits to pg_stat_replication_slots | 
| Date: | 2025-08-27 07:26:45 | 
| Message-ID: | aK6zNcmb+PpySFvG@ip-10-97-1-34.eu-west-3.compute.internal | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Hi hackers,
I think that it's currently not always possible to determine how many times
logical_decoding_work_mem has been reached.
For example, say a transaction is made of 40 subtransactions, and I get:
  slot_name   | spill_txns | spill_count | total_txns
--------------+------------+-------------+------------
 logical_slot |         40 |          41 |          1
(1 row)
Then I know that logical_decoding_work_mem has been reached one time (total_txns).
But as soon as another transaction is decoded (that does not involve spilling):
  slot_name   | spill_txns | spill_count | total_txns
--------------+------------+-------------+------------
 logical_slot |         40 |          41 |          2
(1 row)
Then we don't know if logical_decoding_work_mem has been reached one or two 
times.
Please find attached a patch to $SUBJECT, to report the number of times the 
logical_decoding_work_mem has been reached.
With such a counter one could get a ratio like total_txns/memory_limit_hits.
That could help to see if reaching logical_decoding_work_mem is rare or 
frequent enough. If frequent, then maybe there is a need to adjust
logical_decoding_work_mem.
Based on my simple example above, one could say that it might be possible to get
the same with:
(spill_count - spill_txns) + (stream_count - stream_txns)
but that doesn't appear to be the case with a more complicated example (277 vs 247):
  slot_name   | spill_txns | spill_count | total_txns | stream_txns | stream_count | memory_limit_hits | (spc-spct)+(strc-strt)
--------------+------------+-------------+------------+-------------+--------------+-------------------+------------------------
 logical_slot |        405 |         552 |         19 |           5 |          105 |               277 |                    247
(1 row)
Not sure I like memory_limit_hits that much, maybe work_mem_exceeded is better?
Looking forward to your feedback,
Regards,
-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| Attachment | Content-Type | Size | 
|---|---|---|
| v1-0001-Add-memory_limit_hits-to-pg_stat_replication_slot.patch | text/x-diff | 22.0 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bertrand Drouvot | 2025-08-27 07:31:57 | Re: Report reorder buffer size | 
| Previous Message | Chao Li | 2025-08-27 07:26:08 | Re: SQL:2023 JSON simplified accessor support |