可以到v$sql中查询,比如以buffer_gets,executions,disk_reads等条件判断.
--值得怀疑的SQL
selectsubstr(to_char(s.pct,'99.00'),2)||'%'load,
s.executions executes,
p.sql_text
from(selectaddress,
disk_reads,
executions,
pct,
rank()over(orderbydisk_readsdesc) ranking
from(selectaddress,
disk_reads,
executions,
100*ratio_to_report(disk_reads)over() pct
fromsys.v_$sql
wherecommand_type!=47)
wheredisk_reads>50*executions) s,
sys.v_$sqltext p
wheres.ranking<=5
andp.address=s.address
orderby1, s.address, p.piece;
--逻辑读多的SQL
select*
from(selectbuffer_gets, sql_text
fromv$sqlarea
wherebuffer_gets>500000
orderbybuffer_getsdesc)
whererownum<=30;
--执行次数多的SQL
selectsql_text, executions
from(selectsql_text, executionsfromv$sqlareaorderbyexecutionsdesc)
whererownum<81;
--读硬盘多的SQL
selectsql_text, disk_reads
from(selectsql_text, disk_readsfromv$sqlareaorderbydisk_readsdesc)
whererownum<21;
--排序多的SQL
selectsql_text, sorts
from(selectsql_text, sortsfromv$sqlareaorderbysortsdesc)
whererownum<21;
--分析的次数太多,执行的次数太少,要用绑变量的方法来写sql
setpagesize600;
setlinesize120;
selectsubstr(sql_text,1,80) "sql",count(*),sum(executions) "totexecs"
fromv$sqlarea
whereexecutions<5
groupbysubstr(sql_text,1,80)
havingcount(*)>30
orderby2;
--游标的观察
setpages300;
selectsum(a.value), b.name
fromv$sesstat a, v$statname b
wherea.statistic#=b.statistic#
andb.name='opened cursors current'
groupbyb.name;
selectcount(0)fromv$open_cursor;
selectuser_name, sql_text,count(0)
fromv$open_cursor
groupbyuser_name, sql_text
havingcount(0)>30;
--查看当前用户&username执行的SQL
selectsql_text
fromv$sqltext_with_newlines
where(hash_value, address)in
(selectsql_hash_value, sql_address
fromv$session
whereusername='&username')
orderbyaddress, piece;
阅读(1333) | 评论(0) | 转发(0) |