mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Add stats_reset to pg_stat_all_{tables,indexes} and related views
It is possible to call pg_stat_reset_single_table_counters() on a relation (index or table) but the reset time was missing from the system views showing their statistics. This commit adds the reset time as an attribute of pg_stat_all_tables, pg_stat_all_indexes, and other relations related to them. Bump catalog version. Bump PGSTAT_FILE_FORMAT_ID, as a result of the new field added to PgStat_StatTabEntry. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/aN8l182jKxEq1h9f@paquier.xyz
This commit is contained in:
@@ -1798,7 +1798,8 @@ pg_stat_all_indexes| SELECT c.oid AS relid,
|
||||
pg_stat_get_numscans(i.oid) AS idx_scan,
|
||||
pg_stat_get_lastscan(i.oid) AS last_idx_scan,
|
||||
pg_stat_get_tuples_returned(i.oid) AS idx_tup_read,
|
||||
pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch
|
||||
pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch,
|
||||
pg_stat_get_stat_reset_time(i.oid) AS stats_reset
|
||||
FROM (((pg_class c
|
||||
JOIN pg_index x ON ((c.oid = x.indrelid)))
|
||||
JOIN pg_class i ON ((i.oid = x.indexrelid)))
|
||||
@@ -1833,7 +1834,8 @@ pg_stat_all_tables| SELECT c.oid AS relid,
|
||||
pg_stat_get_total_vacuum_time(c.oid) AS total_vacuum_time,
|
||||
pg_stat_get_total_autovacuum_time(c.oid) AS total_autovacuum_time,
|
||||
pg_stat_get_total_analyze_time(c.oid) AS total_analyze_time,
|
||||
pg_stat_get_total_autoanalyze_time(c.oid) AS total_autoanalyze_time
|
||||
pg_stat_get_total_autoanalyze_time(c.oid) AS total_autoanalyze_time,
|
||||
pg_stat_get_stat_reset_time(c.oid) AS stats_reset
|
||||
FROM ((pg_class c
|
||||
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
|
||||
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
|
||||
@@ -2200,7 +2202,8 @@ pg_stat_sys_indexes| SELECT relid,
|
||||
idx_scan,
|
||||
last_idx_scan,
|
||||
idx_tup_read,
|
||||
idx_tup_fetch
|
||||
idx_tup_fetch,
|
||||
stats_reset
|
||||
FROM pg_stat_all_indexes
|
||||
WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
|
||||
pg_stat_sys_tables| SELECT relid,
|
||||
@@ -2232,7 +2235,8 @@ pg_stat_sys_tables| SELECT relid,
|
||||
total_vacuum_time,
|
||||
total_autovacuum_time,
|
||||
total_analyze_time,
|
||||
total_autoanalyze_time
|
||||
total_autoanalyze_time,
|
||||
stats_reset
|
||||
FROM pg_stat_all_tables
|
||||
WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
|
||||
pg_stat_user_functions| SELECT p.oid AS funcid,
|
||||
@@ -2252,7 +2256,8 @@ pg_stat_user_indexes| SELECT relid,
|
||||
idx_scan,
|
||||
last_idx_scan,
|
||||
idx_tup_read,
|
||||
idx_tup_fetch
|
||||
idx_tup_fetch,
|
||||
stats_reset
|
||||
FROM pg_stat_all_indexes
|
||||
WHERE ((schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (schemaname !~ '^pg_toast'::text));
|
||||
pg_stat_user_tables| SELECT relid,
|
||||
@@ -2284,7 +2289,8 @@ pg_stat_user_tables| SELECT relid,
|
||||
total_vacuum_time,
|
||||
total_autovacuum_time,
|
||||
total_analyze_time,
|
||||
total_autoanalyze_time
|
||||
total_autoanalyze_time,
|
||||
stats_reset
|
||||
FROM pg_stat_all_tables
|
||||
WHERE ((schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (schemaname !~ '^pg_toast'::text));
|
||||
pg_stat_wal| SELECT wal_records,
|
||||
@@ -2370,7 +2376,8 @@ pg_statio_all_indexes| SELECT c.oid AS relid,
|
||||
c.relname,
|
||||
i.relname AS indexrelname,
|
||||
(pg_stat_get_blocks_fetched(i.oid) - pg_stat_get_blocks_hit(i.oid)) AS idx_blks_read,
|
||||
pg_stat_get_blocks_hit(i.oid) AS idx_blks_hit
|
||||
pg_stat_get_blocks_hit(i.oid) AS idx_blks_hit,
|
||||
pg_stat_get_stat_reset_time(i.oid) AS stats_reset
|
||||
FROM (((pg_class c
|
||||
JOIN pg_index x ON ((c.oid = x.indrelid)))
|
||||
JOIN pg_class i ON ((i.oid = x.indexrelid)))
|
||||
@@ -2394,7 +2401,8 @@ pg_statio_all_tables| SELECT c.oid AS relid,
|
||||
(pg_stat_get_blocks_fetched(t.oid) - pg_stat_get_blocks_hit(t.oid)) AS toast_blks_read,
|
||||
pg_stat_get_blocks_hit(t.oid) AS toast_blks_hit,
|
||||
x.idx_blks_read AS tidx_blks_read,
|
||||
x.idx_blks_hit AS tidx_blks_hit
|
||||
x.idx_blks_hit AS tidx_blks_hit,
|
||||
pg_stat_get_stat_reset_time(c.oid) AS stats_reset
|
||||
FROM ((((pg_class c
|
||||
LEFT JOIN pg_class t ON ((c.reltoastrelid = t.oid)))
|
||||
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
|
||||
@@ -2413,7 +2421,8 @@ pg_statio_sys_indexes| SELECT relid,
|
||||
relname,
|
||||
indexrelname,
|
||||
idx_blks_read,
|
||||
idx_blks_hit
|
||||
idx_blks_hit,
|
||||
stats_reset
|
||||
FROM pg_statio_all_indexes
|
||||
WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
|
||||
pg_statio_sys_sequences| SELECT relid,
|
||||
@@ -2433,7 +2442,8 @@ pg_statio_sys_tables| SELECT relid,
|
||||
toast_blks_read,
|
||||
toast_blks_hit,
|
||||
tidx_blks_read,
|
||||
tidx_blks_hit
|
||||
tidx_blks_hit,
|
||||
stats_reset
|
||||
FROM pg_statio_all_tables
|
||||
WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
|
||||
pg_statio_user_indexes| SELECT relid,
|
||||
@@ -2442,7 +2452,8 @@ pg_statio_user_indexes| SELECT relid,
|
||||
relname,
|
||||
indexrelname,
|
||||
idx_blks_read,
|
||||
idx_blks_hit
|
||||
idx_blks_hit,
|
||||
stats_reset
|
||||
FROM pg_statio_all_indexes
|
||||
WHERE ((schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (schemaname !~ '^pg_toast'::text));
|
||||
pg_statio_user_sequences| SELECT relid,
|
||||
@@ -2462,7 +2473,8 @@ pg_statio_user_tables| SELECT relid,
|
||||
toast_blks_read,
|
||||
toast_blks_hit,
|
||||
tidx_blks_read,
|
||||
tidx_blks_hit
|
||||
tidx_blks_hit,
|
||||
stats_reset
|
||||
FROM pg_statio_all_tables
|
||||
WHERE ((schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (schemaname !~ '^pg_toast'::text));
|
||||
pg_stats| SELECT n.nspname AS schemaname,
|
||||
|
||||
@@ -666,16 +666,24 @@ SELECT last_seq_scan, last_idx_scan FROM pg_stat_all_tables WHERE relid = 'test_
|
||||
(1 row)
|
||||
|
||||
COMMIT;
|
||||
SELECT stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
has_stats_reset
|
||||
-----------------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
SELECT pg_stat_reset_single_table_counters('test_last_scan'::regclass);
|
||||
pg_stat_reset_single_table_counters
|
||||
-------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT seq_scan, idx_scan FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
seq_scan | idx_scan
|
||||
----------+----------
|
||||
0 | 0
|
||||
SELECT seq_scan, idx_scan, stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
seq_scan | idx_scan | has_stats_reset
|
||||
----------+----------+-----------------
|
||||
0 | 0 | t
|
||||
(1 row)
|
||||
|
||||
-- ensure we start out with exactly one index and sequential scan
|
||||
@@ -851,11 +859,12 @@ FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
(1 row)
|
||||
|
||||
-- check the stats in pg_stat_all_indexes
|
||||
SELECT idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok
|
||||
SELECT idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok,
|
||||
stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
|
||||
idx_scan | idx_ok
|
||||
----------+--------
|
||||
3 | t
|
||||
idx_scan | idx_ok | has_stats_reset
|
||||
----------+--------+-----------------
|
||||
3 | t | f
|
||||
(1 row)
|
||||
|
||||
-- check that the stats in pg_stat_all_indexes are reset
|
||||
@@ -865,10 +874,11 @@ SELECT pg_stat_reset_single_table_counters('test_last_scan_pkey'::regclass);
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT idx_scan FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
|
||||
idx_scan
|
||||
----------
|
||||
0
|
||||
SELECT idx_scan, stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
|
||||
idx_scan | has_stats_reset
|
||||
----------+-----------------
|
||||
0 | t
|
||||
(1 row)
|
||||
|
||||
-----
|
||||
|
||||
@@ -312,8 +312,11 @@ SELECT pg_stat_force_next_flush();
|
||||
SELECT last_seq_scan, last_idx_scan FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
COMMIT;
|
||||
|
||||
SELECT stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
SELECT pg_stat_reset_single_table_counters('test_last_scan'::regclass);
|
||||
SELECT seq_scan, idx_scan FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
SELECT seq_scan, idx_scan, stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
|
||||
-- ensure we start out with exactly one index and sequential scan
|
||||
BEGIN;
|
||||
@@ -383,13 +386,15 @@ SELECT seq_scan, :'test_last_seq' = last_seq_scan AS seq_ok, idx_scan, :'test_la
|
||||
FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
|
||||
|
||||
-- check the stats in pg_stat_all_indexes
|
||||
SELECT idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok
|
||||
SELECT idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok,
|
||||
stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
|
||||
|
||||
-- check that the stats in pg_stat_all_indexes are reset
|
||||
SELECT pg_stat_reset_single_table_counters('test_last_scan_pkey'::regclass);
|
||||
|
||||
SELECT idx_scan FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
|
||||
SELECT idx_scan, stats_reset IS NOT NULL AS has_stats_reset
|
||||
FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
|
||||
|
||||
-----
|
||||
-- Test reset of some stats for shared table
|
||||
|
||||
Reference in New Issue
Block a user