How to set application name in a Postgresql JDBC url?

前端 未结 1 1198
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 16:09

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_na

相关标签:
1条回答
  • 2020-12-15 16:36

    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.

    0 讨论(0)
提交回复
热议问题