該腳本主要用來作數據庫的常規檢查,以及dg備庫.sql
各位少作修改便可使用
數據庫
- 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
- !