Oracle找出执行慢的SQL

该语句找出磁盘读大于10000的SQL
col username format a10
col sid format 9999
select b.username,a.disk_reads,a.executions,a.disk_reads/decode(a.executions,0,1,a.executions) rds_ratio,
a.sql_text sql from v s q l a r e a a , d b a u s e r s b w h e r e a . p a r s i n g u s e r i d = b . u s e r i d a n d b . u s e r n a m e < > ′ S Y S ′ a n d a . d i s k r e a d s > 10000 o r d e r b y a . d i s k r e a d s d e s c ; 该 语 句 找 出 逻 辑 读 超 过 10000 的 S Q L c o l u s e r n a m e f o r m a t a 10 c o l s i d f o r m a t 9999 s e l e c t b . u s e r n a m e , a . b u f f e r g e t s , a . e x e c u t i o n s , a . b u f f e r g e t s / d e c o d e ( a . e x e c u t i o n s , 0 , 1 , a . e x e c u t i o n s ) r d s r a t i o , a . s q l t e x t s q l f r o m v sqlarea a,dba_users b where a.parsing_user_id=b.user_id and b.username<>'SYS' and a.disk_reads>10000 order by a.disk_reads desc; 该语句找出逻辑读超过10000的SQL col username format a10 col sid format 9999 select b.username,a.buffer_gets,a.executions,a.buffer_gets/decode(a.executions,0,1,a.executions) rds_ratio, a.sql_text sql from v sqlareaa,dbausersbwherea.parsinguserid=b.useridandb.username<>SYSanda.diskreads>10000orderbya.diskreadsdesc;10000SQLcolusernameformata10colsidformat9999selectb.username,a.buffergets,a.executions,a.buffergets/decode(a.executions,0,1,a.executions)rdsratio,a.sqltextsqlfromvsqlarea a,dba_users b where a.parsing_user_id=b.user_id and b.username<>‘SYS’ and a.disk_reads>10000
order by a.buffer_gets desc;
该语句找出consistent_gets最多的session
select a.username,a.sid,b.block_gets,b.consistent_gets,b.physical_reads,b.block_changes,b.consistent_changes
from v s e s s i o n a , v session a,v sessiona,vsess_io b where a.sid=b.sid and username is not null order by consistent_gets desc;
该语句找出physical_gets最多的session
select a.username,a.sid,b.block_gets,b.consistent_gets,b.physical_reads,b.block_changes,b.consistent_changes
from v s e s s i o n a , v session a,v sessiona,vsess_io b where a.sid=b.sid and username is not null order by physical_gets desc;
可以根据实际需要调整阀值
select * from dba_sys_privs where GRANTEE=‘GGS’

统计信息:
exec dbms_stats.gather_table_stats(user,‘EYGLE’);

exec dbms_stats.gather_schema_stats(ownname=>‘用户名 称’,estimate_percent=>100,cascade=> TRUE, degree =>12);

SGA PGA 的计算

select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total100,2) pctused from
(select ‘SGA’ name,(select sum(value/1024/1024) from v s g a ) t o t a l , ( s e l e c t s u m ( b y t e s / 1024 / 1024 ) f r o m v sga) total, (select sum(bytes/1024/1024) from v sga)total,(selectsum(bytes/1024/1024)fromvsgastat where name=‘free memory’)free from dual)
union
select name,total,round(used,2)used,round(total-used,2)free,round(used/total
100,2)pctused from (
select ‘PGA’ name,(select value/1024/1024 total from v p g a s t a t w h e r e n a m e = ′ a g g r e g a t e P G A t a r g e t p a r a m e t e r ′ ) t o t a l , ( s e l e c t v a l u e / 1024 / 1024 u s e d f r o m v pgastat where name='aggregate PGA target parameter')total, (select value/1024/1024 used from v pgastatwherename=aggregatePGAtargetparameter)total,(selectvalue/1024/1024usedfromvpgastat where name=‘total PGA allocated’)used from dual);

下面这个查询可以找到从未收集过统计信息或者统计信息过期的表。
EXEC DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
SELECT OWNER,TABLE_NAME,OBJECT_TYPE,STALE_STATS,LAST_ANALYZED FROM
DBA_TAB_STATISTICS WHERE (STALE_STATS=‘YES’ OR LAST_ANALYZED IS NULL)
AND OWNER NOT IN (‘SYS’, ‘SYSTEM’, ‘SYSMAN’, ‘DMSYS’, ‘OLAPSYS’, ‘XDB’,‘EXFSYS’, ‘CTXSYS’,
‘WMSYS’, ‘DBSNMP’, ‘ORDSYS’, ‘OUTLN’, ‘TSMSYS’, ‘MDSYS’) AND TABLE_NAME NOT LIKE ‘BIN%’;

在进行调优之前,我们就要看表的统计信息是否过期,如果过期了,CBO就可能选择错误的执行计划。
SELECT OWNER,TABLE_NAME,OBJECT_TYPE,STALE_STATS,LAST_ANALYZED FROM DBA_TAB_STATISTICS WHERE OWNER=’&OWNER’ AND TABLE_NAME=’&TABLE_NAME’;

猜你喜欢

转载自blog.csdn.net/hardyer/article/details/103258823