oracle版本:oracle11g
背景:今天在Linux中的oracle服务上,运用top命令发现许多进程的CPU占有率是100%。
操作步骤:
以进程PID:7851为例
执行以下语句:
方法一:
(1)通过PID,查得相对应的系统进程对应的session id
select sid from v$session where paddr in (select addr from v$process where spid=7851
得到SID:206
(2)根据所得的会话ID查得sql地址和hash值
select sql_address,sql_hash_value from v$session where sid=206
得到:SQL_ADDRESS:6EC554F4 SQL_HASH_VALUE:3141392848
(3)根据sql hash值查得sql语句
select sql_text from v$sqltext where hash_value=3141392848
得到SQL语句:INSERT INTO TEST SELECT * FROM SYS.DBA_OBJECTS 此SQL语句就是此进程CPU占有率过高的语句了。
方法二:
SELECT
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 = 7851))
ORDER BY piece ASC
通过此SQL语句可以直接得出:
INSERT INTO TEST SELECT * FROM SYS.DBA_OBJECTS 此SQL语句就是此进程CPU占有率过高的语句了。
原文:https://www.cnblogs.com/xiangxiushu/p/13613600.html