oracle监控脚本语句

查看碎片程度高的表

SELECT segment_name table_name, COUNT(*) extents  

FROM dba_segments

WHERE owner NOT IN (‘SYS‘, ‘SYSTEM‘)
 GROUP BY segment_name
HAVING COUNT(*) = (SELECT MAX(COUNT(*))
                     FROM dba_segments
                    GROUP BY segment_name);

查找使用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;

回滚段的争用情况

select name, waits, gets, waits/gets "Ratio" 
    from v$rollstat a, v$rollname b 
    where a.usn = b.usn; 

 

监控 SGA *享缓存区的命中率,应该小于1%

select sum(pins) "Total Pins",
       sum(reloads) "Total Reloads",
       sum(reloads) / sum(pins) * 100 libcache,
       sum(pinhits - reloads) / sum(pins) "hit radio",
       sum(reloads) / sum(pins) "reload percent"
  from v$librarycache;

监控 SGA 中重做日志缓存区的命中率,应该小于1%

    SELECT name, gets, misses, immediate_gets, immediate_misses,
    Decode(gets,0,0,misses/gets*100) ratio1,
    Decode(immediate_gets+immediate_misses,0,0,
    immediate_misses/(immediate_gets+immediate_misses)*100) ratio2
    FROM v$latch WHERE name IN (‘redo allocation‘, ‘redo copy‘); 

监控log_buffer的使用情况

select name,value from v$sysstat where name in (‘redo entries‘,‘redo buffer allocation retries‘)

 

监控SGA中数据库缓冲区的命中率

 select a.value + b.value "logical_reads", c.value "phys_reads",
    round(100 * ((a.value+b.value)-c.value) / (a.value+b.value)) "BUFFER HIT RATIO" 
    from v$sysstat a, v$sysstat b, v$sysstat c
    where a.statistic# = 38 and b.statistic# = 39 
    and c.statistic# = 40; 

监控表空间的IO比例

 select df.tablespace_name name,df.file_name "ile",f.phyrds pyr,
    f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw
    from v$filestat f, dba_data_files df
    where f.file# = df.file_id
    order by df.tablespace_name;

监控表空间的使用率

SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
       D.TOT_GROOTTE_MB "表空间大小(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
       ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2) "使用比",
       F.TOTAL_BYTES "空闲空间(M)",
       F.MAX_BYTES "最大块(M)"
  FROM (SELECT TABLESPACE_NAME,
               ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
               ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
          FROM SYS.DBA_FREE_SPACE
         GROUP BY TABLESPACE_NAME) F,
       (SELECT DD.TABLESPACE_NAME,
               ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
          FROM SYS.DBA_DATA_FILES DD
         GROUP BY DD.TABLESPACE_NAME) D
 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
 ORDER BY 4 DESC;

 

监控当前数据库谁在运行什么SQL语句

SELECT osuser, username, sql_text
  from v$session a, v$sqltext b
 where a.sql_address = b.address
 order by address, piece;

监控等待事件

select event,sum(decode(wait_Time,0,0,1)) "rev", 
   sum(decode(wait_Time,0,1,0)) "Curr",count(*) "Tot" 
    from v$session_Wait 
    group by event order by 4;

 

监控内存和硬盘的排序比率

SELECT name, value
  FROM v$sysstat
 WHERE name IN (‘sorts (memory)‘, ‘sorts (disk)‘);

监控文件系统的IO比例

    select substr(a.file#,1,2) "#", substr(a.name,1,30) "Name", 
    a.status, a.bytes, b.phyrds, b.phywrts 
    from v$datafile a, v$filestat b 
    where a.file# = b.file#; 

在某个用户下找所有的索引

select user_indexes.table_name,
       user_indexes.index_name,
       uniqueness,
       column_name
  from user_ind_columns, user_indexes
 where user_ind_columns.index_name = user_indexes.index_name
   and user_ind_columns.table_name = user_indexes.table_name
 order by user_indexes.table_type,
          user_indexes.table_name,
          user_indexes.index_name,
          column_position;

本文出自 “飛鴻沓膤” 博客,转载请与作者联系!

oracle监控脚本语句,布布扣,bubuko.com

oracle监控脚本语句

上一篇:【翻译自mos文章】在oracle db 11gR2版本中启用 Oracle NUMA 支持


下一篇:linux下MySQL 5.6源码安装