Re: [PATCH] Tracking statements entry timestamp in pg_stat_statements
Anton A. Melnikov <aamelnikov@inbox.ru>
From: "Anton A. Melnikov" <aamelnikov@inbox.ru>
To: Andrei Zubkov <zubkov@moonset.ru>, pgsql-hackers@lists.postgresql.org
Date: 2021-12-22T01:25:33Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Improve quoting in some error messages
- 07e5e6674233 14.0 cited
On 03.12.2021 19:55, Andrei Zubkov wrote: > On Fri, 2021-12-03 at 17:03 +0300, Andrei Zubkov wrote: ... > What if we'll create a new view for such resettable fields? It will > make description of views and reset functions in the docs much more > clear. > Hi, Andrey! I completely agree that creating a separate view for these new fields is the most correct thing to do. As for variable names, the term global is already used for global statistics, in particular in the struct pgssGlobalStats. The considered timestamps refer to per statement level as pointed out in the struct pgssEntry's comment. Therefore, i think it's better to rename gstats_since to just stats_reset in the same way. Also it might be better to use the term 'auxiliary' and use the same approach as for existent similar vars. So internally it might look something like this: double aux_min_time[PGSS_NUMKIND]; double aux_max_time[PGSS_NUMKIND]; TimestampTz aux_stats_reset; And at the view level: aux_min_plan_time float8, aux_max_plan_time float8, aux_min_exec_time float8, aux_max_exec_time float8, aux_stats_reset timestamp with time zone Functions names might be pg_stat_statements_aux() and pg_stat_statements_aux_reset(). The top-level application may find out period the aux extrema were collected by determining which reset was closer as follows: data_collect_period = aux_stats_reset > stats_reset ? now - aux_stats_reset : now - stats_reset; and decide not to trust this data if the period was too small. For correct work aux_stats_reset must be updated and aux extrema values must be reset simultaneously with updating of stats_reset therefore some synchronization needed to avoid race with possible external reset. I've tested the patch v4 and didn't find any evident problems. Contrib installcheck said: test pg_stat_statements ... ok 163 ms test oldextversions ... ok 46 ms With best regards, -- Anton A. Melnikov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company