diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2006-05-19 19:08:27 +0000 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2006-05-19 19:08:27 +0000 |
commit | 1f219cf433e792d61040246c24b136b0e6a2c930 (patch) | |
tree | 4489a0e0cb6947bc2ece721f220b68f80e64a0f6 /src/backend/utils/adt/pgstatfuncs.c | |
parent | 09518fbdf445554f54e4c3cffc964fe2d073b550 (diff) | |
download | postgresql-1f219cf433e792d61040246c24b136b0e6a2c930.tar.gz postgresql-1f219cf433e792d61040246c24b136b0e6a2c930.zip |
Add last-vacuum/analyze-time columns to the stats collector, both manual and
issued by autovacuum. Add accessor functions to them, and use those in the
pg_stat_*_tables system views.
Catalog version bumped due to changes in the pgstat views and the pgstat file.
Patch from Larry Rosenman, minor improvements by me.
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 362aa1d08ef..eaf379389e4 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.28 2006/05/19 15:15:37 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.29 2006/05/19 19:08:26 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -34,6 +34,10 @@ extern Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS); extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS); extern Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS); extern Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS); +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_backend_idset(PG_FUNCTION_ARGS); extern Datum pg_backend_pid(PG_FUNCTION_ARGS); @@ -197,6 +201,85 @@ pg_stat_get_blocks_hit(PG_FUNCTION_ARGS) PG_RETURN_INT64(result); } +Datum +pg_stat_get_last_vacuum_time(PG_FUNCTION_ARGS) +{ + PgStat_StatTabEntry *tabentry; + Oid relid; + TimestampTz result; + + relid = PG_GETARG_OID(0); + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = tabentry->vacuum_timestamp; + + if (result == 0) + PG_RETURN_NULL(); + else + PG_RETURN_TIMESTAMPTZ(result); +} + +Datum +pg_stat_get_last_autovacuum_time(PG_FUNCTION_ARGS) +{ + PgStat_StatTabEntry *tabentry; + Oid relid; + TimestampTz result; + + relid = PG_GETARG_OID(0); + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = tabentry->autovac_vacuum_timestamp; + + if (result == 0) + PG_RETURN_NULL(); + else + PG_RETURN_TIMESTAMPTZ(result); +} + +Datum +pg_stat_get_last_analyze_time(PG_FUNCTION_ARGS) +{ + PgStat_StatTabEntry *tabentry; + Oid relid; + TimestampTz result; + + relid = PG_GETARG_OID(0); + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = tabentry->analyze_timestamp; + + if (result == 0) + PG_RETURN_NULL(); + else + PG_RETURN_TIMESTAMPTZ(result); +} + +Datum +pg_stat_get_last_autoanalyze_time(PG_FUNCTION_ARGS) +{ + PgStat_StatTabEntry *tabentry; + Oid relid; + TimestampTz result; + + relid = PG_GETARG_OID(0); + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = tabentry->autovac_analyze_timestamp; + + if (result == 0) + PG_RETURN_NULL(); + else + PG_RETURN_TIMESTAMPTZ(result); +} Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS) |