select inst_id,status,count(*) from gv$session group by inst_id,status order by status;


$ORACLE_HOME\rdbms\admin\spreport.sql



Oracle数据库巡检

一、操作系统检查

1.操作系统资源使用情况top/topas/iostat/vmstat 重点关注CPU/内存/交换的使用情况

2.操作系统空间使用情况df -h/-g      重点关注数据库目录空间(du -sh *)(du -sm *)

3.操作系统告警日志

HP: cat /var/adm/syslog/syslog.log

AIX:errpt | more    

LINUX: cat /var/log/messages

SUN:cat /var/log/messages

Windows:事件查看器,查看事件内容

4.uptime查看操作系统是否有重启过特别是rac如有重启重点检查grid的alert日志查明原因

 

 

二、集群检查

1.检查集群状态crs_stat -t

2.检查集群中数据库的状态crsctl status res -t

 

3.检查service状态(grid:lsnrctl status),如都飘在一个检点上需要reload到对应节点(srvctl -h)

srvctl relocate service -d -s {-i -t | -c -n } [-f]

 

4.检查集群alert日志  10g:$CRS_HOME/log/{hostname}/alert{hostname}.log11g:$ORACLE_HOME/log/{hostname}/alert{hostname}.log

5.ASM磁盘空间是否正常

select name,total_mb,free_mb from v$asm_diskgroup;

6.检查磁盘状态

select name,path,STATE,MODE_STATUS from v$asm_disk;

 

 

三、数据库检查

1.重点表空间使用情况确保使用率在85%以内

2.资源使用情况select * from v$resource_limit;(set linesize 300;set pagesize 300;)

3.闪回使用情况

select flashback_on from v$database;

查询视图v$recovery_file_dest视图来了解其位置和最大的大小

select * from v$recovery_file_dest;

使用v$flash_recovery_area_usage确定闪回恢复区中的文件使用明细

select * from v$flash_recovery_area_usage;

 

4.11g的新客户检查新特性是否关闭

是否开启审计show parameter audit_trail   (db 开   none 关)

如开启询问是否有特许需求可以关闭

alter system set audit_trail=none scope=spfile sid='*';

truncate table sys.aud$;

 

select OWNER,SEGMENT_NAME,SEGMENT_TYPE,TABLESPACE_NAME,BYTES/1024/1024 MB from dba_segments where SEGMENT_TYPE='TABLE' and SEGMENT_NAME='AUD$';

 

5.清理监听日志             (win: > listener.log    server 2008 R2 : echo " " > log.xml)


10g及10g以前:$ORACLE_HOME/network/log

11g以后:$ORACLE_BASE/diag/tnslsnr/{hostname}/listener/trace

lsnrctl status查看监听日志目录

10g: $ORACLE_HOME/network/admin/log/    11g:/oracle/gridbase/diag/tnslsnr/s1-11g/listener/alert/log.xml

LSNRCTL> set 

LSNRCTL> set current_listener LISTENER

Current Listener is LISTENER

LSNRCTL> set log_status off

LSNRCTL> set log_status on

LSNRCTL> exit

11g LISTENER_SCAN1

LSNRCTL> set current_listener LISTENER_SCAN1

 

6.检查数据库告警日志

10g以前:$ORACLE_BASE/admin/{SID}/bdump

D:\ORACLE\PRODUCT\10.2.0\ADMIN\{SID}\BDUMP

11g:$ORACLE_BASE/diag/rdbms/{DB_NAME}/{SID}/trace

 

7.查看数据库等待事件

--查看整体数据库的等待事件情况

select event,count(*) from gv$session_wait where wait_class<>'Idle' group by event;

 

 

8.收集awr报告

(1)获取AWR报告

SQL>@ /rdbms/admin/awrrpt.sql     (退出sqlplus即可看到AWR报告)

询问客户高峰期时间点,截取1-2小时的报告

 

四、备份检查

1.确定是否存在逻辑或物理备份并查看备份情况(需检查备份日志)

2.如存在dbra或dg需检查同步情况

