pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: pgstat: Track time of the last scan of a relation
Date: Fri, 14 Oct 2022 18:14:41 +0000
Message-ID: <E1ojPCj-002N3f-09@gemulon.postgresql.org> (raw)

pgstat: Track time of the last scan of a relation

It can be useful to know when a relation has last been used, e.g., when
evaluating whether an index is still required. It was already possible to
infer the time of the last usage by tracking, e.g.,
pg_stat_all_indexes.idx_scan over time. But far from everybody does so.

To make it easier to detect the last time a relation has been scanned, track
that time in each relation's pgstat entry. To minimize overhead a) the
timestamp is updated only when the backend pending stats entry is flushed to
shared stats b) the last transaction's stop timestamp is used as the
timestamp.

Bumps catalog and stats format versions.

Author: Dave Page <dpage@pgadmin.org>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Bruce Momjian <bruce@momjian.us>
Reviewed-by: Vik Fearing <vik@postgresfriends.org>
Discussion: https://postgr.es/m/CA+OCxozrVHNFVEPkweUHMZje+t1tfY816d9MZYc6eZwOOusOaQ@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
doc/src/sgml/monitoring.sgml                 |  30 ++++
src/backend/catalog/system_views.sql         |   3 +
src/backend/utils/activity/pgstat_relation.c |   6 +
src/backend/utils/adt/pgstatfuncs.c          |  13 ++
src/include/catalog/catversion.h             |   2 +-
src/include/catalog/pg_proc.dat              |   4 +
src/include/pgstat.h                         |   3 +-
src/test/regress/expected/rules.out          |   9 ++
src/test/regress/expected/stats.out          | 202 +++++++++++++++++++++++++++
src/test/regress/sql/stats.sql               |  86 ++++++++++++
10 files changed, 356 insertions(+), 2 deletions(-)



Message-ID: <E1ojPCj-002N3f-09@gemulon.postgresql.org>
Permalink:  ../E1ojPCj-002N3f-09@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ojPCj-002N3f-09@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 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: andres@anarazel.de
  Subject: Re: pgsql: pgstat: Track time of the last scan of a relation
  In-Reply-To: <E1ojPCj-002N3f-09@gemulon.postgresql.org>
  References: <E1ojPCj-002N3f-09@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