application_name

A GUC parameter indicating the name of the client application

application_name is a GUC parameter indicating the name of the client application.

application_name was added in PostgreSQL 9.0 (initial commit 8217cfbd).

Usage

application_name is a purely advisory settting which can be provided by any client application. It can consist of up to 63 printable ASCII characters (any other characters will be displayed as ?).

While application_name can be configured like any other GUC, normally it is provided by applications as part of the libpq conninfo string, which will override any existing configuration setting. It can also be provided via the environment variable PGAPPNAME.

If neither application_name nor PGAPPNAME are set, but fallback_application_name is, the latter will be used as the effective application name.

application_name will be displayed in the eponymous field in the system catalogue view pg_stat_activity. It will be included in CSV log output and in other log output via the log_line_prefix parameter.

Examples

postgres$ psql
psql (13beta3)
Type "help" for help.

postgres=# ALTER SYSTEM SET application_name ='foo';
ALTER SYSTEM

postgres=# SELECT pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

postgres=# SHOW application_name;
 application_name 
------------------
 psql
(1 row)

postgres=# SELECT datname, usename, application_name 
             FROM pg_stat_activity 
            WHERE pid = pg_backend_pid();
 datname  | usename  | application_name 
----------+----------+------------------
 postgres | postgres | psql
(1 row)

postgres=# \q

postgres$ psql -d 'application=myapp'
psql (13beta3)
Type "help" for help.

postgres=# SHOW application_name;
 application_name 
------------------
 myapp
(1 row)

postgres$ psql -d 'application='
psql (13beta3)
Type "help" for help.

postgres=# SHOW application_name;
 application_name 
------------------
 foo
(1 row)

Categories

Database connections, GUC configuration item, Logging

See also

fallback_application_name