如何定位佔用oracle資料庫cpu過高的sql

來源:互聯網
上載者:User

看到oracle進程為6331,6517等這幾個進程佔用cpu過高,

2)查看相關進程資訊:

[oracle@oracle-one ~]$ ps -ef | grep 6331oracle    6331     1 23 20:24 ?        00:02:05 ora_vktm_RHYSoracle    6555  6385  0 20:32 pts/2    00:00:00 grep 6331[oracle@oracle-one ~]$ ps -ef | grep 6517oracle    6557  6385  0 20:33 pts/2    00:00:00 grep 6517[oracle@oracle-one ~]$ 


3)查看該會話資訊:

SQL> select sid,serial#,username,machine,osuser,process from v$session s  2     where s.paddr=(select addr from v$process p where p.spid='&pid');Enter value for pid: 6517old   2:    where s.paddr=(select addr from v$process p where p.spid='&pid')new   2:    where s.paddr=(select addr from v$process p where p.spid='6517')       SID    SERIAL# USERNAME                       MACHINE                                                          OSUSER                         PROCESS---------- ---------- ------------------------------ ---------------------------------------------------------------- ------------------------------ ------------------------         1         21 RHYS                           oracle-one                                                       oracle                         6513


可知:session 的資訊為sid:1  serial#:21 資料庫使用者為:RHYS,用戶端機器為:oracle-one,作業系統使用者為:oracle 進程號:6513

4)查看該會話正在啟動並執行sql:

SQL> select sql_text from v$sqltext  2   where (address,hash_value) in (  select sql_address,sql_hash_value from v$session s   3    4        where s.paddr=  5       (select addr from v$process p where p.spid='&pid'));Enter value for pid: 6517old   5:      (select addr from v$process p where p.spid='&pid'))new   5:      (select addr from v$process p where p.spid='6517'))


可知,目前使用者進行中刪除表的操作,本次就是通過v$process 的spid找到進程號,然後找到v$session 的addr地址,然後找到v$sqltext的sql_address以及sql_hash_value,通過這兩個欄位就可以定位出唯一的sql_text,本次通過v$process,v$session,v$sql_text三個視圖結合找到相應的sql;

5)如果該session為非法的,可以使用如下命令殺掉該會話:

alter  sytem kill  session ‘1,21’;

既然找到sql了,那麼 我們就可以通知應用相關人員,確認是否在進行相關資料操作。

另外我們也可以使用dbms_system包對該session進行更加詳細的跟蹤。

相關文章

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.