开发者

Oracle total query executions with count and execution time (for Java program)

开发者 https://www.devze.com 2023-03-07 11:21 出处:网络
I want to know total how many queries got executed with its count and execution time for my Java program开发者_如何学Python (I dont have the source code).

I want to know total how many queries got executed with its count and execution time for my Java program开发者_如何学Python (I dont have the source code).

I am planning to write PL/SQL which joins gv$session and gv$sql, logging output to one of the table. After program execution ends I will query the table to get more details.

But I wanted to know whether Oracle has any default utility to get similar report already? I was looking at AWR reporting for Oracle but didn't get easy documentation for the same.


I'd go with

DBMS_SESSION.SESSION_TRACE_ENABLE (waits => true);

On the database server you will get a file generated (in the directory indicated by user_dump_dest in v$parameter) that will contain a trace.

Run that trace through the tkprof utility (database utility on the DB server) and it will give you all the SQLs, how many times they were executed, how long they spent executed and a breakdown of what that time was spent on.

The drawback of v$sql (or gv$sql for RAC) is that (1) some queries might be aged out, especially for a long running process and (2) potential 'interference' from other sessions if you don't haev exclusive access to the DB.

If you don't want to get into messaing around with files, from v$session you can also drill down to v$sessstat and v$session_event which can offer some useful tidbits.

select event, sum(round(time_waited/(100*60),2)) time_mins, wait_class
from v$session_event
where sid in (221)
group by event, wait_class
order by 2 desc;

select sid, name, value from v$sesstat s 
  join v$statname n on n.statistic# = s.statistic#
where s.sid in (221)
and name in ('consistent gets','sorts (rows)','execute count',
        'parse count (total)','user calls','user commits','user rollbacks'
order by value desc;
0

精彩评论

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