1、通过TOP 命令查看PID:
bash
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1560 oracle 20 0 38.978g 0.038t 16296 R 100.0 15.3 1069:13 python3 Main_Mem.py ProcessLog1 config.ini
2、通过spid 查找对应SQL:
sql
-- 1、通过spid查找对应内存地址:
SELECT addr FROM v$process c WHERE c.spid = 1560 ;
-- 2、通过内存地址寻址hash值:
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 = '00000004B08F4DC8';
-- 3、通过hash值找到对应sql_id:
select a.sql_text,a.sql_id From v$sqltext a where a.hash_value='3838526855' and a.address='00000004DBAE9638' order by piece;
-- 4、通过sql_id查找详细的sql查询脚本:
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='{sqlID}'
3、查找到的sql主要分为三类:
1、where条件缺少主键;
2、where条件缺少索引;
3、对应主表数据量太大。