Oracle 性能监控sql

陈高峰原创

基本都是工作中常用,性能优化和管理必备的sql;

--1.查看表锁
select * from sys.v_$sqlarea where disk_reads>100;

--2.监控事例的等待
select event,sum(decode(wait_Time,0,0,1)) "Prev",
sum(decode(wait_Time,0,1,0)) "Curr",count(*) "Tot"
from v$session_Wait
group by event order by 4;

--3.性能最差的SQL
SELECT * FROM ( SELECT PARSING_USER_ID EXECUTIONS,SORTS,COMMAND_TYPE,DISK_READS,sql_text
                FROM v$sqlarea
                ORDER BY disk_reads DESC)
WHERE ROWNUM<100;
                            
--4.读磁盘数超100次的sql
select * from sys.v_$sqlarea where disk_reads>100 ;

--5.最频繁执行的sql
select * from sys.v_$sqlarea where executions>100;

--6.查询使用CPU多的用户session
select a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,osuser,value/60/100 value
from v$session a,v$process b,v$sesstat c
where c.statistic#=12 and
      c.sid=a.sid and
      a.paddr=b.addr
order by value desc;

--7.当前每个会话使用的对象数
SELECT a.sid,s.terminal,s.program,count(a.sid)
FROM V$ACCESS a,V$SESSION s
WHERE a.owner <> 'SYS'AND s.sid = a.sid
GROUP BY a.sid,s.terminal,s.program
ORDER BY count(a.sid);

--8.数据表占用空间大小情况
select segment_name,tablespace_name,bytes,blocks
from user_segments
where segment_type='TABLE'
ORDER BY bytes DESC ,blocks DESC;

 

你可能感兴趣的:(oracle)