Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set application_name for postgres connections?

Tags:

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)?

like image 578
membersound Avatar asked May 19 '15 09:05

membersound


People also ask

Can Postgres handle multiple connections?

PostgreSQL Connection Limits At provision, Databases for PostgreSQL sets the maximum number of connections to your PostgreSQL database to 115. 15 connections are reserved for the superuser to maintain the state and integrity of your database, and 100 connections are available for you and your applications.

What is connection timeout in PostgreSQL?

The default connection timeout limit to PostgreSQL data sources is 30 seconds.


1 Answers

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.

like image 101
Cristian Sevescu Avatar answered Sep 20 '22 14:09

Cristian Sevescu