proctitle patch (useful) - Mailing list pgsql-general
From | Jim Mercer |
---|---|
Subject | proctitle patch (useful) |
Date | |
Msg-id | 19991224115317.Z4188@reptiles.org Whole thread Raw |
Responses |
Re: [GENERAL] proctitle patch (useful)
Re: [GENERAL] proctitle patch (useful) |
List | 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@reptiles.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 },
pgsql-general by date: