oracle监控常用语句



--数据库实例查询
select * from gv$version;


--RDBMS信息
select * from gv$version where Banner like '%Oracle%';


--SQL &Net版本信息
select * from gv$version where Banner like '%TNS%';




--SGA信息(Database Buffer)
select s.*,round(s.value/1024/1024) from gv$sga s where name = 'Database Buffers'


--SGA(Shared pool)
select s.*,round(s.bytes/1024/1024) from gv$sgainfo s where name = 'Shared Pool Size'


--SGA(LOG Buffers)
select s.*,round(s.bytes/1024/1024) from gv$sgastat s where s.name='log_buffer'


--DB_BLOCK Size
select p.value/1024,p.* from gv$parameter p where name = 'db_block_size'


--表空间信息
select * from dba_tablespaces;


--表空间使用率
select f.tablespace_name,
       a.total 总共M,
       f.free 空闲M,
       round((f.free / a.total) * 100) "空闲比率"
  from (select tablespace_name, sum(bytes / (1024 * 1024)) total
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, round(sum(bytes / (1024 * 1024))) free
          from dba_free_space
         group by tablespace_name) f
 WHERE a.tablespace_name = f.tablespace_name(+)
 order by "空闲比率";




--数据文件:
select * from dba_data_files;


--控制文件状态:
select * from v$controlfile;


--在线日志状态
select group# as 日志组,
       member 地址,
       status 状态,
       is_recovery_dest_file
from v$logfile;


--相关参数查看(session,processes)
select resource_name,max_utilization,initial_allocation,limit_value from v$resource_limit;


--最大游标(一个session执行语句数量)
select * from gv$parameter where name like '%cursor%';


--CPU使用率
SELECT round(t1.value*100/(t1.value+t2.value),4)||'%' 使用率,
       s.begin_interval_time 开始时间
       s.end_interval_time 结束时间
       t1.*,t2.*,
FROM dba_hist_osstat t1,dba_hist_snapshot s,dba_hist_osstat t2
WHERE t1.stat_name = 'BUSY_TICKS'
and t2.stat_name = 'IDLE_TICKS' 
and t1.snap_id = s.snap_id
and t2.snap_id = s.snap_id
and s.begin_interval_time >= TO_TIMESTAMP('2015-01-19 ', 'yyyy-mm-dd hh24')
and s.begin_interval_time < TO_TIMESTAMP('2015-01-19 20', 'yyyy-mm-dd hh24');


--最大内存
select * from gv$parameter p where name = 'sga_target'


--内存使用率
SELECT round(t.bytes*100/1073741824)||'%' 使用率,
       to_char(s.begin_interval_time,'yyyy-mm-dd hh24:mi:ss') 开始时间,
       to_char(s.end_interval_time,'yyyy-mm-dd hh24:mi:ss') 结束时间
FROM dba_hist_sgastat t,dba_hist_snapshot s
where t.snap_id = s.snap_id
and t.name  = 'free memory'
and t.pool = 'shared pool'
and s.begin_interval_time >= TO_TIMESTAMP('2015-01-19 08', 'yyyy-mm-dd hh24')
and s.begin_interval_time < TO_TIMESTAMP('2015-01-19 20', 'yyyy-mm-dd hh24')
order by s.begin_interval_time;


--历史session 统计
select to_char(s.begin_interval_time,'yyyy-mm-dd hh24:mi:ss') 开始时间,
       to_char(s.end_interval_time,'yyyy-mm-dd hh24:mi:ss') 结束时间,
       count(session_id)
from dba_hist_active_sess_history h,dba_hist_snapshot s
where h.snap_id = s.snap_id
and s.begin_interval_time >= TO_TIMESTAMP('2015-01-19 08', 'yyyy-mm-dd hh24')
and s.begin_interval_time < TO_TIMESTAMP('2015-01-19 20', 'yyyy-mm-dd hh24')
and h.session_type = 'FOREGROUND'
and h.sql_id is not null
group by  to_char(s.begin_interval_time,'yyyy-mm-dd hh24:mi:ss'),to_char(s.end_interval_time,'yyyy-mm-dd hh24:mi:ss')
;


--具体运行sql语句查询
select * from dba_hist_sqltext where sql_id = '';


--无效对象
select owner,object_name,object_type from dba_objects where status!='VALID' and owner!='SYS' and owner!='SYSTEM'; 


--IO查询
select * from v$iostat_file;
select * from dba_hist_iostat_filetype;
发布了22 篇原创文章 · 获赞 29 · 访问量 8万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章