简体   繁体   English

Oracle 10g,查看发送到数据库的确切查询

[英]Oracle 10g, see exact query sent to database

I have an application from a third party that writes to the Oracle database. 我有一个来自第三方的应用程序,该应用程序可以写入Oracle数据库。 One component of the application returns no data given particular parameters, while the other component of the application does return data with those same parameters. 在给定特定参数的情况下,应用程序的一个组件不返回任何数据,而在应用程序的另一组件的情况下则返回具有相同参数的数据。 Nobody has the source code to this application, but it can be seen that the database has the proper information in it. 没有人拥有此应用程序的源代码,但是可以看出数据库中包含正确的信息。

The misbehaving component gets ORA-01403 returned from the oracle database server, which means no data found, but can be related to a syntax error, as seen by a packet sniffer I installed. 行为异常的组件会从oracle数据库服务器返回ORA-01403 ,这意味着未找到数据,但可能与语法错误相关,如我安装的数据包嗅探器所示。

I want to see the differences in the queries that the different components of the application actually generate. 我想查看应用程序的不同组件实际生成的查询中的差异。

Would also like to run these queries on the command line or in some other database viewer to see what gets returned. 还希望在命令行或其他一些数据库查看器中运行这些查询,以查看返回了什么。

How can I monitor the database with a trace that actually shows the queries being made? 如何使用实际显示正在查询的跟踪来监视数据库? I would also like to isolate these by IP address or source. 我也想按IP地址或来源将其隔离。

Using Oracle 10g Enterprise 使用Oracle 10g企业版

I found this worked well for an AWS Oracle RDS instance. 我发现这对于AWS Oracle RDS实例非常有效。 I ran the tcpdump from the linux instances connecting to the db... 我从连接到数据库的Linux实例运行了tcpdump ...

tcpdump tcp port 1521 -s 0 -l -w -  | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
  if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
    if (defined $q) { print "$q\n"; }
    $q=$_;
  } else {
    $_ =~ s/^[ \t]+//; $q.=" $_";
  }
}'

Hope that helps someone else. 希望对别人有帮助。

IIRC, TOAD will do what you want. IIRC,TOAD将做您想要的。

Additionally, there is a free trial - http://www.quest.com/toad-for-oracle/software-downloads.aspx 此外,还有一个免费试用版-http: //www.quest.com/toad-for-oracle/software-downloads.aspx

There are other interesting downloads (search oracle free toad) but I can't be sure of their legitimacy. 还有其他有趣的下载(搜索oracle免费toad),但我不确定它们的合法性。

If your client connects directly to the database without any middle-tier layer, then you have two pretty much straightforward options. 如果您的客户端直接连接到数据库而没有任何中间层,则您有两个非常简单的选择。

First of all, figure out required session's ID using v$session view, and then either find your query in v$sql / v$sql_text by its hash value (you can check description of each in the docs ), or enable session-level sql trace (1) (2) and get your queries in a plain text trace file. 首先,使用v$session视图找出所需会话的ID,然后根据其哈希值在v$sql / v$sql_text查找查询(可以在docs中检查每个说明),或启用会话级sql trace (1) (2),并在纯文本跟踪文件中获取查询。

If you have a middle-tier then things get slightly more complicated but only in terms of figuring out the session you need to trace. 如果您有一个中间层,那么事情会变得稍微复杂一些,但是仅在弄清楚您需要跟踪的会话方面。 You can always enable system-wide tracing though. 但是,您始终可以启用系统范围的跟踪。

A little late to the party but I ran into this problem and didn't want to installe something on the database server for a one off use, I wound up using wireshark; 聚会晚了一点,但是我遇到了这个问题,不想在数据库服务器上安装某些东西以供一次性使用。 the queries were sent in plaintext and perfectly readable. 查询以纯文本格式发送,并且可读性强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM