10

I'm new of oracle and now I'm becoming crazy with the following situation. I'm working on a oracle 11g database and many times is happening that I run a query with sql developer and this is correctly executed in 5/6 seconds, others time instead the same query take 300/400 second to be executed. There is some tools to debug what is happening when the query employs 300/400 second?

Update 1 This is my sql developer screenshot the problem seems be direct path read temp

enter image description here

Update 2 report

Update 3 report2

Any suggestion?

6
  • Can you run this and post the output? select dbms_sqltune.report_sql_monitor(sql_id => 'gvqwuz1u29s0f', type => 'text') from dual;
    – Jon Heller
    May 13, 2015 at 17:15
  • 2
    just a guess (and I can't see your image btw), if sometimes you run a query and its much quicker than other times, you're probably pulling blocks from cache, and the slower execution could mean blocks were aged out and had to be reloaded. Just a guess, but running a trace will tell you more whats happening
    – tbone
    May 13, 2015 at 19:48
  • @JonHeller I updated my question with the report of the following sql statementdbms_sqltune.report_sql_monitor(sql_id => 'SQL_ID', type => 'text') from dual;
    – Skizzo
    May 14, 2015 at 7:35
  • @Skizzo The file got cutoff at 4K bytes. Can you try to export it again?
    – Jon Heller
    May 14, 2015 at 18:12
  • @Skizzo The file is still cut off. Can you add the text to the question instead of using an external site?
    – Jon Heller
    May 15, 2015 at 17:42

3 Answers 3

9

Try setting a trace. User being whatever user is experiencing the delay
As sys:

GRANT ALTER SESSION TO USER;

As the user executing the trace:

ALTER SESSION SET EVENTS '10046 trace name context forever, level 8';
ALTER SESSION SET TRACEFILE_IDENTIFIER = "MY_TEST_SESSION";

Produce the error/issue, then as the user testing:

ALTER SESSION SET EVENTS '10046 trace name context off';

As system find out where the trace files are kept:

show parameter background_dump_dest;

Go to that directory and look for .trc/.trm files containing MY_TEST_SESSION. For example ORCL_ora_29772_MY_TEST_SESSION.trc.
After that tkprof those files. In linux:

tkprof ORCL_ora_29772_MY_TEST_SESSION.trc output=ORCL_ora_29772_MY_TEST_SESSION.tkprof explain=user/password sys=no

Read the tkprof file and it will will show you wait times on given statements.
For more info on TKPROF read this. For more info on enabling/disabling a trace read this.

3

The best tool is Real-Time SQL Monitoring. It does not require changing code or access to the operating system. The only downside is it requires licensing the Tuning Pack.

Compare this single line of code with the trace steps in the other answer. Also, the output looks much nicer.

select dbms_sqltune.report_sql_monitor(sql_id => 'your sql id', type => 'text') from dual;

There's almost never a need to use trace in 11g and beyond.

5
  • 2
    So the only downside is $15k? ;)
    – mmmmmpie
    Apr 30, 2015 at 9:50
  • @mmmmmpie Yep, that's it! Hey, your company already paid a few million for Oracle, might as well get this cool option. :) If the tuning pack isn't available, you can sort of recreate the feature with an open source tool I built. It depends on AWR though, which also requires money. Anyway, the point is that Oracle has all these mechanisms silently recording performance data. If possible, using one of them is usually more convenient than dealing with tracing.
    – Jon Heller
    Apr 30, 2015 at 16:56
  • I can confirm though if you deal with oracle support they will want tkprof traces, nothing else.
    – mmmmmpie
    Apr 30, 2015 at 18:11
  • 1
    @mmmmmpie You're right about Oracle support. Last week my coworkers spent days with them trying to trace something. I used monitoring and solved it in a couple of hours. Traces can take a long time to setup - in many environments it's difficult to get permission to change or re-run anything. Why spend all that time when monitoring can get you the wait information in a few seconds? But in the end it's useful to know all these tools.
    – Jon Heller
    Apr 30, 2015 at 18:37
  • Agreed. Unfortunately traces are the world we live in. I can't remember using an oracle instance without tkprof (I started with 9i) and support is the same way. Application traces are usually the trickiest to trace but good applications will have a seeded ability inside of them to trace that users distinct session as opposed to tracing the entire app DB account.
    – mmmmmpie
    May 1, 2015 at 11:54
1

This behaviour can be caused by cardinality feedback bugs / issues in 11gR2. I had a similar issue. You can test if this is the case by turning off this feature with _optimizer_use_feedback=false

Also try applying the latest updates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.