1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

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.
This commit is contained in:
Alvaro Herrera
2006-05-19 19:08:27 +00:00
parent 09518fbdf4
commit 1f219cf433
8 changed files with 171 additions and 12 deletions

View File

@ -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)