Re: pgstat: Flush some statistics within running transactions, take 2

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Lukas Fittl <lukas(at)fittl(dot)com>
Subject: Re: pgstat: Flush some statistics within running transactions, take 2
Date: 2026-09-10 03:43:12
Message-ID: CAN12+YKaJekvHazG-WBCp1OkN+ZFRXXO+749u_9K2ykXrSuoFQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> While I don't forget, this piece of 0002 is worth its own change:
>
> + <row>
> + <entry role="func_table_entry"><para role="func_signature">
> + <indexterm>
> + <primary>pg_stat_force_next_flush</primary>
> + </indexterm>
> + <function>pg_stat_force_next_flush</function> ()
> + <returnvalue>void</returnvalue>
> + </para>
> + <para>
> + Flushes the statistics pending in the current session to shared
> + memory, making them visible to other sessions. When called within
> + a transaction, counters tracking data modifications, such as the
> + numbers of inserted, updated, and deleted tuples, are deferred
> + until the transaction ends.
> + </para></entry>
> + </row>
>
> FWIW, I have used it in some out-of-core tests to accelerate some
> logic based on many stats lookups, and only knew about it because of
> my knowledge of the core code (test script went down from 8s to 1s-ish
> mostly thanks to this function on my laptop, due to waits for the
> stats lookups previously).
>
> I think that we should add it to the docs, with a slightly different
> description, and without mentioning any transactional behavior as a
> starting point. Say:
> "Forces the statistics accumulated by the current session to be
> flushed to shared memory at the end of current transaction, without
> waiting for the usual <varname>PGSTAT_MIN_INTERVAL</varname> delay
> between flushes. This is mainly useful when writing tests so as the
> statistics are generated by a session in a predictable way."

Attached is the doc update with some slightly different wording.

--
Sami

Attachment Content-Type Size
v1-0001-doc-document-pg_stat_force_next_flush.patch application/octet-stream 1.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2026-09-10 03:44:41 Re: Use WALReadFromBuffers in more places
Previous Message shihao zhong 2026-09-10 03:39:07 Re: Correct documentation for protocol version