diff options
author | Magnus Hagander <magnus@hagander.net> | 2010-08-21 10:59:17 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2010-08-21 10:59:17 +0000 |
commit | 946045f04d11d246a834b917a2b8bc6e4f884a37 (patch) | |
tree | 0ba0523ecc0eda2ad543445ee0624175395e201b /src | |
parent | efe2e9a75897dbe1270b16bf93ce5d526b4c1fe8 (diff) | |
download | postgresql-946045f04d11d246a834b917a2b8bc6e4f884a37.tar.gz postgresql-946045f04d11d246a834b917a2b8bc6e4f884a37.zip |
Add vacuum and analyze counters to pg_stat_*_tables views.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/catalog/system_views.sql | 8 | ||||
-rw-r--r-- | src/backend/postmaster/pgstat.c | 18 | ||||
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 66 | ||||
-rw-r--r-- | src/include/catalog/catversion.h | 4 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 10 | ||||
-rw-r--r-- | src/include/pgstat.h | 6 |
6 files changed, 104 insertions, 8 deletions
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 217e597513b..a1604802892 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -3,7 +3,7 @@ * * Copyright (c) 1996-2010, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.67 2010/08/08 16:27:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.68 2010/08/21 10:59:17 mha Exp $ */ CREATE VIEW pg_roles AS @@ -201,7 +201,11 @@ CREATE VIEW pg_stat_all_tables AS pg_stat_get_last_vacuum_time(C.oid) as last_vacuum, pg_stat_get_last_autovacuum_time(C.oid) as last_autovacuum, pg_stat_get_last_analyze_time(C.oid) as last_analyze, - pg_stat_get_last_autoanalyze_time(C.oid) as last_autoanalyze + pg_stat_get_last_autoanalyze_time(C.oid) as last_autoanalyze, + pg_stat_get_vacuum_count(C.oid) AS vacuum_count, + pg_stat_get_autovacuum_count(C.oid) AS autovacuum_count, + pg_stat_get_analyze_count(C.oid) AS analyze_count, + pg_stat_get_autoanalyze_count(C.oid) AS autoanalyze_count FROM pg_class C LEFT JOIN pg_index I ON C.oid = I.indrelid LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index ae8db9e9dea..b1782da4237 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2010, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.205 2010/08/08 16:27:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.206 2010/08/21 10:59:17 mha Exp $ * ---------- */ #include "postgres.h" @@ -3192,6 +3192,10 @@ pgstat_get_tab_entry(PgStat_StatDBEntry *dbentry, Oid tableoid, bool create) result->autovac_vacuum_timestamp = 0; result->analyze_timestamp = 0; result->autovac_analyze_timestamp = 0; + result->vacuum_count = 0; + result->autovac_vacuum_count = 0; + result->analyze_count = 0; + result->autovac_analyze_count = 0; } return result; @@ -4114,9 +4118,15 @@ pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len) tabentry->n_dead_tuples = 0; if (msg->m_autovacuum) + { tabentry->autovac_vacuum_timestamp = msg->m_vacuumtime; + tabentry->autovac_vacuum_count++; + } else + { tabentry->vacuum_timestamp = msg->m_vacuumtime; + tabentry->vacuum_count++; + } } /* ---------- @@ -4151,9 +4161,15 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len) tabentry->changes_since_analyze = 0; if (msg->m_autovacuum) + { tabentry->autovac_analyze_timestamp = msg->m_analyzetime; + tabentry->autovac_analyze_count++; + } else + { tabentry->analyze_timestamp = msg->m_analyzetime; + tabentry->analyze_count++; + } } diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 77627dbdf36..9432fc86c6a 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.61 2010/08/08 16:27:04 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.62 2010/08/21 10:59:17 mha Exp $ * *------------------------------------------------------------------------- */ @@ -38,6 +38,10 @@ extern Datum pg_stat_get_last_vacuum_time(PG_FUNCTION_ARGS); extern Datum pg_stat_get_last_autovacuum_time(PG_FUNCTION_ARGS); extern Datum pg_stat_get_last_analyze_time(PG_FUNCTION_ARGS); extern Datum pg_stat_get_last_autoanalyze_time(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_vacuum_count(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_autovacuum_count(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_analyze_count(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_autoanalyze_count(PG_FUNCTION_ARGS); extern Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS); extern Datum pg_stat_get_function_time(PG_FUNCTION_ARGS); @@ -347,6 +351,66 @@ pg_stat_get_last_autoanalyze_time(PG_FUNCTION_ARGS) } Datum +pg_stat_get_vacuum_count(PG_FUNCTION_ARGS) +{ + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = (int64) (tabentry->vacuum_count); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_autovacuum_count(PG_FUNCTION_ARGS) +{ + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = (int64) (tabentry->autovac_vacuum_count); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_analyze_count(PG_FUNCTION_ARGS) +{ + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = (int64) (tabentry->analyze_count); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_autoanalyze_count(PG_FUNCTION_ARGS) +{ + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = (int64) (tabentry->autovac_analyze_count); + + PG_RETURN_INT64(result); +} + +Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS) { Oid funcid = PG_GETARG_OID(0); diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index db5f3c67b3a..5c538e6f790 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.595 2010/08/13 18:36:24 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.596 2010/08/21 10:59:17 mha Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201008131 +#define CATALOG_VERSION_NO 201008211 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 7531b7ab5ec..c4dd14a71e7 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.579 2010/08/13 18:36:25 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.580 2010/08/21 10:59:17 mha Exp $ * * NOTES * The script catalog/genbki.pl reads this file and generates .bki @@ -3029,6 +3029,14 @@ DATA(insert OID = 2783 ( pg_stat_get_last_analyze_time PGNSP PGUID 12 1 0 0 f f DESCR("statistics: last manual analyze time for a table"); DATA(insert OID = 2784 ( pg_stat_get_last_autoanalyze_time PGNSP PGUID 12 1 0 0 f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_autoanalyze_time _null_ _null_ _null_ )); DESCR("statistics: last auto analyze time for a table"); +DATA(insert OID = 3054 ( pg_stat_get_vacuum_count PGNSP PGUID 12 1 0 0 f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_vacuum_count _null_ _null_ _null_ )); +DESCR("statistics: number of manual vacuums for a table"); +DATA(insert OID = 3055 ( pg_stat_get_autovacuum_count PGNSP PGUID 12 1 0 0 f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_autovacuum_count _null_ _null_ _null_ )); +DESCR("statistics: number of auto vacuums for a table"); +DATA(insert OID = 3056 ( pg_stat_get_analyze_count PGNSP PGUID 12 1 0 0 f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_analyze_count _null_ _null_ _null_ )); +DESCR("statistics: number of manual analyzes for a table"); +DATA(insert OID = 3057 ( pg_stat_get_autoanalyze_count PGNSP PGUID 12 1 0 0 f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_autoanalyze_count _null_ _null_ _null_ )); +DESCR("statistics: number of auto analyzes for a table"); DATA(insert OID = 1936 ( pg_stat_get_backend_idset PGNSP PGUID 12 1 100 0 f f f t t s 0 0 23 "" _null_ _null_ _null_ _null_ pg_stat_get_backend_idset _null_ _null_ _null_ )); DESCR("statistics: currently active backend IDs"); DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 f f f f t s 1 0 2249 "23" "{23,26,23,26,25,25,16,1184,1184,1184,869,23}" "{i,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,procpid,usesysid,application_name,current_query,waiting,xact_start,query_start,backend_start,client_addr,client_port}" _null_ pg_stat_get_activity _null_ _null_ _null_ )); diff --git a/src/include/pgstat.h b/src/include/pgstat.h index fae6cb8155f..1bbe008c463 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -5,7 +5,7 @@ * * Copyright (c) 2001-2010, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.90 2010/08/08 16:27:06 tgl Exp $ + * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.91 2010/08/21 10:59:17 mha Exp $ * ---------- */ #ifndef PGSTAT_H @@ -525,9 +525,13 @@ typedef struct PgStat_StatTabEntry PgStat_Counter blocks_hit; TimestampTz vacuum_timestamp; /* user initiated vacuum */ + PgStat_Counter vacuum_count; TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */ + PgStat_Counter autovac_vacuum_count; TimestampTz analyze_timestamp; /* user initiated */ + PgStat_Counter analyze_count; TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */ + PgStat_Counter autovac_analyze_count; } PgStat_StatTabEntry; |