summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera2006-05-19 15:15:38 +0000
committerAlvaro Herrera2006-05-19 15:15:38 +0000
commite5ab52b27375461198c09bdaf3916bca64215357 (patch)
tree9b33d62b3b27919fef251ba76394e6933bd07308
parent3a3622c5f03ace3b0933e078d65e8a9a196dedf0 (diff)
Have autovacuum report its activities to the stat collector.
-rw-r--r--src/backend/postmaster/autovacuum.c69
-rw-r--r--src/backend/postmaster/pgstat.c18
-rw-r--r--src/backend/postmaster/postmaster.c5
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c16
4 files changed, 96 insertions, 12 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 83a359ed4d0..866f6460035 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.5.2.5 2006/01/20 15:17:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.5.2.6 2006/05/19 15:15:38 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -45,6 +45,8 @@
#include "utils/fmgroids.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
+#include "utils/lsyscache.h"
+#include "utils/rel.h"
#include "utils/relcache.h"
@@ -108,6 +110,8 @@ static void test_rel_for_autovac(Oid relid, PgStat_StatTabEntry *tabentry,
List **toast_table_ids);
static void autovacuum_do_vac_analyze(List *relids, bool dovacuum,
bool doanalyze, bool freeze);
+static void autovac_report_activity(VacuumStmt *vacstmt,
+ List *relids);
/*
@@ -916,6 +920,9 @@ autovacuum_do_vac_analyze(List *relids, bool dovacuum, bool doanalyze,
vacstmt->relation = NULL; /* all tables, or not used if relids != NIL */
vacstmt->va_cols = NIL;
+ /* Let pgstat know what we're doing */
+ autovac_report_activity(vacstmt, relids);
+
vacuum(vacstmt, relids);
pfree(vacstmt);
@@ -923,6 +930,66 @@ autovacuum_do_vac_analyze(List *relids, bool dovacuum, bool doanalyze,
}
/*
+ * autovac_report_activity
+ * Report to pgstat what autovacuum is doing
+ *
+ * We send a SQL string corresponding to what the user would see if the
+ * equivalent command was to be issued manually.
+ *
+ * Note we assume that we are going to report the next command as soon as we're
+ * done with the current one, and exiting right after the last one, so we don't
+ * bother to report "<IDLE>" or some such.
+ */
+#define MAX_AUTOVAC_ACTIV_LEN (NAMEDATALEN * 2 + 32)
+static void
+autovac_report_activity(VacuumStmt *vacstmt, List *relids)
+{
+ char activity[MAX_AUTOVAC_ACTIV_LEN];
+
+ /*
+ * This case is not currently exercised by the autovac code. Fill it in
+ * if needed.
+ */
+ if (list_length(relids) > 1)
+ elog(WARNING, "vacuuming >1 rel unsupported");
+
+ /* Report the command and possible options */
+ if (vacstmt->vacuum)
+ snprintf(activity, MAX_AUTOVAC_ACTIV_LEN,
+ "VACUUM%s%s%s",
+ vacstmt->full ? " FULL" : "",
+ vacstmt->freeze ? " FREEZE" : "",
+ vacstmt->analyze ? " ANALYZE" : "");
+ else if (vacstmt->analyze)
+ snprintf(activity, MAX_AUTOVAC_ACTIV_LEN,
+ "ANALYZE");
+
+ /* Report the qualified name of the first relation, if any */
+ if (list_length(relids) > 0)
+ {
+ Oid relid = linitial_oid(relids);
+ Relation rel;
+
+ rel = RelationIdGetRelation(relid);
+ if (rel == NULL)
+ elog(WARNING, "cache lookup failed for relation %u", relid);
+ else
+ {
+ char *nspname = get_namespace_name(RelationGetNamespace(rel));
+ int len = strlen(activity);
+
+ snprintf(activity + len, MAX_AUTOVAC_ACTIV_LEN - len,
+ " %s.%s", nspname, RelationGetRelationName(rel));
+
+ pfree(nspname);
+ RelationClose(rel);
+ }
+ }
+
+ pgstat_report_activity(activity);
+}
+
+/*
* AutoVacuumingActive
* Check GUC vars and report whether the autovacuum process should be
* running.
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 1edcd123aaf..cd3c4b28cbf 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.111.2.2 2006/01/18 20:35:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.111.2.3 2006/05/19 15:15:38 alvherre Exp $
* ----------
*/
#include "postgres.h"
@@ -691,17 +691,17 @@ pgstat_bestart(void)
/*
* We may not have a MyProcPort (eg, if this is the autovacuum process).
- * For the moment, punt and don't send BESTART --- would be better to work
- * out a clean way of handling "unknown clientaddr".
+ * Send an all-zeroes client address, which is dealt with specially in
+ * pg_stat_get_backend_client_addr and pg_stat_get_backend_client_port.
*/
+ pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
+ msg.m_databaseid = MyDatabaseId;
+ msg.m_userid = GetSessionUserId();
if (MyProcPort)
- {
- pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
- msg.m_databaseid = MyDatabaseId;
- msg.m_userid = GetSessionUserId();
memcpy(&msg.m_clientaddr, &MyProcPort->raddr, sizeof(msg.m_clientaddr));
- pgstat_send(&msg, sizeof(msg));
- }
+ else
+ MemSet(&msg.m_clientaddr, 0, sizeof(msg.m_clientaddr));
+ pgstat_send(&msg, sizeof(msg));
/*
* Set up a process-exit hook to ensure we flush the last batch of
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 0a226dba279..fb45b89587b 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.475.2.4 2006/03/18 22:10:11 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.475.2.5 2006/05/19 15:15:38 alvherre Exp $
*
* NOTES
*
@@ -2135,6 +2135,9 @@ reaper(SIGNAL_ARGS)
{
AutoVacPID = 0;
autovac_stopped();
+ /* Tell the collector about process termination */
+ pgstat_beterm(pid);
+
if (exitstatus != 0)
HandleChildCrash(pid, exitstatus,
_("autovacuum process"));
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 1d68b32e526..4b31a6ef5ba 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.26 2005/10/17 16:24:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.26.2.1 2006/05/19 15:15:38 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -389,6 +389,7 @@ Datum
pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
+ SockAddr zero_clientaddr;
int32 beid;
char remote_host[NI_MAXHOST];
int ret;
@@ -405,6 +406,12 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
if (!superuser() && beentry->userid != GetUserId())
PG_RETURN_NULL();
+ /* A zeroed client addr means we don't know */
+ memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
+ if (memcmp(&(beentry->clientaddr), &zero_clientaddr,
+ sizeof(zero_clientaddr) == 0))
+ PG_RETURN_NULL();
+
switch (beentry->clientaddr.addr.ss_family)
{
case AF_INET:
@@ -432,6 +439,7 @@ Datum
pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
+ SockAddr zero_clientaddr;
int32 beid;
char remote_port[NI_MAXSERV];
int ret;
@@ -448,6 +456,12 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
if (!superuser() && beentry->userid != GetUserId())
PG_RETURN_NULL();
+ /* A zeroed client addr means we don't know */
+ memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
+ if (memcmp(&(beentry->clientaddr), &zero_clientaddr,
+ sizeof(zero_clientaddr) == 0))
+ PG_RETURN_NULL();
+
switch (beentry->clientaddr.addr.ss_family)
{
case AF_INET: