*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.18 2006/05/03 22:45:26 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.19 2006/05/19 15:15:37 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
#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"
#include "utils/syscache.h"
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);
/*
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);
MemoryContextSwitchTo(old_cxt);
}
+/*
+ * 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
*
* Copyright (c) 2001-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.124 2006/04/27 00:06:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.125 2006/05/19 15:15:37 alvherre Exp $
* ----------
*/
#include "postgres.h"
/*
* 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
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.27 2006/03/05 15:58:43 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.28 2006/05/19 15:15:37 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
+ SockAddr zero_clientaddr;
int32 beid;
char remote_host[NI_MAXHOST];
int ret;
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:
pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
+ SockAddr zero_clientaddr;
int32 beid;
char remote_port[NI_MAXSERV];
int ret;
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: