1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +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:
Andres Freund
2014-06-29 14:15:09 +02:00
parent a6d488cb53
commit 51adcaa0df
6 changed files with 86 additions and 7 deletions

View File

@ -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 bool check_application_name(char **newval, void **extra, GucSource source);
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_log_file_mode(void);
@ -443,6 +444,7 @@ int temp_file_limit = -1;
int num_temp_buffers = 1024;
char *cluster_name = "";
char *data_directory;
char *ConfigFileName;
char *HbaFileName;
@ -3261,6 +3263,17 @@ static struct config_string ConfigureNamesString[] =
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 */
{
{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);
}
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 *
show_unix_socket_permissions(void)
{