mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Add cluster_name GUC which is included in process titles if set.
When running several postgres clusters on one OS instance it's often inconveniently hard to identify which "postgres" process belongs to which postgres instance. Add the cluster_name GUC, whose value will be included as part of the process titles if set. With that processes can more easily identified using tools like 'ps'. To avoid problems with encoding mismatches between postgresql.conf, consoles, and individual databases replace non-ASCII chars in the name with question marks. The length is limited to NAMEDATALEN to make it less likely to truncate important information at the end of the status. Thomas Munro, with some adjustments by me and review by a host of people.
This commit is contained in:
@ -4131,6 +4131,29 @@ local0.* /var/log/postgresql
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry id="guc-cluster-name" xreflabel="cluster_name">
|
||||||
|
<term><varname>cluster_name</varname> (<type>string</type>)</term>
|
||||||
|
<indexterm>
|
||||||
|
<primary><varname>cluster_name</> configuration parameter</primary>
|
||||||
|
</indexterm>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Sets the cluster name that appears in the process title for all
|
||||||
|
processes in this cluster. The name can be any string of less than
|
||||||
|
<symbol>NAMEDATALEN</> characters (64 characters in a standard
|
||||||
|
build). Only printable ASCII characters may be used in the
|
||||||
|
<varname>application_name</varname> value. Other characters will be
|
||||||
|
replaced with question marks (<literal>?</literal>). No name is shown
|
||||||
|
if this parameter is set to the empty string <literal>''</> (which is
|
||||||
|
the default). This parameter can only be set at server start.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
The process title is typically viewed using programs like
|
||||||
|
<application>ps</> or, on Windows, <application>Process Explorer</>.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><varname>debug_print_parse</varname> (<type>boolean</type>)
|
<term><varname>debug_print_parse</varname> (<type>boolean</type>)
|
||||||
<indexterm>
|
<indexterm>
|
||||||
|
@ -91,6 +91,22 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
|
|||||||
system view to determine who is blocking whom.)
|
system view to determine who is blocking whom.)
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
If <xref linkend="guc-cluster-name"> has been configured the
|
||||||
|
cluster name will also be show in <command>ps</> output:
|
||||||
|
<screen>
|
||||||
|
$ psql -c 'SHOW cluster_name'
|
||||||
|
cluster_name
|
||||||
|
--------------
|
||||||
|
server1
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
$ ps aux|grep server1
|
||||||
|
postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: server1: writer process
|
||||||
|
...
|
||||||
|
</screen>
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
If you have turned off <xref linkend="guc-update-process-title"> then the
|
If you have turned off <xref linkend="guc-update-process-title"> then the
|
||||||
activity indicator is not updated; the process title is set only once
|
activity indicator is not updated; the process title is set only once
|
||||||
|
@ -198,6 +198,7 @@ static void assign_effective_io_concurrency(int newval, void *extra);
|
|||||||
static void assign_pgstat_temp_directory(const char *newval, void *extra);
|
static void assign_pgstat_temp_directory(const char *newval, void *extra);
|
||||||
static bool check_application_name(char **newval, void **extra, GucSource source);
|
static bool check_application_name(char **newval, void **extra, GucSource source);
|
||||||
static void assign_application_name(const char *newval, void *extra);
|
static void assign_application_name(const char *newval, void *extra);
|
||||||
|
static bool check_cluster_name(char **newval, void **extra, GucSource source);
|
||||||
static const char *show_unix_socket_permissions(void);
|
static const char *show_unix_socket_permissions(void);
|
||||||
static const char *show_log_file_mode(void);
|
static const char *show_log_file_mode(void);
|
||||||
|
|
||||||
@ -443,6 +444,7 @@ int temp_file_limit = -1;
|
|||||||
|
|
||||||
int num_temp_buffers = 1024;
|
int num_temp_buffers = 1024;
|
||||||
|
|
||||||
|
char *cluster_name = "";
|
||||||
char *data_directory;
|
char *data_directory;
|
||||||
char *ConfigFileName;
|
char *ConfigFileName;
|
||||||
char *HbaFileName;
|
char *HbaFileName;
|
||||||
@ -3261,6 +3263,17 @@ static struct config_string ConfigureNamesString[] =
|
|||||||
check_application_name, assign_application_name, NULL
|
check_application_name, assign_application_name, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
{"cluster_name", PGC_POSTMASTER, LOGGING_WHAT,
|
||||||
|
gettext_noop("Sets the name of the cluster which is included in the process title."),
|
||||||
|
NULL,
|
||||||
|
GUC_IS_NAME
|
||||||
|
},
|
||||||
|
&cluster_name,
|
||||||
|
"",
|
||||||
|
check_cluster_name, NULL, NULL
|
||||||
|
},
|
||||||
|
|
||||||
/* End-of-list marker */
|
/* End-of-list marker */
|
||||||
{
|
{
|
||||||
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
|
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
|
||||||
@ -9470,6 +9483,21 @@ assign_application_name(const char *newval, void *extra)
|
|||||||
pgstat_report_appname(newval);
|
pgstat_report_appname(newval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
check_cluster_name(char **newval, void **extra, GucSource source)
|
||||||
|
{
|
||||||
|
/* Only allow clean ASCII chars in the cluster name */
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
for (p = *newval; *p; p++)
|
||||||
|
{
|
||||||
|
if (*p < 32 || *p > 126)
|
||||||
|
*p = '?';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
show_unix_socket_permissions(void)
|
show_unix_socket_permissions(void)
|
||||||
{
|
{
|
||||||
|
@ -435,7 +435,8 @@
|
|||||||
# than the specified size in kilobytes;
|
# than the specified size in kilobytes;
|
||||||
# -1 disables, 0 logs all temp files
|
# -1 disables, 0 logs all temp files
|
||||||
#log_timezone = 'GMT'
|
#log_timezone = 'GMT'
|
||||||
|
#cluster_name = '' # added to process titles if nonempty
|
||||||
|
# (change requires restart)
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# RUNTIME STATISTICS
|
# RUNTIME STATISTICS
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "libpq/libpq.h"
|
#include "libpq/libpq.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
|
#include "utils/guc.h"
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
bool update_process_title = true;
|
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
|
* apparently setproctitle() already adds a `progname:' prefix to the ps
|
||||||
* line
|
* line
|
||||||
*/
|
*/
|
||||||
snprintf(ps_buffer, ps_buffer_size,
|
#define PROGRAM_NAME_PREFIX ""
|
||||||
"%s %s %s ",
|
|
||||||
username, dbname, host_info);
|
|
||||||
#else
|
#else
|
||||||
snprintf(ps_buffer, ps_buffer_size,
|
#define PROGRAM_NAME_PREFIX "postgres: "
|
||||||
"postgres: %s %s %s ",
|
|
||||||
username, dbname, host_info);
|
|
||||||
#endif
|
#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);
|
ps_buffer_cur_len = ps_buffer_fixed_size = strlen(ps_buffer);
|
||||||
|
|
||||||
set_ps_display(initial_str, true);
|
set_ps_display(initial_str, true);
|
||||||
|
@ -224,6 +224,7 @@ extern int temp_file_limit;
|
|||||||
|
|
||||||
extern int num_temp_buffers;
|
extern int num_temp_buffers;
|
||||||
|
|
||||||
|
extern char *cluster_name;
|
||||||
extern char *data_directory;
|
extern char *data_directory;
|
||||||
extern char *ConfigFileName;
|
extern char *ConfigFileName;
|
||||||
extern char *HbaFileName;
|
extern char *HbaFileName;
|
||||||
|
Reference in New Issue
Block a user