修改自大神博客:http://www.cnblogs.com/jyzhao/p/5364049.html

脚本巡检的优化:自动化,节省时间。

脚本需加强:巡检结果中有大量的sqlplus连接信息,后期考虑用shell只过滤出有用信息,优化查看。

开始介绍:

1.环境sentos6\7、redhat6

2.可以将脚本放至/home/oracle/checkdir/ORA_check.sh

3.修改脚本文件权限:

# chown -R oracle:dba /var/ORA_check.sh
# chmod u+x ORA_check.sh

4.vim ORA_check.sh

#!/usr/bin/ksh
echo ""
echo "ORAWatcher Version:1.0.1"
echo ""
#Create Time:--
#Update Time:--
######################################################################
#数据库连接设置
######################################################################
read -p "Please input system passwd: " DBApasswd
sqlstr=system/$DBApasswd ######################################################################
# Create log subdirectories if they don't exist
######################################################################
archive=/home/oracle/checkdir/archive
if [ ! -d $archive ]; then
mkdir $archive
fi echo "Starting ..."
echo ""
######################################################################
hostn=`hostname`
CKtime=`date +%F_%H:%M.log`
echo "CHECK_TIME: $CKtime ">$archive/${hostn}_oracle_$CKtime
###################################################################### echo "######################## 1.数据库版本"
echo "--1.Database Version" >>$archive/${hostn}_oracle_$CKtime
echo "Select version FROM Product_component_version
Where SUBSTR(PRODUCT,,)='Oracle';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 2.控制文件"
echo "--2.Control files" >>$archive/${hostn}_oracle_$CKtime
echo "select name from v\$controlfile;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 3.pfile、spfile"
echo "--3.Parameter files" >>$archive/${hostn}_oracle_$CKtime
echo "show parameter pfile;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 4.字符集"
echo "--4.DB Character" >>$archive/${hostn}_oracle_$CKtime
echo "col PARAMETER for a20
col value for a20
select * from v\$nls_parameters where parameter='NLS_CHARACTERSET';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 5.归档状态"
echo "--5.DB Archive Mode" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 333
show parameter log_$archive" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 6.参数设置"
echo "--6.Parameter Config" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 500
set pages
show parameter;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 7.回滚段存储位置"
echo "--7.Undo Info" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 500
set pages
SELECT SEGMENT_NAME, TABLESPACE_NAME, STATUS FROM DBA_ROLLBACK_SEGS;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 8.redolog"
echo "--8.Redolog Files" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 200
set pages
col MEMBER for a50
select a.member,a.group#,b.thread#,b.bytes,b.members,b.status
from v\$logfile a,v\$log b
where a.group#=b.group#;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 9.查看表空间大小及利用率"
echo "--9.Tablespace Usage" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 200
set pages
col TABLESPACENAME for a30
select substr(a.TABLESPACE_NAME,,) TablespaceName,
sum(a.bytes//) as \"Totle_size(M)\",
sum(nvl(b.free_space1//,)) as \"Free_space(M)\",
sum(a.bytes//)-sum(nvl(b.free_space1//,)) as \"Used_space(M)\",
round((sum(a.bytes//)-sum(nvl(b.free_space1//,)))
*/sum(a.bytes//),) as \"Used_percent%\" from dba_data_files a,(select sum(nvl(bytes,0)) free_space1,file_id from dba_free_space
group by file_id) b where a.file_id = b.file_id(+) group by a.TABLESPACE_NAME
order by \"Used_percent%\";" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 10.数据文件"
echo "--10.DB Files Info" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 300
SEt pagesize
col file_name format a80
col TABLESPACE_NAME for a30
select tablespace_name,file_id,status,bytes// FileSizeM,file_name from dba_data_files order by tablespace_name;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 11.查看数据文件的扩展方式"
echo "--11.DB Files Extend" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 300
set pagesize
col FILE_NAME for a60
col TABLESPACE_NAME for a30
select file_id,file_name,tablespace_name,autoextensible
from dba_data_files order by file_id;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 12.查看表空间的扩展方式"
echo "--12.TBS Extend" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 120
select TABLESPACE_NAME, BLOCK_SIZE, EXTENT_MANAGEMENT, SEGMENT_SPACE_MANAGEMENT
from dba_tablespaces;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 13.临时表空间"
echo "--13.DB Temp TBS" >>$archive/${hostn}_oracle_$CKtime
echo "select FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES/1024/1024 \"BYTES(M)\", USER_BYTES/1024/1024 \"USER_BYTES(M)\", status from dba_temp_files;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 14.用户默认表空间"
echo "--14.User Default TBS" >>$archive/${hostn}_oracle_$CKtime
echo "set lines 200
set pages
col username for a20
col default_tablespace for a30
col temporary_tablespace for a30
select username, default_tablespace, temporary_tablespace from dba_users;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 15.数据库缓冲区高速缓存命中率"
echo "--15.DB Cache Hit" >>$archive/${hostn}_oracle_$CKtime
echo "select 1-(phy.value/(cur.value+con.value))
from v\$sysstat cur, v\$sysstat con, v\$sysstat phy
where cur.name = 'db block gets'
and con.name = 'consistent gets'
and phy.name = 'physical reads';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 16.重写不等待比率"
echo "--16.Redo nowaits" >>$archive/${hostn}_oracle_$CKtime
echo "select (req.value*5000)/entries.value
from v\$sysstat req,v\$sysstat entries
where req.name = 'redo log space requests'
and entries.name = 'redo entires';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 17.库高速缓存命中率"
echo "--17.Library Cache Hit" >>$archive/${hostn}_oracle_$CKtime
echo "select namespace,gethitratio from v\$librarycache;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 18.数据字典高速缓存Getmisses对gets的目标比例"
echo "--18.DB Dic cache" >>$archive/${hostn}_oracle_$CKtime
echo "select sum(getmisses)/sum(gets) from v\$rowcache;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 19.用户对像(表、索引、大小)"
echo "--19.User objects" >>$archive/${hostn}_oracle_$CKtime
echo "col OWNER for a30
col SEGMENT_NAME for a33
col PARTITION_NAME for a22
col SEGMENT_TYPE for a11
col TABLESPACE_NAME for a30
set lines
set pages
select OWNER ,SEGMENT_NAME,PARTITION_NAME,SEGMENT_TYPE,TABLESPACE_NAME,bytes// as table_size_M
from Dba_Segments where SEGMENT_TYPE='TABLE' order by OWNER;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 20.检查是否有失效的索引"
echo "--20.Check invalid Ind" >>$archive/${hostn}_oracle_$CKtime
echo "set lines 333
set pages
select index_name, owner, status, tablespace_name
from dba_indexes
where owner not in('SYS','SYSTEM')
and status != 'VALID'
and tablespace_name is not null
union all
select index_name, index_owner owner, status, tablespace_name
from dba_ind_partitions
where index_owner not in ('SYS','SYSTEM')
and status <> 'USABLE'
and tablespace_name is not null;
select '' as a from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 21.检查数据库会话连接占用率"
echo "--21.Check DB Sessions" >>$archive/${hostn}_oracle_$CKtime
echo "col TOT_SESSIONS for a15
select cur_sessions, tot_sessions, a.cur_sessions/b.tot_sessions* \"sessions used%\"
from (select count(*) cur_sessions from v\$session) a,
(select value tot_sessions from v\$parameter where name = 'sessions') b;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 22.检查数据库会话连接历史最高值"
echo "--22.Highwater of Session" >>$archive/${hostn}_oracle_$CKtime
echo "select HIGHWATER
from dba_high_water_mark_statistics
where name = 'SESSIONS';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime echo "######################## 23.检查数据库Job状态"
echo "--23.Check Status of Job" >>$archive/${hostn}_oracle_$CKtime
echo "set linesize 333
col what for a30
col NEXT_DATE for a30
col INTERVAL for a30
select job, what, next_date, INTERVAL, BROKEN
from dba_jobs
where BROKEN != 'N';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>$archive/${hostn}_oracle_$CKtime
echo "" >>$archive/${hostn}_oracle_$CKtime
##################################################################### echo "Check completed."
echo "The Collected result saved in $archive/${hostn}_oracle_$CKtime."
echo ""

执行过程:

[oracle@rac2 checkdir]$ sh ORA_check.sh 

ORAWatcher Version:1.0.

Please input system passwd: ipii314
Starting ... ######################## .数据库版本
######################## .控制文件
######################## .pfile、spfile
######################## .字符集
######################## .归档状态
######################## .参数设置
######################## .回滚段存储位置
######################## .redolog
######################## .查看表空间大小及利用率
######################## .数据文件
######################## .查看数据文件的扩展方式
######################## .查看表空间的扩展方式
######################## .临时表空间
######################## .用户默认表空间
######################## .数据库缓冲区高速缓存命中率
######################## .重写不等待比率
######################## .库高速缓存命中率
######################## .数据字典高速缓存Getmisses对gets的目标比例
######################## .用户对像(表、索引、大小)
######################## .检查是否有失效的索引
######################## .检查数据库会话连接占用率
######################## .检查数据库会话连接历史最高值
######################## .检查数据库Job状态
Check completed.
The Collected result saved in /home/oracle/checkdir/archive/rac2_oracle_2017--14_22:.log. //巡检结果保存位置
 

Linux上的oracle巡检脚本的更多相关文章

  1. 在 linux 上运行 oracle sql脚本

    方法一 su - oracle  //切换到oracle用户模式下 sqlplus /nolog  //登录sqlplus connect /as sysdba; //连接orcale @sql脚本路 ...

  2. 数据库系统入门 | Oracle Linux上部署Oracle 11g服务,并实现SSH远程登录管理

    文章目录 写在前面 一.实验内容 二.实验前期准备 1.软件目录 2.准备一些配置文件.脚本文件 三.实验方案(具体步骤) (一)在虚拟机上安装Oracle Linux (二)在Linux上安装Ora ...

  3. Oracle巡检脚本:ORAWatcher.sh

    Oracle巡检脚本:ORAWatcher.sh #!/usr/bin/ksh echo "" echo "ORAWatcher Version:1.0.1" ...

  4. linux上备份Oracle时EXP-00091的错误解决方法

    unix/linux上备份Oracle时EXP-00091的错误解决方法 unix/linux上备份数据时的错误解决方法 EXP-00091: Exporting questionable stati ...

  5. linux上安装oracle

    Linux上安装Oracle 10g:  http://69520.blog.51cto.com/59520/91156

  6. [转载]linux上安装oracle

    原文地址:linux上安装oracle作者:天涯恨客 1.创建oinstall组 [root@xieqing ~]# groupadd oinstall 创建dba组 [root@xieqing ~] ...

  7. DBA_在Linux上安装Oracle Database11g数据库(案例)

    2014-08-08 Created By BaoXinjian

  8. 在Linux上安装Oracle RAC 12 c(12.1) 虚拟机,一步一步向导

    Oracle RAC 12 c(12.1)在Linux上安装虚拟机,一步一步向导 今天我们将看到如何安装 12 c版本1 RAC(真正的应用程序集群)数据库2 Linux 64位的虚拟机 使用VMWa ...

  9. Linux上安装Oracle的教程-centos7

    一.安装Oracle前准备 1.创建运行oracle数据库的系统用户和用户组   [humf@localhost ~]$ su root #切换到root   Password:   [root@lo ...

随机推荐

  1. React对比Vue(一些小细节的差异)

    @1===>发现一个神奇的地方在对数组进行增加删除的时候 react中一个输入框点击enter键,然后数组push,然后渲染 <input ref='valInput' onKeyUp={ ...

  2. Cocos Creator 对象池cc.NodePool的使用

    对象池cc.NodePool把层级管理器中的节点拖进资源管理器中就创建了预制体:let和var 一样,是声明变量的关键词, 同一个变量名时,var 即使在{}内也作用全局,let有范围:(1)将需要数 ...

  3. SpringMVC注解式开发之接收请求参数

    逐个接收(涉及注解@RequestParam) index.jsp的name必须和后端的名字一致,第一种才可以实现. 以对象形式整合接收 域属性参数的接收 数组或集合参数的接收 restfull风格传 ...

  4. mysql 5.6 每天凌晨12:00 重置sequence表中的某个值

    #.创建evevt要调用的存储过程update_current_value_procedure delimiter // drop procedure if exists update_current ...

  5. 软工网络15团队作业4——Alpha阶段敏捷冲刺8.0

    软工网络15团队作业4--Alpha阶段敏捷冲刺8.0 1.每天举行站立式会议,提供当天站立式会议照片一张. 2.项目每个成员的昨天进展.存在问题.今天安排. 2.1 任务完成安排: 成员 昨日已完成 ...

  6. node.js中ws模块创建服务端和客户端,网页WebSocket客户端

    首先下载websocket模块,命令行输入 npm install ws 1.node.js中ws模块创建服务端 // 加载node上websocket模块 ws; var ws = require( ...

  7. 20165305 实验二:Java面向对象程序设计

    2-1 参考 http://www.cnblogs.com/rocedu/p/6371315.html#SECUNITTEST 参考http://www.cnblogs.com/rocedu/p/67 ...

  8. word2vec原理知识铺垫

    word2vec: 词向量计算工具====>训练结果 词向量(word embedding) 可以很好的度量词与词的相似性,word2vec为浅层神经网络 *值得注意的是,word2vec是计算 ...

  9. 教你如何修改CentOS系统上的时间

    直接看命令:

  10. Python爬虫【四】Scrapy+Cookies池抓取新浪微博

    1.设置ROBOTSTXT_OBEY,由true变为false 2.设置DEFAULT_REQUEST_HEADERS,将其改为request headers 3.根据请求链接,发出第一个请求,设置一 ...