On 5 May 2014 10:49, Thomas Munro <mu...@ip9.org> wrote: > On 5 May 2014 10:10, Andres Freund <and...@2ndquadrant.com> wrote: > >> I guess the question is where this should be available as well. At the >> very least I'd want to reference it in log_line_prefix as well? >> > > Good idea, I will look into that. >
See v2 patch attached which lets you use %C for cluster name in the log prefix. Maybe it would be overkill, but seeing the various responses about which information belongs in the ps string, I guess we could also use a format string with %blah fields for that. Then the Debian/Ubuntu package users who tend to think of the major version + name as the complete cluster identifier could use "[%V/%C] ..." to get "postgres: [9.3/main] ...", and others could throw in a "%P" to see a port number.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 977fc66..0adfee7 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -2345,6 +2345,12 @@ log_line_prefix(StringInfo buf, ErrorData *edata) else appendStringInfo(buf, "%lx.%x", (long) (MyStartTime), MyProcPid); break; + case 'C': + if (padding != 0) + appendStringInfo(buf, "%*s", padding, cluster_name); + else + appendStringInfoString(buf, cluster_name); + break; case 'p': if (padding != 0) appendStringInfo(buf, "%*d", padding, MyProcPid); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 15020c4..7f7fd52 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -449,6 +449,7 @@ int temp_file_limit = -1; int num_temp_buffers = 1024; +char *cluster_name; char *data_directory; char *ConfigFileName; char *HbaFileName; @@ -3091,6 +3092,17 @@ static struct config_string ConfigureNamesString[] = }, { + {"cluster_name", PGC_POSTMASTER, CUSTOM_OPTIONS, + gettext_noop("Sets the name of the cluster that appears in 'ps' output."), + NULL, + GUC_IS_NAME + }, + &cluster_name, + "", + NULL, NULL, NULL + }, + + { {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS, gettext_noop("Sets the server's data directory."), NULL, diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 6294ca3..ead7ea4 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -29,6 +29,7 @@ #include "libpq/libpq.h" #include "miscadmin.h" #include "utils/ps_status.h" +#include "utils/guc.h" extern char **environ; bool update_process_title = true; @@ -264,15 +265,24 @@ init_ps_display(const char *username, const char *dbname, * apparently setproctitle() already adds a `progname:' prefix to the ps * line */ - snprintf(ps_buffer, ps_buffer_size, - "%s %s %s ", - username, dbname, host_info); +#define PROGRAM_NAME_PREFIX "" #else - snprintf(ps_buffer, ps_buffer_size, - "postgres: %s %s %s ", - username, dbname, host_info); +#define PROGRAM_NAME_PREFIX "postgres: " #endif + if (*cluster_name == '\0') + { + snprintf(ps_buffer, ps_buffer_size, + PROGRAM_NAME_PREFIX "%s %s %s ", + username, dbname, host_info); + } + else + { + snprintf(ps_buffer, ps_buffer_size, + PROGRAM_NAME_PREFIX "[%s] %s %s %s ", + cluster_name, username, dbname, host_info); + } + ps_buffer_cur_len = ps_buffer_fixed_size = strlen(ps_buffer); set_ps_display(initial_str, true); diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index be68f35..639288a 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -223,6 +223,7 @@ extern int temp_file_limit; extern int num_temp_buffers; +extern char *cluster_name; extern char *data_directory; extern char *ConfigFileName; extern char *HbaFileName;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers