Re: pgstat: add pgstat_prep_pending() for entry ref pending setup

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgstat: add pgstat_prep_pending() for entry ref pending setup
Date: 2026-07-16 01:08:17
Message-ID: algvAXK8fKlU-DY1@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 15, 2026 at 03:50:19PM -0500, Sami Imseih wrote:
> pgstat_prep_pending_entry() bundles three operations in a single call:
> lookup, entry creation, and pending data setup. This is convenient for
> the common case, but some callers need to do some other things in
> between these steps. For example, looking at what needs to be done
> for moving pg_stat_statements [1] to the cumulative statistics collector,
> it needs to:
>
> 1. Look up the entry (pgstat_get_entry_ref with create=false)
> 2. If not found, check capacity and possibly evict before creating
> 3. Create the entry (pgstat_get_entry_ref with create=true)
> 4. Attach pending data
>
> Steps 1-3 are already possible with pgstat_get_entry_ref(), but step 4
> has no API.
>
> The attached adds pgstat_prep_pending() which exposes step 4 as a
> function. Together with pgstat_get_entry_ref(), callers can now perform
> the same work as pgstat_prep_pending_entry() in individual steps.
> pgstat_prep_pending_entry() itself is refactored to use the new
> function internally.

Hmm. So we have the APIs to do steps 1 to 3, with an eviction cleanup
happening in-between. Your argument is that if you would like to do
something between steps 3 and 4, as we don't have an API to attach
pending data. If there is nothing to do between steps 3 and 4, we can
just:
- use pgstat_get_entry_ref(create=false)
- eviction
- pgstat_prep_pending_entry() (has pgstat_get_entry_ref(create=true))

So my question is: what do you intend to do between steps 3 and 4?
More waiting for some of parallel eviction done in step 2? I was
looking at v4-0004 on the other thread, and it does the combo of
pgstat_get_entry_ref -> eviction -> pgstat_prep_pending_entry(), so I
am wondering what the actual reason for this new separation is. I
don't object to this change, but you are not mentioning why you want
it, as far as I can see?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-07-16 01:09:40 Re: Fix RLS checks for UPDATE/DELETE FOR PORTION OF leftover rows
Previous Message Tom Lane 2026-07-16 00:51:10 Re: sequencesync worker race with REFRESH SEQUENCES