该脚本主要用来做数据库的常规检查,以及dg备库.
各位少做修改即可使用
- bin/env bash
- # FILE: db_check.sh
- #
- # USAGE: ./db_check.sh
- #
- # DESCRIPTION: Check the database status.
- #
- # BUGS: ---
- # AUTHOR: JadeShow/xiaosuyang@gmail.com
- # VERSION: 0.1
- # CREATED: Sat Feb 4 12:29:19 BEIST 2012
- #================================================================================
- ORACLE_BASE=/oracle
- ORACLE_HOME=/oracle/product/10.2.0
- ORACLE_SID=htdisdb
- PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/htmon/bin:/usr/bin/X11:/sbin:.:/bin:/oracle/product/10.2.0/bin
- export PATH ORACLE_SID ORACLE_HOME ORACLE_BASE
- export NLS_LANG=American_America.AL32UTF8;
- set line 120;
- set pages 0;
- set feedback off;
- set heading off;
- set verify off;
- set echo off;
- sqlplus -s sys/sys@htdisdb "as sysdba" << !
- column dest_name format a30
- column destination format a20
- column MEMBER format a45
- column destination format a20
- column TABLESPACE_NAME format a10
- column FREE_RATE format a10
- prompt **************************** 实 例 状 态 ************************************;
- select instance_name,version,status,database_status from v\$instance;
- prompt **************************** 数据库状态 *************************************;
- select name,log_mode,open_mode from v\$database;
- prompt **************************** 控制文件状态 ***********************************;
- column name format a50
- select status,name from v\$controlfile;
- prompt **************************** 日志文件状态 ***********************************;
- select GROUP#,status,type,member from v\$logfile;
- prompt***************************** 归档目的地状态 *********************************;
- select dest_name ,status,database_mode,destination from v\$archive_dest_status where dest_id in ('1','2');
- set heading off;
- prompt ************数据库已连续运行天数*******************************************
- select round(a.atime-b.startup_time)||' days ' from(select sysdate atime from dual) a,v\$instance b;
- set heading on;
- prompt***************************** 会 话 数 *************************************;
- select sessions_current,sessions_highwater from v\$license;
- prompt********************** 表空间监控********************;
- prompt TABLESPACE_NAME 已用空间(M) 空闲空间(M)
- SELECT D.TABLESPACE_NAME,
- SPACE "SUM_SPACE(M)",
- BLOCKS "SUM_BLOCKS",
- SPACE - NVL (FREE_SPACE, 0) "USED_SPACE(M)",
- ROUND( (1 - NVL (FREE_SPACE, 0) / SPACE) * 100, 2) "USED_RATE(%)",
- FREE_SPACE "FREE_SPACE(M)"
- FROM ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES) / (1024 * 1024), 2) SPACE,
- SUM (BLOCKS) BLOCKS
- FROM DBA_DATA_FILES
- GROUP BY TABLESPACE_NAME) D,
- ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES) / (1024 * 1024), 2) FREE_SPACE
- FROM DBA_FREE_SPACE
- GROUP BY TABLESPACE_NAME) F
- WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
- UNION ALL --如果有临时表空间
- SELECT D.TABLESPACE_NAME,
- SPACE "SUM_SPACE(M)",
- BLOCKS SUM_BLOCKS,
- USED_SPACE "USED_SPACE(M)",
- ROUND (NVL (USED_SPACE, 0) / SPACE * 100, 2) "USED_RATE(%)",
- NVL (FREE_SPACE, 0) "FREE_SPACE(M)"
- FROM ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES) / (1024 * 1024), 2) SPACE,
- SUM (BLOCKS) BLOCKS
- FROM DBA_TEMP_FILES
- GROUP BY TABLESPACE_NAME) D,
- ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES_USED) / (1024 * 1024), 2) USED_SPACE,
- ROUND (SUM (BYTES_FREE) / (1024 * 1024), 2) FREE_SPACE
- FROM V\$TEMP_SPACE_HEADER
- GROUP BY TABLESPACE_NAME) F
- WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
- ORDER BY 1;
- prompt **************************** 表空间OFFLINE(显示为空正常) ********************;
- select tablespace_name ,status from dba_tablespaces where status='OFFLINE';
- prompt **************************** SEQUENCE同步数 *********************************;
- select max(sequence#)from v\$log_history;
- disconnect
- !
- sqlplus -s sys/sys@htdisdb "as sysdba" <<!
- prompt **************************** 备库SEQUENCE同步数 *****************************;
- select max(sequence#)from v\$log_history;
- prompt **************************** 备库日志未应用(显示为空正常) *******************;
- select sequence#,applied from v\$archived_log where applied='NO';
- prompt **************************** 备库日志应用(显示最近十个日志) *****************;
- select * from(select sequence#,applied from v\$archived_log order by sequence# desc) where rownum<=10;
- set time on
- disconnect
- !