1.第一步查看消耗资源的进程;
SELECT s.Schemaname Schema_Name,Decode(Sign(48 - Command),
1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,Status Session_Status, s.Osuser Os_User_Name, s.Sid, p.Spid,s.Serial# Serial_Num, Nvl(s.Username, '[Oracle process]') User_Name,
s.Terminal Terminal, s.Program Program, St.VALUE Criteria_Value
FROM V$sesstat St, V$session s, V$process p
WHERE St.Sid = s.Sid
AND St.Statistic# = To_Number('38')
AND ('ALL' = 'ALL' OR s.Status = 'ALL')
AND p.Addr = s.Paddr
ORDER BY St.VALUE DESC, p.Spid ASC, s.Username ASC, s.Osuser ASC
2.第二步Spid查看sql_id;
SELECT *
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
/
3.第三步通过sql_id查sql_fulltext;
select SQL_TEXT,SQL_FULLTEXT,SQL_ID,LOADS,FIRST_LOAD_TIME,PLSQL_EXEC_TIME,JAVA_EXEC_TIME,ROWS_PROCESSED,COMMAND_TYPE,PARSING_USER_ID,PARSING_SCHEMA_ID,PARSING_SCHEMA_NAME,KEPT_VERSIONS,ADDRESS,SERVICE,MODULE,MODULE_HASH,ACTION,CPU_TIME,ELAPSED_TIME,OUTLINE_SID,CHILD_ADDRESS,SQLTYPE,REMOTE,OBJECT_STATUS,LITERAL_HASH_VALUE,LAST_LOAD_TIME,PROGRAM_ID,PROGRAM_LINE#,LAST_ACTIVE_TIME
from v$sql where sql_id='7h35uxf5uhmm1'