如何跟踪 db2 特定连接的 sql 命令?
我正在设置中央构建服务器。服务器负责生成将部署到所有环境的官方构建工件。对于其中一个应用程序,有一个写入数据库的构建步骤。在部署时,我们需要在适当的环境中运行此构建步骤。由于稍后可靠地重现此构建步骤很困难/昂贵,因此诞生了在部署时仅捕获 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 p6spy:
http://www.p6spy.com/
Have a look at p6spy:
http://www.p6spy.com/
如果在填充 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.