[轉]定位佔用oracle資料庫cpu過高的sql

來源:互聯網
上載者:User

標籤:

 

    今天在吃飯的時候我的朋友的資料庫出現了問題,cpu佔用率為97%,當我看到這個問題的時候我就想到了或許是sql導致的此問題,由於忍不住吃飯,暫時沒有幫他看這個問題,這是我飯後自己類比的故障,進行的分析:

 1)查看一下cpu進程佔用情況:

 

 

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

 

2)查看相關進程資訊:

[[email protected] ~]$ ps -ef | grep 6331  oracle    6331     1 23 20:24 ?        00:02:05 ora_vktm_RHYS  oracle    6555  6385  0 20:32 pts/2    00:00:00 grep 6331  [[email protected]-one ~]$ ps -ef | grep 6517  <span style="color:#ff0000">oracle    6517  6513  9 20:28 ?        00:00:24 oracleRHYS (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))  </span>oracle    6557  6385  0 20:33 pts/2    00:00:00 grep 6517  [[email protected]-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: 6517  old   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: 6517  old   5:      (select addr from v$process p where p.spid=‘&pid‘))  new   5:      (select addr from v$process p where p.spid=‘6517‘))    <span style="color:#ff0000">SQL_TEXT  ----------------------------------------------------------------  delete from amy_emp</span>  

     可知,目前使用者進行中刪除表的操作,本次就是通過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進行更加詳細的跟蹤。

 

 

比價老的一篇文章,轉自:http://www.bitscn.com/pdb/oracle/201309/241814.html

[轉]定位佔用oracle資料庫cpu過高的sql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.