How to set application_name for postgres connections? How to set application_name for postgres connections? postgresql postgresql

How to set application_name for postgres connections?


You could specify the application name in the connection string.
Documentation here.

Example:

jdbc:postgresql://localhost:5435/DBNAME?ApplicationName=MyApp

Take care: the param names are case sensitive.


Use set command:

set application_name to my_application;


You can add this to the JDBC URL that you use in your connection pool definition:

jdbc:postgresql://localhost/postgres?ApplicationName=my_app

If you want to change it dynamically e.g. to reflect different modules inside your application, the you can use the SET command as shown by klin.