pgsql: Track statement entry timestamp in contrib/pg_stat_statements

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Track statement entry timestamp in contrib/pg_stat_statements
Date: 2023-11-27 00:52:53
Message-ID: E1r7Prp-007QQX-0j@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2023-11-27 03:49:56 pgsql: Avoid unconditionally filling in missing values with NULL in pgo
Previous Message Michael Paquier 2023-11-27 00:41:18 pgsql: Fix race condition with BIO methods initialization in libpq with