在PGSQL JDBC中的SetClientInfo方法——这些信息在数据库中的哪里存储?

huangapple go评论69阅读模式
英文:

In PGSQL JDBC SetClientInfo -- where is this information set stored on the database?

问题

JDBC PGSQL驱动程序的文档解释了它会将setClientInfo中设置的信息存储在数据库的适当位置。在运行在数据库上的查询中,是否有一种方法可以访问这个位置呢?例如,如果触发器被触发,是否有一种方法可以在不使用应用程序层的情况下在查询中获取连接上设置的属性?

驱动程序会将指定的值存储在数据库的适当位置,例如在特殊寄存器、会话参数或系统表列中。为了提高效率,驱动程序可能会延迟将该值设置到数据库,直到下次执行或准备语句为止。除了将客户端信息存储在数据库的适当位置之外,这些方法不会以任何方式更改连接的行为。提供给这些方法的值仅用于会计、诊断和调试目的。

https://jdbc.postgresql.org/documentation/publicapi/index.html?org/postgresql/jdbc/PgConnection.html

我们已经尝试查找有关JDBC驱动程序的任何文档,但找不到记录这一点的位置,也不知道如何控制(如果可能的话)。

英文:

The documentation for the JDBC PGSQL driver explains that it stores information set in setClientInfo in a suitable location. Is there a way to access this location from within Queries that are running on the DB. For example, if a trigger gets run, is there a way to grab a property that we set on the connection into the query without the use of the application layer?

> The driver stores the value specified in a suitable location in the database. For example in a special register, session parameter, or system table column. For efficiency the driver may defer setting the value in the database until the next time a statement is executed or prepared. Other than storing the client information in the appropriate place in the database, these methods shall not alter the behavior of the connection in anyway. The values supplied to these methods are used for accounting, diagnostics and debugging purposes only.

https://jdbc.postgresql.org/documentation/publicapi/index.html?org/postgresql/jdbc/PgConnection.html

We have tried looking through any documentation around the JDBC driver and cannot find a location where this is documented, or how to control if possible.

答案1

得分: 0

It's "stored" in the session as a configuration setting with the name application_name

You can retrieve it using:

current_setting('application_name')

The JDBC driver doesn't do anything special. It just runs set application_name = '...'; after the connection has been established.

英文:

It's "stored" in the session as a configuration setting with the name application_name

You can retrieve it using:

current_setting('application_name')

The JDBC driver doesn't do anything special. If just runs set application_name = '...'; after the connection has been established.

huangapple
  • 本文由 发表于 2023年2月14日 07:37:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442166.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定