]> granicus.if.org Git - postgresql/commitdiff
Add GUC update_process_title to control whether 'ps' display is updated
authorBruce Momjian <bruce@momjian.us>
Tue, 27 Jun 2006 22:16:44 +0000 (22:16 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 27 Jun 2006 22:16:44 +0000 (22:16 +0000)
for every command, default to on.

14 files changed:
doc/src/sgml/config.sgml
src/backend/bootstrap/bootstrap.c
src/backend/commands/async.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/postmaster/syslogger.c
src/backend/storage/lmgr/lock.c
src/backend/tcop/postgres.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/backend/utils/misc/ps_status.c
src/include/utils/ps_status.h

index c8572f8d552b5360d9fc5c9a20cf3f24069e011d..e073148ff9ae1348305a9f7719eec7a8106fa9c3 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.67 2006/06/27 19:07:50 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.68 2006/06/27 22:16:43 momjian Exp $ -->
 
 <chapter Id="runtime-config">
   <title>Server Configuration</title>
@@ -2888,6 +2888,21 @@ SELECT * FROM parent WHERE key = 2400;
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-update-process-title" xreflabel="update_process_title">
+      <term><varname>update_process_title</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>update_process_title</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        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 <command>ps</> command or in Windows using the <application>Process
+        Explorer</>.   Only superusers can change this setting.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-stats-start-collector" xreflabel="stats_start_collector">
       <term><varname>stats_start_collector</varname> (<type>boolean</type>)</term>
       <indexterm>
index 8acac3ad4495d55b42b447a9cd19f3abc12e7100..28d17d052a5f6e118accc151a8195e1d81be1a93 100644 (file)
@@ -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 */
index ae6b2f9137466c4a19e4bd9a906e5fd0f88e3121..969d2974615ed792f8458c7353c5a8e184b1ed86 100644 (file)
@@ -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");
index 93ba5c2c98938bb046df9d2bc6b1d8d46f5bba5b..6f9bfe2e9afefde7fc7d4d88fd6b9a3e5de675ab 100644 (file)
@@ -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)));
 
index 538ba0c3ec6082427c8cf89f2e3fa9410f8048b2..bcf1b2dcafb55493ef2fccaa1fc43927ef21fd5e 100644 (file)
@@ -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();
 
index f300b142dcc16660af7b4d1fb7f311cb33031b3e..34ae644351dfeb00bc38fc90b3b076b0ab5a7248 100644 (file)
@@ -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
index 8164d7e5b033d81d56321767f21ae6e11aea110b..faf124587da027a0b05b0614beb9f13c456371a1 100644 (file)
@@ -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.
         */
index 899dcad1f7ace8e98f7658e8e13efad5ebe60858..cd7823329e7d4d4282367ed8fa47407bdaf216c0 100644 (file)
@@ -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
index 782f968d25509d9e4715fb3029ba1ac20a3e49ff..1e3c6429493e901ef152a3a4f5c9356e052d3d05 100644 (file)
@@ -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);
index 227498d1f67e3ede3d38814b7fddd076765a2a97..8427b34920dd8e62a99b3e104f39adf3959e62c0 100644 (file)
@@ -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("<BIND>");
 
-       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("<EXECUTE>");
        }
 
-       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("<IDLE> in transaction");
                        }
                        else
                        {
                                pgstat_report_tabstat();
 
-                               set_ps_display("idle");
+                               set_ps_display("idle", false);
                                pgstat_report_activity("<IDLE>");
                        }
 
index 72041bbef7ebffe61727b564140db1d1d06c89d2..9863696e1fbecff244e4ce035e599b356f069313 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut <peter_e@gmx.net>.
  *
  * 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."),
index 88d872fbec2cbe6abc59fc8c96de42561fdd4366..565d8b277be152c5ad09109229a2bf0612f3a40e 100644 (file)
 # - 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
index bd8f1d21a1d0afbefa06d5984e6e10598132c544..d23aa563f79b4f5d15783315ac2fe13a1a494a41 100644 (file)
@@ -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)
index b940888784b27abdfa75562569358dc7c7eb5e98..ff2bd6316687a3440a0222aa9d03a55789a99bac 100644 (file)
@@ -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 $
  *
  *-------------------------------------------------------------------------
  */
 #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);