From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: pgstat: add/extend tests for resetting various kinds of stats.
Date: Fri, 16 Sep 2022 16:17:48 -0400
Message-ID: <3874726.1663359468@sss.pgh.pa.us> (raw)
In-Reply-To: <20220916183904.sss3vsau5tfgtx56@awork3.anarazel.de>
References: <E1ncazy-000nql-Sq@gemulon.postgresql.org>
<3428246.1663271992@sss.pgh.pa.us>
<20220916183904.sss3vsau5tfgtx56@awork3.anarazel.de>
Andres Freund <andres@anarazel.de> writes:
> On 2022-09-15 15:59:52 -0400, Tom Lane wrote:
>> It seems likely to me that the n_sessions increment hasn't made it to shared
>> memory because some background process happened to have a lock on the stats
>> entry when we tried. Don't we need a pg_stat_force_next_flush() call before
>> trying to inspect the sessions count?
> Indeed. Pushed a fix. To see if there are other omissions, I made
> pgstat_report_stat() never flush stats unless force is passed in. No other
> failures.
Cool, thanks for dealing with that.
>> BTW, the header comment for pgstat_report_stat is badly in need of
>> copy-editing.
> Hm - you're talking about this sentence?
/*
* Must be called by processes that performs DML: tcop/postgres.c, logical
^^^^^^^^^^^^^^^^^^^^^^^
Plural agreement problem. "all processes that perform" or "each process
that performs" would be OK.
* receiver processes, SPI worker, etc. to flush pending statistics updates to
* shared memory.
*
* Unless called with 'force', pending stats updates are flushed happen once
^^^^^^^^^^^^^^^^^^
One verb too many.
* per PGSTAT_MIN_INTERVAL (1000ms). When not forced, stats flushes do not
* block on lock acquisition, except if stats updates have been pending for
* longer than PGSTAT_MAX_INTERVAL (60000ms).
*
* Whenever pending stats updates remain at the end of pgstat_report_stat() a
* suggested idle timeout is returned. Currently this is always
* PGSTAT_IDLE_INTERVAL (10000ms). Callers can use the returned time to set up
* a timeout after which to call pgstat_report_stat(true), but are not
* required to to do so.
This isn't grammatically bad, but it fails to explain how callers are to
know whether they need to do that. It looks like the convention is to
return 0 if no updates remain, but you have to read the code and guess.
*
* Note that this is called only when not within a transaction, so it is fair
* to use transaction stop time as an approximation of current time.
*/
This should be inside the function, it's not part of the API spec nor of
any concern to callers. Or maybe the API spec should say "This must be
called immediately after finishing a transaction", and then inside the
function say "We assume GetCurrentTransactionStopTimestamp gives a
close-enough approximation of current time."
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de
Subject: Re: pgsql: pgstat: add/extend tests for resetting various kinds of stats.
In-Reply-To: <3874726.1663359468@sss.pgh.pa.us>
References: <E1ncazy-000nql-Sq@gemulon.postgresql.org> <3428246.1663271992@sss.pgh.pa.us> <20220916183904.sss3vsau5tfgtx56@awork3.anarazel.de> <3874726.1663359468@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox