46

I want to set the application name of the connections of my application. So when I list the rows in pg_stat_activity I can have a non empty application_name column.

I have setup the following JDBC url for connecting to my Postgresql database:

jdbc:postgresql://localhost:5435/MyDB?application-name=MyApp

I have tried also this url with no more success.

jdbc:postgresql://localhost:5435/MyDB?application_name=MyApp

What is the correct parameter name ?

Here is my JDBC driver version: 9.1-901.jdbc4

3
  • 2
    stackoverflow.com/questions/7145908/… Commented Oct 7, 2013 at 12:30
  • have you tried to pass the application_name with properties?! Commented Oct 7, 2013 at 12:31
  • @user2511414 I have already checked the question you suggest. properties is not an option. Commented Oct 7, 2013 at 12:39

1 Answer 1

72

Looking at the PostgreSQL JDBC 9.1 documentation, connection parameters, the correct property name in the JDBC url is ApplicationName:

ApplicationName = String

Specifies the name of the application that is using the connection. This allows a database administrator to see what applications are connected to the server and what resources they are using through views like pg_stat_activity

So try:

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

Be aware some comments suggest that this is broken in the 9.1 version driver. Given it is a more than 5 year old version, you should upgrade to a newer version anyway. Check https://jdbc.postgresql.org/ for the latest version and use that.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried this parameter (ApplicationName or ApplicationName) with no much success :(
In that case, I'd suggest to file a bug with postgresql
This works for me with this version of the PG driver: 9.2-1003-jdbc4.
Must be broken for 9.1, see also stackoverflow.com/a/39099066/32453
@rogerdpack I added a note to that effect, however given the 9.1 driver is almost 7 years old, you should be using a newer version than that anyway. The driver version is not tied to a specific PostgreSQL version, which is also why they now changed the version scheme to 42.x.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.