1.查询占用物理读资源
select sql_text,sql_id, disk_reads, buffer_gets, parsing_schema_name, executions
from v$sqlarea where parsing_schema_name='用户对象'
order by disk_reads desc;
2.查询当前执行sql
SELECT b.inst_id,b.sid oracleID,
b.username 登录Oracle用户名,
b.serial#,
spid 操作系统ID,
paddr,
sql_text 正在执行的SQL,
sql_fulltext,
b.machine 计算机名,
b.EVENT,
'alter system kill session '''||b.sid||','||b.serial#||''';'
FROM gv$process a, gv$session b, gv$sql c
WHERE a.addr = b.paddr
AND b.sql_hash_value = c.hash_value
and a.inst_id=1
and b.inst_id=1
and c.inst_id=1
and b.status='ACTIVE'
3.查到当前等待事件最多的sql
SELECT b.inst_id,b.sid oracleID,
b.username 登录Oracle用户名,
b.serial#,
spid 操作系统ID,
paddr,
sql_text 正在执行的SQL,
sql_fulltext,
b.machine 计算机名,
b.EVENT,
c.SQL_ID,
c.CHILD_NUMBER
FROM gv$process a, gv$session b, gv$sql c
WHERE a.addr = b.paddr
AND b.sql_hash_value = c.hash_value
and event like '%gc current request%'
and a.inst_id=1
and b.inst_id=1
and c.inst_id=1
4.查询执行最慢的sql-top50
select *
from (select sa.SQL_TEXT,
sa.SQL_FULLTEXT,
sa.EXECUTIONS "执行次数",
round(sa.ELAPSED_TIME / 1000000, 2) "总执行时间",
round(sa.ELAPSED_TIME / 1000000 / sa.EXECUTIONS, 2) "平均执行时间",
sa.COMMAND_TYPE,
sa.PARSING_USER_ID "用户ID",
u.username "用户名",
sa.HASH_VALUE
from v$sqlarea sa
left join all_users u
on sa.PARSING_USER_ID = u.user_id
where sa.EXECUTIONS > 0
order by (sa.ELAPSED_TIME / sa.EXECUTIONS) desc)
where rownum <= 50;
5.查询次数最多的sql
select *
from (select s.SQL_TEXT,
s.EXECUTIONS "执行次数",
s.parsing_schema_name,
s.PARSING_USER_ID "用户名",
rank() over(order by EXECUTIONS desc) EXEC_RANK
from v$sql s
left join all_users u
on u.USER_ID = s.PARSING_USER_ID) t
where exec_rank <= 100;