How to set application_name for postgres connections?

membersound picture membersound · May 19, 2015 · Viewed 14.3k times · Source

I'm using tomcat connection pool org.apache.tomcat.jdbc.pool.DataSource. The connections appear in my database pg_stat_activity with empty application_name.

How could I set that application name in my java app, so I know where each connection comes from (as there will be multiple applications accessing the same db)?

Answer

Cristian Sevescu picture Cristian Sevescu · May 19, 2015

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.