1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Add support for an application_name parameter, which is displayed in

pg_stat_activity and recorded in log entries.

Dave Page, reviewed by Andres Freund
This commit is contained in:
Tom Lane
2009-11-28 23:38:08 +00:00
parent cb98f61538
commit 8217cfbd99
16 changed files with 479 additions and 95 deletions

View File

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.523 2009/10/21 20:38:58 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.524 2009/11/28 23:38:07 tgl Exp $
*
*--------------------------------------------------------------------
*/
@ -168,6 +168,7 @@ static bool assign_maxconnections(int newval, bool doit, GucSource source);
static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
static bool assign_effective_io_concurrency(int newval, bool doit, GucSource source);
static const char *assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source);
static const char *assign_application_name(const char *newval, bool doit, GucSource source);
static char *config_enum_get_options(struct config_enum * record,
const char *prefix, const char *suffix,
@ -378,6 +379,8 @@ char *pgstat_temp_directory;
char *default_do_language;
char *application_name;
int tcp_keepalives_idle;
int tcp_keepalives_interval;
int tcp_keepalives_count;
@ -2534,6 +2537,16 @@ static struct config_string ConfigureNamesString[] =
"plpgsql", NULL, NULL
},
{
{"application_name", PGC_USERSET, LOGGING,
gettext_noop("Sets the application name to be reported in statistics and logs."),
NULL,
GUC_IS_NAME | GUC_NOT_IN_SAMPLE
},
&application_name,
"", assign_application_name, NULL
},
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
@ -7717,4 +7730,28 @@ assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source)
return newval;
}
static const char *
assign_application_name(const char *newval, bool doit, GucSource source)
{
if (doit)
{
/* Only allow clean ASCII chars in the application name */
char *repval = guc_strdup(ERROR, newval);
char *p;
for (p = repval; *p; p++)
{
if (*p < 32 || *p > 126)
*p = '?';
}
/* Update the pg_stat_activity view */
pgstat_report_appname(repval);
return repval;
}
else
return newval;
}
#include "guc-file.c"