部署awr自动生成脚本

Oracle 10g之前,对数据库性能检测一般使用statspack工具。而从10g开始,oracle提供了一个新的工具:AWRAutomatic Workload Repository)。定期生成AWR报告并分析,有利于我们对数据库进行监控和调优。

 

使用awr有一个前提:参数statistics_level不能为basic。该参数默认为typical,如非必要不建议修改。

 

执行如下命令并根据提示输入信息,即可生成awr报告:

SQL>@?/rdbms/admin/awrrpt.sql

 

其实通过查看awrrpt.sql,可以看到,awrrpt.sql会调用awrrpti.sql

以下是awrrpti.sql部分内容:

 

-- ***************************************************

--   Customer-customizable report settings

--   Change these variables to run a report on different statistics

-- ***************************************************

-- The default number of days of snapshots to list when displaying the

-- list of snapshots to choose the begin and end snapshot Ids from.

--

--   List all snapshots

-- define num_days = '';

--

--   List no (i.e. 0) snapshots

-- define num_days = 0;

--

-- List past 3 day's snapshots

-- define num_days = 3;

--

-- Reports can be printed in text or html, and you must set the report_type

-- in addition to the report_name

--

-- Issue Report in Text Format

--define report_type='text';

--

-- Issue Report in HTML Format

--define report_type='html';

 

-- Optionally, set the snapshots for the report.  If you do not set them,

-- you will be prompted for the values.

--define begin_snap = 545;

--define end_snap   = 546;

 

-- Optionally, set the name for the report itself

--define report_name = 'awrrpt_1_545_546.html'

 

看到这里,我们已经发现,其实,只需要对上述参数手动define,就可以将生成awr的动作写成脚本,避免交互式操作。换句话说,可以部署在我们需要的主机上定期自动生成awr报告。

 

以下是脚本部分,awr的时间段定义为最大snap跨度(默认为7天):

 

#!/bin/ksh

 

for i in `cat SID.txt`

do

ORACLE_SID=$i

export ORACLE_SID

 

sqlplus /nolog<>/dev/null

connect / as sysdba

set heading off

spool tempfile.tmp

select  min(SNAP_ID)  from  dba_hist_snapshot;

spool off

!

MINSNAPID=`cat tempfile.tmp|grep -v "SQL>" |grep -v ^$`

 

sqlplus /nolog</dev/null

connect / as sysdba

set heading off

spool tempfile.tmp

select  max(SNAP_ID)  from  dba_hist_snapshot;

spool off

!

MAXSNAPID=`cat tempfile.tmp|grep -v "SQL>" |grep -v ^$`

 

echo "${i}_awrrpt_`date +%Y%m%d`.html" >tempfile.tmp

REPORT_NAME=`cat tempfile.tmp`

rm tempfile.tmp

 

echo "define num_days = 7">awrrpt_tmp.sql

echo "define report_type = 'html'">>awrrpt_tmp.sql

echo "define begin_snap = $MINSNAPID">>awrrpt_tmp.sql

echo "define end_snap   = $MAXSNAPID">>awrrpt_tmp.sql

echo "define report_name = '$REPORT_NAME'">>awrrpt_tmp.sql

echo "@@?/rdbms/admin/awrrpt" >>awrrpt_tmp.sql

 

sqlplus /nolog</dev/null

connect / as sysdba

@awrrpt_tmp.sql

!

done

 

 

SID.txt文件里,可以将需要生成awr的实例写入其中。

 

SID.txt

 

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20750200/viewspace-696909/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20750200/viewspace-696909/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值