From 370a709c75becffba230a3fa14747a134b7d55b4 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 27 Jun 2006 22:16:44 +0000 Subject: [PATCH] Add GUC update_process_title to control whether 'ps' display is updated for every command, default to on. --- doc/src/sgml/config.sgml | 17 ++++++++++- src/backend/bootstrap/bootstrap.c | 5 ++-- src/backend/commands/async.c | 6 ++-- src/backend/postmaster/autovacuum.c | 7 ++--- src/backend/postmaster/pgarch.c | 5 ++-- src/backend/postmaster/pgstat.c | 8 ++---- src/backend/postmaster/postmaster.c | 8 +++--- src/backend/postmaster/syslogger.c | 5 ++-- src/backend/storage/lmgr/lock.c | 28 +++++++++++-------- src/backend/tcop/postgres.c | 16 +++++------ src/backend/utils/misc/guc.c | 13 ++++++++- src/backend/utils/misc/postgresql.conf.sample | 3 ++ src/backend/utils/misc/ps_status.c | 12 ++++++-- src/include/utils/ps_status.h | 8 ++++-- 14 files changed, 89 insertions(+), 52 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index c8572f8d55..e073148ff9 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -1,4 +1,4 @@ - + Server Configuration @@ -2888,6 +2888,21 @@ SELECT * FROM parent WHERE key = 2400; + + update_process_title (boolean) + + update_process_title configuration parameter + + + + Enables updating of the process title every time a new SQL command + is received by the server. The process title is typically viewed + by the ps command or in Windows using the Process + Explorer. Only superusers can change this setting. + + + + stats_start_collector (boolean) diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 8acac3ad44..28d17d052a 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.217 2006/06/18 15:38:36 petere Exp $ + * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.218 2006/06/27 22:16:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -353,8 +353,7 @@ BootstrapMain(int argc, char *argv[]) statmsg = "??? process"; break; } - init_ps_display(statmsg, "", ""); - set_ps_display(""); + init_ps_display(statmsg, "", "", ""); } /* Acquire configuration parameters, unless inherited from postmaster */ diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index ae6b2f9137..969d297461 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.131 2006/04/25 14:11:54 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.132 2006/06/27 22:16:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -908,7 +908,7 @@ ProcessIncomingNotify(void) if (Trace_notify) elog(DEBUG1, "ProcessIncomingNotify"); - set_ps_display("notify interrupt"); + set_ps_display("notify interrupt", false); notifyInterruptOccurred = 0; @@ -979,7 +979,7 @@ ProcessIncomingNotify(void) */ pq_flush(); - set_ps_display("idle"); + set_ps_display("idle", false); if (Trace_notify) elog(DEBUG1, "ProcessIncomingNotify: done"); diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 93ba5c2c98..6f9bfe2e9a 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.20 2006/06/18 15:38:37 petere Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.21 2006/06/27 22:16:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -239,8 +239,7 @@ AutoVacMain(int argc, char *argv[]) MyProcPid = getpid(); /* Identify myself via ps */ - init_ps_display("autovacuum process", "", ""); - set_ps_display(""); + init_ps_display("autovacuum process", "", "", ""); SetProcessingMode(InitProcessing); @@ -416,7 +415,7 @@ AutoVacMain(int argc, char *argv[]) */ InitPostgres(db->name, NULL); SetProcessingMode(NormalProcessing); - set_ps_display(db->name); + set_ps_display(db->name, false); ereport(DEBUG1, (errmsg("autovacuum: processing database \"%s\"", db->name))); diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 538ba0c3ec..bcf1b2dcaf 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -19,7 +19,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.23 2006/06/18 15:38:37 petere Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.24 2006/06/27 22:16:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -244,8 +244,7 @@ PgArchiverMain(int argc, char *argv[]) /* * Identify myself via ps */ - init_ps_display("archiver process", "", ""); - set_ps_display(""); + init_ps_display("archiver process", "", "", ""); pgarch_MainLoop(); diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index f300b142dc..34ae644351 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.131 2006/06/27 03:45:16 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.132 2006/06/27 22:16:43 momjian Exp $ * ---------- */ #include "postgres.h" @@ -1743,8 +1743,7 @@ PgstatCollectorMain(int argc, char *argv[]) /* * Identify myself via ps */ - init_ps_display("stats collector process", "", ""); - set_ps_display(""); + init_ps_display("stats collector process", "", "", ""); /* * Arrange to write the initial status file right away @@ -1975,8 +1974,7 @@ pgstat_recvbuffer(void) /* * Identify myself via ps */ - init_ps_display("stats buffer process", "", ""); - set_ps_display(""); + init_ps_display("stats buffer process", "", "", ""); /* * We want to die if our child collector process does. There are two ways diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 8164d7e5b0..faf124587d 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.488 2006/06/20 22:52:00 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.489 2006/06/27 22:16:43 momjian Exp $ * * NOTES * @@ -2713,9 +2713,9 @@ BackendInitialize(Port *port) * Now that we have the user and database name, we can set the process * title for ps. It's good to do this as early as possible in startup. */ - init_ps_display(port->user_name, port->database_name, remote_ps_data); - set_ps_display("authentication"); - + init_ps_display(port->user_name, port->database_name, remote_ps_data, + update_process_title ? "authentication" : ""); + /* * Now perform authentication exchange. */ diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index 899dcad1f7..cd7823329e 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -18,7 +18,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.25 2006/06/18 15:38:37 petere Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.26 2006/06/27 22:16:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -141,8 +141,7 @@ SysLoggerMain(int argc, char *argv[]) am_syslogger = true; - init_ps_display("logger process", "", ""); - set_ps_display(""); + init_ps_display("logger process", "", "", ""); /* * If we restarted, our stderr is already redirected into our own input diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 782f968d25..1e3c642949 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.164 2006/04/14 03:38:55 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.165 2006/06/27 22:16:43 momjian Exp $ * * NOTES * A lock table is a shared memory hash table. When @@ -1059,19 +1059,22 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner) LOCKMETHODID lockmethodid = LOCALLOCK_LOCKMETHOD(*locallock); LockMethod lockMethodTable = LockMethods[lockmethodid]; const char *old_status; - char *new_status; + char *new_status = NULL; int len; LOCK_PRINT("WaitOnLock: sleeping on lock", locallock->lock, locallock->tag.mode); - old_status = get_ps_display(&len); - new_status = (char *) palloc(len + 8 + 1); - memcpy(new_status, old_status, len); - strcpy(new_status + len, " waiting"); - set_ps_display(new_status); - new_status[len] = '\0'; /* truncate off " waiting" */ - + if (update_process_title) + { + old_status = get_ps_display(&len); + new_status = (char *) palloc(len + 8 + 1); + memcpy(new_status, old_status, len); + strcpy(new_status + len, " waiting"); + set_ps_display(new_status, false); + new_status[len] = '\0'; /* truncate off " waiting" */ + } + awaitedLock = locallock; awaitedOwner = owner; @@ -1108,8 +1111,11 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner) awaitedLock = NULL; - set_ps_display(new_status); - pfree(new_status); + if (update_process_title) + { + set_ps_display(new_status, false); + pfree(new_status); + } LOCK_PRINT("WaitOnLock: wakeup on lock", locallock->lock, locallock->tag.mode); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 227498d1f6..8427b34920 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.489 2006/06/20 22:52:00 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.490 2006/06/27 22:16:44 momjian Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -910,7 +910,7 @@ exec_simple_query(const char *query_string) */ commandTag = CreateCommandTag(parsetree); - set_ps_display(commandTag); + set_ps_display(commandTag, false); BeginCommand(commandTag, dest); @@ -1144,7 +1144,7 @@ exec_parse_message(const char *query_string, /* string to execute */ pgstat_report_activity(query_string); - set_ps_display("PARSE"); + set_ps_display("PARSE", false); if (save_log_statement_stats) ResetUsage(); @@ -1376,7 +1376,7 @@ exec_bind_message(StringInfo input_message) pgstat_report_activity(""); - set_ps_display("BIND"); + set_ps_display("BIND", false); /* * Start up a transaction command so we can call functions etc. (Note that @@ -1711,7 +1711,7 @@ exec_execute_message(const char *portal_name, long max_rows) pgstat_report_activity(""); } - set_ps_display(portal->commandTag); + set_ps_display(portal->commandTag, false); /* * We use save_log_statement_stats so ShowUsage doesn't report incorrect @@ -2486,7 +2486,7 @@ PostgresMain(int argc, char *argv[], const char *username) if (!IsUnderPostmaster) MemoryContextInit(); - set_ps_display("startup"); + set_ps_display("startup", false); SetProcessingMode(InitProcessing); @@ -3121,14 +3121,14 @@ PostgresMain(int argc, char *argv[], const char *username) { if (IsTransactionOrTransactionBlock()) { - set_ps_display("idle in transaction"); + set_ps_display("idle in transaction", false); pgstat_report_activity(" in transaction"); } else { pgstat_report_tabstat(); - set_ps_display("idle"); + set_ps_display("idle", false); pgstat_report_activity(""); } diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 72041bbef7..9863696e1f 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut . * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.323 2006/06/27 19:07:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.324 2006/06/27 22:16:44 momjian Exp $ * *-------------------------------------------------------------------- */ @@ -64,6 +64,7 @@ #include "utils/builtins.h" #include "utils/memutils.h" #include "utils/pg_locale.h" +#include "utils/ps_status.h" #include "pgstat.h" #include "access/gin.h" @@ -728,6 +729,16 @@ static struct config_bool ConfigureNamesBool[] = true, NULL, NULL }, + { + {"update_process_title", PGC_SUSET, STATS_COLLECTOR, + gettext_noop("Updates the process title to show the active SQL command."), + gettext_noop("Enables updating of the process title every time a new + SQL command is received by the server.") + }, + &update_process_title, + true, NULL, NULL + }, + { {"autovacuum", PGC_SIGHUP, AUTOVACUUM, gettext_noop("Starts the autovacuum subprocess."), diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 88d872fbec..565d8b277b 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -323,11 +323,14 @@ # - Query/Index Statistics Collector - #stats_command_string = on +#update_process_title = on + #stats_start_collector = on # needed for block or row stats #stats_block_level = off #stats_row_level = off #stats_reset_on_server_start = off + # - Statistics Monitoring - #log_parser_stats = off diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index bd8f1d21a1..d23aa563f7 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -5,7 +5,7 @@ * to contain some useful information. Mechanism differs wildly across * platforms. * - * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.30 2006/06/12 02:39:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.31 2006/06/27 22:16:44 momjian Exp $ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * various details abducted from various places @@ -31,6 +31,7 @@ #include "utils/ps_status.h" extern char **environ; +bool update_process_title = true; /* @@ -210,7 +211,7 @@ save_ps_display_args(int argc, char **argv) */ void init_ps_display(const char *username, const char *dbname, - const char *host_info) + const char *host_info, const char *initial_str) { Assert(username); Assert(dbname); @@ -270,6 +271,7 @@ init_ps_display(const char *username, const char *dbname, ps_buffer_fixed_size = strlen(ps_buffer); + set_ps_display(initial_str, true); #endif /* not PS_USE_NONE */ } @@ -280,8 +282,12 @@ init_ps_display(const char *username, const char *dbname, * indication of what you're currently doing passed in the argument. */ void -set_ps_display(const char *activity) +set_ps_display(const char *activity, bool force) { + + if (!force && !update_process_title) + return; + #ifndef PS_USE_NONE /* no ps display for stand-alone backend */ if (!IsUnderPostmaster) diff --git a/src/include/utils/ps_status.h b/src/include/utils/ps_status.h index b940888784..ff2bd63166 100644 --- a/src/include/utils/ps_status.h +++ b/src/include/utils/ps_status.h @@ -4,7 +4,7 @@ * * Declarations for backend/utils/misc/ps_status.c * - * $PostgreSQL: pgsql/src/include/utils/ps_status.h,v 1.26 2005/11/05 03:04:53 tgl Exp $ + * $PostgreSQL: pgsql/src/include/utils/ps_status.h,v 1.27 2006/06/27 22:16:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -12,12 +12,14 @@ #ifndef PS_STATUS_H #define PS_STATUS_H +extern bool update_process_title; + extern char **save_ps_display_args(int argc, char **argv); extern void init_ps_display(const char *username, const char *dbname, - const char *host_info); + const char *host_info, const char *initial_str); -extern void set_ps_display(const char *activity); +extern void set_ps_display(const char *activity, bool force); extern const char *get_ps_display(int *displen); -- 2.40.0