Oracle巡检脚本:ORAWatcher.sh
Oracle巡检脚本:ORAWatcher.sh
#!/usr/bin/ksh
echo ""
echo "ORAWatcher Version:1.0.1"
echo ""
#Create Time:--
#Update Time:-- :
######################################################################
#数据库连接设置
######################################################################
sqlstr=$
test $
if [ $? = ]; then
echo
echo "Info...You did not enter a value for sqlstr."
echo "Info...Using default value = system/system"
sqlstr="system/system"
fi ######################################################################
# Create log subdirectories if they don't exist
######################################################################
if [ ! -d archive ]; then
mkdir archive
fi echo "$sqlstr"
echo "Starting Data Collection..."
echo ""
######################################################################
hostn=`hostname`
hour=`date +'%m.%d.%y.%H00.dat'`
echo "`date` collect...">archive/${hostn}_oracle_$hour
######################################################################
echo "######################## 1.数据库版本"
echo "select ' ' as \"--1.Database Version\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "Select version FROM Product_component_version
Where SUBSTR(PRODUCT,,)='Oracle';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 2.控制文件"
echo "select ' ' as \"--2.Control files\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "select name from v\$controlfile;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 3.pfile、spfile"
echo "select ' ' as \"--3.Parameter files\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "show parameter pfile;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 4.字符集"
echo "select ' ' as \"--4.DB Character\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 5.归档状态"
echo "select ' ' as \"--5.DB Archive Mode\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "set linesize 333
show parameter log_archive" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 6.参数设置"
echo "select ' ' as \"--6.Parameter Config\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "set linesize 500
set pages
show parameter;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 7.回滚段存储位置"
echo "select ' ' as \"--7.Undo Info\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 8.redolog"
echo "select ' ' as \"--8.Redolog Files\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 9.查看表空间大小及利用率"
echo "select ' ' as \"--9.Tablespace Usage\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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,)) 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_$hour echo "######################## 10.数据文件"
echo "select ' ' as \"--10.DB Files Info\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 11.查看数据文件的扩展方式"
echo "select ' ' as \"--11.DB Files Extend\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 12.查看表空间的扩展方式"
echo "select ' ' as \"--12.TBS Extend\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 13.临时表空间"
echo "select ' ' as \"--13.DB Temp TBS\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 14.用户默认表空间"
echo "select ' ' as \"--14.User Default TBS\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 15.数据库缓冲区高速缓存命中率"
echo "select ' ' as \"--15.DB Cache Hit\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 16.重写不等待比率"
echo "select ' ' as \"--16.Redo nowaits\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 17.库高速缓存命中率"
echo "select ' ' as \"--17.Library Cache Hit\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "select namespace,gethitratio from v\$librarycache;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 18.数据字典高速缓存Getmisses对gets的目标比例"
echo "select ' ' as \"--18.DB Dic cache\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "select sum(getmisses)/sum(gets) from v\$rowcache;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 19.用户对像(表、索引、大小)"
echo "select ' ' as \"--19.User objects\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 20.检查是否有失效的索引"
echo "select ' ' as \"--20.Check invalid Ind\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 21.检查数据库会话连接占用率"
echo "select ' ' as \"--21.Check DB Sessions\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour echo "######################## 22.检查数据库会话连接历史最高值"
echo "select ' ' as \"--22.Highwater of Session\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
echo "select HIGHWATER
from dba_high_water_mark_statistics
where name = 'SESSIONS';" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour echo "######################## 23.检查数据库Job状态"
echo "select ' ' as \"--23.Check Status of Job\" from dual;" >my_sql.sql
sqlplus $sqlstr <my_sql.sql>>archive/${hostn}_oracle_$hour
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_$hour
###################################################################### echo "Collection completed."
echo "The Collected result saved in ./archive/${hostn}_oracle_$hour."
echo ""
Oracle巡检脚本:ORAWatcher.sh的更多相关文章
- Linux上的oracle巡检脚本
修改自大神博客:http://www.cnblogs.com/jyzhao/p/5364049.html 脚本巡检的优化:自动化,节省时间. 脚本需加强:巡检结果中有大量的sqlplus连接信息,后期 ...
- oracle巡检脚本备份
重做日志生成情况,一天生成日志大小:select round(sum(blocks*block_size)/1024/1024/1024,2) BLOCK from v\$archived_log w ...
- 巡检脚本OS+Oracle
巡检脚本 主机巡检脚本:OSWatcher.sh Oracle巡检脚本:ORAWatcher.sh 脚本使用方法 1.建立脚本放置目录 # mkdir /var/collect 2.把脚本ORAWat ...
- Oracle运行脚本:exp,hist 和 err
上一篇我们讲到:首次使用rman备份数据库时,为了安全起见,我们应将整个数据库exp出来. 显而易见,每次都手敲exp代码是不可取的. ----费时费力还不规范! 为此,我们可以写一个exp脚本,之后 ...
- 主机巡检脚本:OSWatcher.sh
主机巡检脚本:OSWatcher.sh 2016-09-26更新,目前该脚本只支持Linux操作系统,后续有需求可以继续完善. 注意: 经测试,普通用户执行脚本可以顺利执行前9项检查: 第10项,普通 ...
- Oracle - 数据库巡检脚本
分享一个oracle数据库巡检脚本,欢迎大家使用,希望大家在用的过程中发现脚本中的错误并提出改进意见. -- 数据库巡检脚本 -- 版本号2.1 -- 该脚本仅对数据库的做一个初步的巡检,具体的优化方 ...
- 小麦苗数据库巡检脚本,支持Oracle、MySQL、SQL Server和PG等数据库
目录 一.巡检脚本简介 二.巡检脚本特点 三.巡检结果展示 1.Oracle数据库 2.MySQL数据库 3.SQL Server数据库 4.PG数据库 5.OS信息 四.脚本运行方式 1.Oracl ...
- Linux/hp unix/AIX日常巡检脚本(转)
以下为Linux/hp unix/AIX日常巡检脚本,大家可以参考着进行改写,用于自己的服务器. #!/usr/bin/ksh syserrdate=`date +"%m/%d"` ...
- linux手动或者自动启动oracle11g的服务 Oracle 自动启动脚本
手动启动: [oracle@localhost ~]$ sqlplus SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 26 23:39:52 2 ...
随机推荐
- Linux 下安装中文 ctex 指南
大家在用 $\LaTeX$ 进行中文排版时相信会遇到不少问题,而$\textbf{ctex}$套装的出现则有效的解决了这一问题,只要安装了$\textbf{ctex}$那么在文中不用进行引用设置就可以 ...
- 定时任务crontab 例子
查看定时任务格式 [root@centos ~]# vim /etc/crontab 1 SHELL=/bin/bash 2 PATH=/sbin:/bin:/usr/sbin:/usr/bin 3 ...
- *HDU1850 博弈
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- *HDU 1115 计算几何
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Django数据导入
从网上下载的一些数据,excel表格,xml文件,txt文件等有时候我们想把它导入数据库,应该如何操作呢? 以下操作符合 Django版本为 1.6 ,兼顾 Django 1.7, Django 1. ...
- 仿JQ基础架构,可扩展。
(function(win,doc,fn){ var events = [];//拷贝核心方法 var publicEvent = ["extend","f ...
- DataTable转List(备忘)
public static List ToList(DataTable dt) { List<Dictionary<string, object>> list = new Li ...
- windows和linux中搭建python集成开发环境IDE——如何设置多个python环境
本系列分为两篇: 1.[转]windows和linux中搭建python集成开发环境IDE 2.[转]linux和windows下安装python集成开发环境及其python包 3.windows和l ...
- SQL Server恢复软件SysTools SQL Recovery/SysTools SQL Server Recovery Manager
SQL Server恢复软件SysTools SQL Recovery/SysTools SQL Server Recovery Manager http://www.systoolsgroup.co ...
- CYQ.Data.Orm.DBFast 新增类介绍(含类的源码及新版本配置工具源码)
前言: 以下功能在国庆期就完成并提前发布了,但到今天才有时间写文介绍,主要是国庆后还是选择就职了,悲催的是上班的地方全公司都能上网,唯独开发部竟不让上网,是个局域网. 也不是全不能上,房间里有三台能上 ...