公司的庫裡面不是所有的資料表空間都是unlimted,所以還是要搞個郵件發送,時不時監控一下資料表空間的使用率。以下是我參考一些文檔,修改後在我工作中使用的。我的資料庫版本是11.2.0.4,Linux版本是Centos 6.3。
- #!/bin/bash
- ORACLE_SID=orcl; export ORACLE_SID
- ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1; export ORACLE_HOME
- $ORACLE_HOME/bin:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/sbin:/usr/openwin/bin:/opt/bin:.;
- export PATH
- DBALIST="masicong1019@hotmail.com";export DBALIST
- sqlplus -s '/ as sysdba' <<EOF
- 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
- 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
- FROM DBA_DATA_FILES
- GROUP BY TABLESPACE_NAME
- ) T
- WHERE F.TABLESPACE_NAME = T.TABLESPACE_NAME
- AND (ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)) < 80;
- spool off
- exit
- EOF
- if [cat tablespace.alert|wc -l -gt 0]
- then
- cat tablespace.alert > tablespace.tmp
- mailx -s "TABLESPACE ALERT for PPRD10" $DBALIST < tablespace.tmp
- fi
本文出自 “無雙城” 部落格,請務必保留此出處http://929044991.blog.51cto.com/1758347/1176173