Tuning a Wait Session

When I was about to bring down the server in an immediate mode for the start of the weekend maintenace window, I saw a user session is still active where he was trying to run a query. This query, in the past, took a minute or so and now its more than half hour. All I could do is kill it.

The thing I am wondering about is, if time permits, the approach towards tuning it. How do I find out which object is he accessing, is there a wait for any latches or is it undergoing any full table scans or is it waiting for any resource to be freed and etc..

----->
The first thing you should do is select * from v$session_wait where sid = [his session ID]. We can go from there. Run that query multiple times a few seconds apart.

----->
****************
To find out what sql the problem session(s) are executing, run the following query:

select s.sid, event, wait_time, w.seq#, q.sql_text
from v$session_wait w, v$session s, v$process p, v$sqlarea q
where s.paddr=p.addr and
s.sid=&p and
s.sql_address=q.address;
****************

I suggest you drop v$process from that query because you're not using anything in it. And suggest you change v$sqlarea to v$sql because the latter is much less expensive.

To be more accurate, v$sql (or v$sqlarea) contains the SQL the session either is running or last ran, depending on the info in v$session_wait.

Have a Oracle Question
Do you have an Oracle Question?

Oracle Books
Oracle Certification, Database Administration, SQL, Application, Programming Reference Books

Oracle Application
Oracle Application Hints and Tips

Oracle Home
Oracle Database, SQL, Application, Programming Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.