Re: Flush some statistics within running transactions

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Sami Imseih <samimseih(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Subject: Re: Flush some statistics within running transactions
Date: 2026-01-28 11:14:00
Message-ID: aXnveIxQEB5wwcB8@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Jan 28, 2026 at 03:35:21PM +0900, Michael Paquier wrote:
> On Mon, Jan 26, 2026 at 06:59:28AM +0000, Bertrand Drouvot wrote:
> > The attached, to apply on top of 0001, fix the issue. However it handles only the
> > WaitLatch in ProcSleep() case and I start to have concern about the others WaitLatch()
> > that would/could be "woken up" every 1s.
>
> > Using disable_timeout() and enable_timeout_after() in WaitEventSetWait() does not
> > look like a great answer to this concern, so I wonder if we should use a larger
> > flush frequency instead (as proposed up-thread), thoughts?
>
> Only a larger frequency is not the correct answer here. It would just
> reduce the frequency of the extra lock wait messages for one: these
> should never appear more than necessary.

Right. The fix in fix_ProcSleep.txt shared up-thread solves that and has been
added in 0001 attached.

Also the attached is now split in 4 sub-patches with 0002 introducing a new
GUC to control the flush interval (default is 10s). Note that 0001 to 0003 could
be merged as one patch but I did it that way to ease the review.

The new version also adds more documentation and takes care of Sami's comments
shared up-thread.

> And how about for example extension code?

I think that depending on how they write their code around WaitLatch (if any) they
could see messages being reported (if they do) in the logs at stats_flush_interval
frequency.

That said the default value is 10s and that looks pretty long for a latch to wait on.
In any case, they should already take care of a latch being woken by WL_LATCH_SET.

What do you think?

Regards,

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

Attachment Content-Type Size
v4-0001-Add-pgstat_report_anytime_stat-for-periodic-stats.patch text/x-diff 17.9 KB
v4-0002-Add-GUC-to-specify-non-transactional-statistics-f.patch text/x-diff 8.3 KB
v4-0003-Remove-useless-calls-to-flush-some-stats.patch text/x-diff 7.6 KB
v4-0004-Add-FLUSH_MIXED-support-and-implement-it-for-RELA.patch text/x-diff 17.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-01-28 11:20:18 Re: pgsql: Prevent invalidation of newly synced replication slots.
Previous Message Jakub Wartak 2026-01-28 11:12:10 Re: pg_stat_io_histogram