切日志,查看备库是否应用正常

select THREAD#,max(sequence#) from v$archived_log group by thread#;  主机

select THREAD#,max(sequence#) from v$archived_log where applied='YES' group by thread#;  备库

select THREAD#,max(sequence#) from v$archived_log group by thread#;  备库

备机空间检查

3.ogg同步情况检查

[oracle@localhost odc12]$ ps -ef | grep mgr

oracle    8492     1  0 Mar17          00:02:29 ./mgr PARAMFILE /odc12/dirprm/mgr.prm REPORTFILE /odc12/dirrpt/MGR.rpt PROCESSID MGR USESUBDIRS

oracle   26085     1  0 Mar22          00:00:15 ./mgr PARAMFILE /odc/dirprm/mgr.prm REPORTFILE /odc/dirrpt/MGR.rpt PROCESSID MGR PORT 7809

cd /odc12

./ggsci

info all

ggserr.log

 

 

 

 

五、跑巡检脚本

六、信息收集打包

1.操作系统日志

2.集群alert日志      grid用户(/oracle/grid/crs_1($ORACLE_HOME)/log/zjrac1)

3.数据库alert日志

4.巡检脚本输出内容

 

mkdir 

 

表空间检查

set feed off 

set linesize 100 

set pagesize 200 

column "USED (MB)" format a10 

column "FREE (MB)" format a10 

column "TOTAL (MB)" format a10 

column PER_FREE format a10 

--spool tablespace.alert 

SELECT F.TABLESPACE_NAME,

TO_CHAR ((T.TOTAL_SPACE - F.FREE_SPACE),'999,999') "USED (MB)", 

TO_CHAR (F.FREE_SPACE, '999,999') "FREE (MB)", 

TO_CHAR (T.TOTAL_SPACE, '999,999') "TOTAL (MB)", 

TO_CHAR ((ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)),'999')||' %' PER_FREE,

TO_CHAR (T.MAX_SPACE,'999,999') "MAXEXTEND (MB)"

FROM ( 

SELECT TABLESPACE_NAME, 

ROUND (SUM (BLOCKS*(SELECT VALUE/1024 

FROM V$PARAMETER 

WHERE NAME = 'db_block_size')/1024) 

) FREE_SPACE 

FROM DBA_FREE_SPACE 

GROUP BY TABLESPACE_NAME 

) F, 

SELECT TABLESPACE_NAME, 

ROUND (SUM (BYTES/1048576)) TOTAL_SPACE,

ROUND (SUM (MAXBYTES/1048576)) MAX_SPACE

FROM DBA_DATA_FILES 

GROUP BY TABLESPACE_NAME 

) T 

WHERE F.TABLESPACE_NAME = T.TABLESPACE_NAME

order by PER_FREE asc;

 

表空间:

select tpsname,status,mgr,maxsize,c_userd,max_used from (

SELECT  d.tablespace_name  tpsname,d.status status,

        d.segment_space_management mgr, d.contents type,

        TO_CHAR(NVL(trunc(A.maxbytes / 1024 / 1024), 0),'99G999G990') maxsize,

        TO_CHAR(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0),'990D00') c_userd,

        TO_CHAR(NVL((a.bytes - NVL(f.bytes, 0)) / a.maxbytes * 100, 0),'990D00') max_used

        FROM sys.dba_tablespaces d,

        (SELECT tablespace_name,sum(bytes) bytes,SUM(case autoextensible when  'NO'  then BYTES when  'YES' then MAXBYTES else null end ) maxbytes   FROM dba_data_files  GROUP BY tablespace_name) a,

        (SELECT tablespace_name,SUM(bytes) bytes, MAX(bytes) largest_free   FROM dba_free_space   GROUP BY tablespace_name) f  

        WHERE d.tablespace_name = a.tablespace_name   AND d.tablespace_name = f.tablespace_name(+)

        )

        where max_used>80

    order by max_used desc;




其它:


SQL> select file_name,bytes/1024/1024,maxbytes/1024/1024,AUTOEXTENSIBLE from dba_data_files;