mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +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:
@@ -716,7 +716,8 @@ CREATE VIEW pg_stat_all_tables AS
|
||||
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)
|
||||
@@ -778,7 +779,8 @@ CREATE VIEW pg_statio_all_tables AS
|
||||
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)
|
||||
@@ -818,7 +820,8 @@ CREATE VIEW pg_stat_all_indexes AS
|
||||
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
|
||||
@@ -844,7 +847,8 @@ CREATE VIEW pg_statio_all_indexes AS
|
||||
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
|
||||
|
||||
@@ -313,6 +313,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
|
||||
|
||||
.flush_pending_cb = pgstat_relation_flush_cb,
|
||||
.delete_pending_cb = pgstat_relation_delete_pending_cb,
|
||||
.reset_timestamp_cb = pgstat_relation_reset_timestamp_cb,
|
||||
},
|
||||
|
||||
[PGSTAT_KIND_FUNCTION] = {
|
||||
|
||||
@@ -910,6 +910,12 @@ pgstat_relation_delete_pending_cb(PgStat_EntryRef *entry_ref)
|
||||
pgstat_unlink_relation(pending->relation);
|
||||
}
|
||||
|
||||
void
|
||||
pgstat_relation_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
|
||||
{
|
||||
((PgStatShared_Relation *) header)->stats.stat_reset_time = ts;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find or create a PgStat_TableStatus entry for rel. New entry is created and
|
||||
* initialized if not exists.
|
||||
|
||||
@@ -168,6 +168,9 @@ PG_STAT_GET_RELENTRY_TIMESTAMPTZ(last_vacuum_time)
|
||||
/* pg_stat_get_lastscan */
|
||||
PG_STAT_GET_RELENTRY_TIMESTAMPTZ(lastscan)
|
||||
|
||||
/* pg_stat_get_stat_reset_time */
|
||||
PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat_reset_time)
|
||||
|
||||
Datum
|
||||
pg_stat_get_function_calls(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user