pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Track statement entry timestamp in contrib/pg_stat_statements
Date: Mon, 27 Nov 2023 00:52:53 +0000
Message-ID: <E1r7Prp-007QQX-0j@gemulon.postgresql.org> (raw)

Track statement entry timestamp in contrib/pg_stat_statements

This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function.  The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.

'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable.  It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.

Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.

Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dc9f8a798307244d791b71f666f50de319799e7c

Modified Files
--------------
contrib/pg_stat_statements/Makefile                |   2 +-
.../expected/entry_timestamp.out                   | 159 +++++++++++++++++++++
.../pg_stat_statements/expected/oldextversions.out | 116 ++++++++-------
contrib/pg_stat_statements/meson.build             |   1 +
.../pg_stat_statements--1.10--1.11.sql             |  23 ++-
contrib/pg_stat_statements/pg_stat_statements.c    | 119 +++++++++++----
contrib/pg_stat_statements/sql/entry_timestamp.sql | 114 +++++++++++++++
contrib/pg_stat_statements/sql/oldextversions.sql  |   4 +-
doc/src/sgml/pgstatstatements.sgml                 |  69 +++++++--
9 files changed, 511 insertions(+), 96 deletions(-)



Message-ID: <E1r7Prp-007QQX-0j@gemulon.postgresql.org>
Permalink:  ../E1r7Prp-007QQX-0j@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1r7Prp-007QQX-0j@gemulon.postgresql.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Track statement entry timestamp in contrib/pg_stat_statements
  In-Reply-To: <E1r7Prp-007QQX-0j@gemulon.postgresql.org>

* 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