如何跟踪 db2 特定连接的 sql 命令?

发布于 2024-08-18 20:23:42 字数 465 浏览 3 评论 0原文

我正在设置中央构建服务器。服务器负责生成将部署到所有环境的官方构建工件。对于其中一个应用程序,有一个写入数据库的构建步骤。在部署时,我们需要在适当的环境中运行此构建步骤。由于稍后可靠地重现此构建步骤很困难/昂贵,因此诞生了在部署时仅捕获 sql 运行的 sql 脚本的想法。

我无法控制生成 sql 的源代码。它是一个使用hibernate的java程序。我还没有找到将 log4j.properties/log4j.xml 放在哪里来使用 hibernate 跟踪功能。准备好的语句显示“?”可能存在问题而不是实际值。

有人有 DB2 活动监视器的经验以及如何使用它吗?或者是否有其他(更简单的)选项,例如替换 hibernate 配置中的 db2 驱动程序?不过,我仍然想使用 DB2Dialect 驱动程序。

编辑:我无法控制数据库结构。数据库结构可能会更新,或者进程将来可能会写入不同的表。这不应该影响我现在设置的解决方案。

I am in the process of setting up a central build server. The server is responsible to produce the official build artifacts that will be deployed to all environment. For one of the applications there is an build step that writes to a database. At deploy time we would need to run this build step to the appropriate environment. Since it is difficult/expensive to reliably reproduce this build step later the idea was born to capture the sql run just the sql script later at deployment time.

I have no control over the source code that generates the sql. It is an java program that uses hibernate. I haven't found out yet, where to put the log4j.properties/log4j.xml to use the hibernate trace functionality. And there might be a problem with prepared statements showing '?' instead of the actual value.

Does anyone have experience with Activity Monitor of DB2 and how to use it? Or is there other (easier) options like replacing the db2 driver in the hibernate configuration? I still want to use the DB2Dialect driver, though.

EDIT: I don't have control over the database structure. The database structure might be updated or the process might write to different tables in the future. This should not impact the solution I am setting up now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2024-08-25 20:23:42

看看 p6spy:

P6Spy 是一个开源框架
支持拦截的应用程序
并可选择修改数据库
声明。 P6Spy 发行版
包括以下模块:

P6日志。 P6Log 拦截并记录
任何应用程序的数据库语句
使用 JDBC。这个应用程序是
对于开发人员特别有用
监控生成的 SQL 语句
EJB 服务器,使开发人员能够
编写代码以达到最大
服务器上的效率。 P6Spy 是
设计为在几分钟内安装
并且不需要更改代码。

http://www.p6spy.com/

Have a look at p6spy:

P6Spy is an open source framework to
support applications that intercept
and optionally modify database
statements. The P6Spy distribution
includes the following modules:

P6Log. P6Log intercepts and logs the
database statements of any application
that uses JDBC. This application is
particularly useful for developers to
monitor the SQL statements produced by
EJB servers, enabling the developer to
write code that achieves maximum
efficiency on the server. P6Spy is
designed to be installed in minutes
and requires no code changes.

http://www.p6spy.com/

那些过往 2024-08-25 20:23:42

如果在填充 id 之前该表不存在/为空,您还可以导出包含记录的结果表,并在部署时将其导入到生产数据库中。

正如您已经说过的,使用执行的操作日志来确定表的内容可能是不可能的。记录准备好的语句将不包含绑定数据,如果执行的不仅仅是简单的插入,您可能会被迫实现部分 SQL 来重现您记录的内容。

If the table is non-existent / empty before is id filled, you could also export the resulting table including records and import that into you production database at deploy time.

As you already said, it might prove impossible to determine the contents of the tables using a log of actions performed. Logging prepared statements will not contain the bound data and if more than simple inserts are executed you might be forced to implement parts of SQL to reproduce what you recorded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文