Reputation: 2728
How can i check the Query running from long time & steps of tuning the query? (Oracle)
Upvotes: 1
Views: 442
Reputation: 11
If you do not want to use OEM, then you can query and find out.
First find the long running query. If it's currently being executing, You can join gv$session to find which session running since long time. Then go to gv$sql to find SQL details. You need to look last_call_et column.If SQL executed some time inpast you can use dba_hist_snapshot ,dba_hist_sqlstat ,DBA_HIST_SQLTEXT tables to find offending SQL.
Once you get query, you can check what plan it's picking from dba_hist_sql_plan table if this SQL executed in past or from gv$sql_plan if it's currently executing.
Now you analyze execution plan and see if it's using right index, join etc. If not tune those.
Let me know which step you have the problem. I can help you in answering those.
Upvotes: 0
Reputation: 146229
Unfortunately your question is not expressed clearly. The other answers have already tackled the issue of tuning a known bad query, but another interpretation is that you want to monitor your database to find poorly performing queries.
If you don't have Enterprise Edition with the Diagnostics pack - and not many of us do - your best bet is to run statspack snapshots on a reqular basis. This will give you a lot of information about your system, including which queries take a long time to complete and which queries consume a lot of your system's resources. You can find out more about statspack here.
Upvotes: 0
Reputation: 502
You can capture the query by selecting from v$sql or v$sqltext. If you are not familiar with it, look up 'Explain Plan' in the Oracle documentation. There should be plenty on it in the performance tuning guide.
Have a look at Quest Software's Toad for a third party tool that helps in this area too.
K
Upvotes: 1
Reputation: 95133
explain plan for select ....
to see what Oracle is doing with your query.Upvotes: 2