From c037471832e1ec3327f81eebbd8892e5c1042fe0 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 14 Oct 2022 11:11:34 -0700 Subject: 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 Reviewed-by: Andres Freund Reviewed-by: Bruce Momjian Reviewed-by: Vik Fearing Discussion: https://postgr.es/m/CA+OCxozrVHNFVEPkweUHMZje+t1tfY816d9MZYc6eZwOOusOaQ@mail.gmail.com --- doc/src/sgml/monitoring.sgml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 342b20ebeb0..60a2026b0b0 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -4385,6 +4385,16 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i + + + last_seq_scan timestamptz + + + The time of the last sequential scan on this table, based on the + most recent transaction stop time + + + seq_tup_read bigint @@ -4403,6 +4413,16 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i + + + last_idx_scan timestamptz + + + The time of the last index scan on this table, based on the + most recent transaction stop time + + + idx_tup_fetch bigint @@ -4654,6 +4674,16 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i + + + last_idx_scan timestamptz + + + The time of the last scan on this index, based on the + most recent transaction stop time + + + idx_tup_read bigint -- cgit v1.2.3