proctitle patch (useful)

From: Jim Mercer <jim(at)reptiles(dot)org>
To: pgsql-general(at)postgreSQL(dot)org
Subject: proctitle patch (useful)
Date: 1999-12-24 16:53:17
Message-ID: 19991224115317.Z4188@reptiles.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


when trying to diagnose problems, it is sometimes difficult to identify which
backend process is connected to what client process.

here is a patch for src/backend/commands/variable.c

this patch adds a new variable PROCTITLE.

this allows client processes to set the backend proctitle to something useful:

$ ps auxww | grep post
11080 ?? Is 0:00.06 postmaster -S -i -d 3 -o -F (postgres)
11125 ?? I 0:00.42 (postgres)

$ psql database
database=> SET PROCTITLE = 'testing proctitle 123';
SET VARIABLE
database=>

$ ps ax | grep post
11080 ?? Is 0:00.06 postmaster -S -i -d 3 -o -F (postgres)
11125 ?? I 0:00.21 postmaster: testing proctitle 123 (postgres)

i'm not overly familiar with GNU configure, so i'll leave it up to the people
who manage the source to figure out a clean portable way of enabling the
feature.

also note: not all systems have setproctitle(), although there is usually
a way to do it.

--
[ Jim Mercer jim(at)reptiles(dot)org +1 416 506-0654 ]
[ Reptilian Research -- Longer Life through Colder Blood ]
[ Don't be fooled by cheap Finnish imitations; BSD is the One True Code. ]

*** variable.c.orig Fri Dec 24 11:23:42 1999
--- variable.c Fri Dec 24 11:23:10 1999
***************
*** 21,26 ****
--- 21,32 ----
#include "mb/pg_wchar.h"
#endif

+ #define PROCTITLE
+ #ifdef PROCTITLE
+ static bool show_title(void);
+ static bool reset_title(void);
+ static bool parse_title(const char *);
+ #endif
static bool show_date(void);
static bool reset_date(void);
static bool parse_date(const char *);
***************
*** 304,309 ****
--- 310,370 ----
return TRUE;
}

+ #ifdef PROCTITLE
+ /*
+ *
+ * PROCTITLE
+ *
+ */
+ static char *ProcTitle = NULL;
+ static bool
+ parse_title(const char *value)
+ {
+ if (value == NULL)
+ {
+ reset_title();
+ return TRUE;
+ }
+
+ if (ProcTitle != NULL)
+ free(ProcTitle);
+
+ ProcTitle = strdup(value);
+ setproctitle(ProcTitle);
+
+ return TRUE;
+ }
+
+ static bool
+ show_title()
+ {
+ char buf[64];
+
+ strcpy(buf, "DateStyle is ");
+ if (ProcTitle != NULL)
+ strcat(buf, ProcTitle);
+ else
+ strcat(buf, "NULL");
+
+ elog(NOTICE, buf, NULL);
+
+ return TRUE;
+ }
+
+ static bool
+ reset_title()
+ {
+ if (ProcTitle != NULL)
+ {
+ free(ProcTitle);
+ ProcTitle = NULL;
+ }
+
+ setproctitle(ProcTitle);
+ return TRUE;
+ }
+ #endif
+
/*
*
* DATE_STYLE
***************
*** 539,544 ****
--- 600,610 ----
} VariableParsers[] =

{
+ #ifdef PROCTITLE
+ {
+ "proctitle", parse_title, show_title, reset_title
+ },
+ #endif
{
"datestyle", parse_date, show_date, reset_date
},

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 1999-12-24 17:09:31 Re: [GENERAL] proctitle patch (useful)
Previous Message Natalya Makushina 1999-12-24 13:19:27 Can not destroy db