开发者

Display application name in Session Information when connecting via JDBC

I create a connection to a postgres 9 database using the stardard JDBC driver.

...
Connection myCon = Dr开发者_运维知识库iverManager.getConnection("jdbc:postgresql://localhost/test?&user=test&password=test"); 
...

When I check the server status with PgAdmin and display all database sessions, I can see that the "Application Name" is not set for my Session. Is there a way to set the application name in the JDBC connection?


That is possible to set application name as connection parameter since Postgres JDBC 9.1dev-900:

Add support for setting application_name on both connection startup and later through Connection.setClientInfo. (jurka)

ex: jdbc:postgresql://localhost:5432/DbName?ApplicationName=MyApp

or Connection.setClientInfo("ApplicationName", "My App")

For previous versions you could do this by setting application_name runtime parameter:

s.execute("SET application_name TO 'MyApp'");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