通過作業系統上的PID找出相應的SQL語句,pid找出sql語句

來源:互聯網
上載者:User

通過作業系統上的PID找出相應的SQL語句,pid找出sql語句
linux平台下,我們一般通過TOP命令,查看效能消耗最大的進程,如果看到是oracle進行,那麼就需要通過進程號,查詢該進程當前執行的SQL語句,網上百度有很多SQL,我一般通過下面的方式進行尋找:通過作業系統上的PID找出相應的SQL語句的SID:

SELECT s.sid, p.spid FROM v$session s, v$process p WHERE s.paddr = p.addr  AND  < p.spid = <os pid> 


然後通過SID找出相應的SQL語句的具體內容:

SELECT s.sid, s.status, q.sql_text FROM v$session s, v$sqltext q WHERE s.sql_hash_value = q.hash_value AND s.sql_address = q.address AND s.sid = <sid> order by q.piece;

合并一

SELECT   /*+ ORDERED */         sql_text    FROM v$sqltext a   WHERE (a.hash_value, a.address) IN (            SELECT DECODE (sql_hash_value,                           0, prev_hash_value,                           sql_hash_value                          ),                   DECODE (sql_hash_value, 0, prev_sql_addr, sql_address)              FROM v$session b             WHERE b.paddr = (SELECT addr                                FROM v$process c                               WHERE c.spid = '&pid'))ORDER BY piece ASC/


合并二:
Select s.Sid, s.Status, q.Sql_TextFrom V$session s, V$sqltext qWhere s.Sql_Hash_Value = q.Hash_Value And s.Sql_Address = q.Address And                        s.Sid In (Select s.Sid                                                                 From V$session s, V$process p                                                                 Where s.Paddr = p.Addr And  p.Spid = '&pid' )Order By q.Piece;


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.