close

Menu

Contact Info

Folow us on social

How to set application_name for psql command line utility?

  • Denish Patel
  • 27th April 2020
  • Database, postgres, postgresql

If you are using psql command line utility and wonder how you can set application_name…

If you try to set application_name using psql variable, it doesn’t work …

$ psql -d postgres -U elephas --variable=application_name=elephas_backupĀ 
postgres=# show application_name ;
application_name
------------------
psql
(1 row)
Option-1:
psql -U elephas -d 'dbname=postgres application_name=elephas_backup' 
postgres=# show application_name ;
 application_name
------------------
 elephas_backup
(1 row)
Option-2:
You can export PGAPPNAME variable before making a connection ..

$export PGAPPNAME=myapp
$ psql -d postgres
Type "help" for help.

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

Hopefully, it will help you to track down psql connections coming from various places.

Leave a comment

Your email address will not be published. Required fields are marked *