mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +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:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.26 2006/03/05 15:58:23 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.27 2006/05/19 19:08:26 alvherre Exp $
|
||||
*/
|
||||
|
||||
CREATE VIEW pg_roles AS
|
||||
@@ -193,6 +193,10 @@ CREATE VIEW pg_stat_all_tables AS
|
||||
C.oid AS relid,
|
||||
N.nspname AS schemaname,
|
||||
C.relname AS relname,
|
||||
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_numscans(C.oid) AS seq_scan,
|
||||
pg_stat_get_tuples_returned(C.oid) AS seq_tup_read,
|
||||
sum(pg_stat_get_numscans(I.indexrelid))::bigint AS idx_scan,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
* Copyright (c) 2001-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.125 2006/05/19 15:15:37 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.126 2006/05/19 19:08:26 alvherre Exp $
|
||||
* ----------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@@ -739,6 +739,8 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
|
||||
msg.m_databaseid = shared ? InvalidOid : MyDatabaseId;
|
||||
msg.m_tableoid = tableoid;
|
||||
msg.m_analyze = analyze;
|
||||
msg.m_autovacuum = IsAutoVacuumProcess(); /* is this autovacuum? */
|
||||
msg.m_vacuumtime = GetCurrentTimestamp();
|
||||
msg.m_tuples = tuples;
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
}
|
||||
@@ -762,6 +764,8 @@ pgstat_report_analyze(Oid tableoid, bool shared, PgStat_Counter livetuples,
|
||||
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_ANALYZE);
|
||||
msg.m_databaseid = shared ? InvalidOid : MyDatabaseId;
|
||||
msg.m_tableoid = tableoid;
|
||||
msg.m_autovacuum = IsAutoVacuumProcess(); /* is this autovacuum? */
|
||||
msg.m_analyzetime = GetCurrentTimestamp();
|
||||
msg.m_live_tuples = livetuples;
|
||||
msg.m_dead_tuples = deadtuples;
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
@@ -2887,10 +2891,20 @@ pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len)
|
||||
if (tabentry == NULL)
|
||||
return;
|
||||
|
||||
if (msg->m_autovacuum)
|
||||
tabentry->autovac_vacuum_timestamp = msg->m_vacuumtime;
|
||||
else
|
||||
tabentry->vacuum_timestamp = msg->m_vacuumtime;
|
||||
tabentry->n_live_tuples = msg->m_tuples;
|
||||
tabentry->n_dead_tuples = 0;
|
||||
if (msg->m_analyze)
|
||||
{
|
||||
tabentry->last_anl_tuples = msg->m_tuples;
|
||||
if (msg->m_autovacuum)
|
||||
tabentry->autovac_analyze_timestamp = msg->m_vacuumtime;
|
||||
else
|
||||
tabentry->analyze_timestamp = msg->m_vacuumtime;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------
|
||||
@@ -2919,6 +2933,10 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len)
|
||||
if (tabentry == NULL)
|
||||
return;
|
||||
|
||||
if (msg->m_autovacuum)
|
||||
tabentry->autovac_analyze_timestamp = msg->m_analyzetime;
|
||||
else
|
||||
tabentry->analyze_timestamp = msg->m_analyzetime;
|
||||
tabentry->n_live_tuples = msg->m_live_tuples;
|
||||
tabentry->n_dead_tuples = msg->m_dead_tuples;
|
||||
tabentry->last_anl_tuples = msg->m_live_tuples + msg->m_dead_tuples;
|
||||
@@ -3005,6 +3023,10 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
|
||||
tabentry->n_dead_tuples = tabmsg[i].t_tuples_updated +
|
||||
tabmsg[i].t_tuples_deleted;
|
||||
tabentry->last_anl_tuples = 0;
|
||||
tabentry->vacuum_timestamp = 0;
|
||||
tabentry->autovac_vacuum_timestamp = 0;
|
||||
tabentry->analyze_timestamp = 0;
|
||||
tabentry->autovac_analyze_timestamp = 0;
|
||||
|
||||
tabentry->blocks_fetched = tabmsg[i].t_blocks_fetched;
|
||||
tabentry->blocks_hit = tabmsg[i].t_blocks_hit;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user