How to check Oracle database for long running queries

前端 未结 8 1735
半阙折子戏
半阙折子戏 2020-12-02 04:03

My application, which uses an Oracle database, is going slow or appears to have stopped completely.

How can find out which queries are most expensive, so I can inves

相关标签:
8条回答
  • 2020-12-02 04:47

    You can check the long-running queries details like % completed and remaining time using the below query:

     SELECT SID, SERIAL#, OPNAME, CONTEXT, SOFAR, 
     TOTALWORK,ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE" 
     FROM V$SESSION_LONGOPS 
     WHERE OPNAME NOT LIKE '%aggregate%' 
           AND TOTALWORK != 0 
           AND SOFAR <> TOTALWORK;
    

    For the complete list of troubleshooting steps, you can check here:Troubleshooting long running sessions

    0 讨论(0)
  • 2020-12-02 04:50

    Try this, it will give you queries currently running for more than 60 seconds. Note that it prints multiple lines per running query if the SQL has multiple lines. Look at the sid,serial# to see what belongs together.

    select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from v$session s 
    join v$sqltext_with_newlines q
    on s.sql_address = q.address
     where status='ACTIVE'
    and type <>'BACKGROUND'
    and last_call_et> 60
    order by sid,serial#,q.piece
    
    0 讨论(0)
提交回复
热议问题