ITPub博客

首页 > 数据库 > Oracle > 自动收集awr报告

自动收集awr报告

原创 Oracle 作者:OGG-01161 时间:2015-08-25 09:07:46 0 删除 编辑

每天自动收集awr脚本
1、crontab 配置

30  20 * * *  /home/oracle/autoawr/awr_test.sh

2、脚本内容

more awr_test.sh
. $HOME/.profile
datetime=`date  +%Y%m%d%H`
cd /home/oracle/autoawr/
export ORACLE_SID=hsdb
$ORACLE_HOME/bin/sqlplus /nolog<<!
connect / as sysdba;
@awr1.sql
exit
!

more awr1.sql
set echo off;
set veri off;
set feedback off;
set termout on;
set heading off;
variable rpt_options number;
define NO_OPTIONS = 0;
rem according to your needs, the value can be 'text' or 'html'
define report_type='html';
begin
:rpt_options := &NO_OPTIONS;
end;
/
variable dbid number;
variable inst_num number;
variable bid number;
variable eid number;
variable day number;
variable insname varchar2(12);
begin
select max(snap_id)-1 into :bid from dba_hist_snapshot s where to_char(s.end_interval_time,'hh24')=11 ;
select max(snap_id) into :eid from dba_hist_snapshot s where to_char(s.end_interval_time,'hh24')=11 ; 
select dbid into :dbid from v$database;
select instance_number,instance_name into :inst_num,:insname from v$instance;
select to_number(to_char(sysdate,'yyyymmdd.hh24')) into :day from dual;
end;
/
column ext new_value ext noprint
column fn_name new_value fn_name noprint;
column lnsz new_value lnsz noprint;
select 'txt' ext from dual where lower('&report_type') = 'text';
select 'html' ext from dual where lower('&report_type') = 'html';
select 'awr_report_text' fn_name from dual where lower('&report_type') = 'text';
select 'awr_report_html' fn_name from dual where lower('&report_type') = 'html';
select '80' lnsz from dual where lower('&report_type') = 'text';
select '1500' lnsz from dual where lower('&report_type') = 'html';
set linesize &lnsz;
column report_name new_value report_name noprint;
--select 'sp_'||:bid||'_'||:eid||'.'||'&ext' report_name from dual;
select :insname||'_'||:day||'.15to16.'||'&ext' report_name from dual;
set termout off;
spool &report_name;
select output from table(dbms_workload_repository.&fn_name(:dbid, :inst_num,:bid, :eid,:rpt_options ));
spool off;
set termout on;
clear columns sql;
ttitle off;
btitle off;
repfooter off;
undefine report_name
undefine report_type
undefine fn_name
undefine lnsz
undefine NO_OPTIONS





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

请登录后发表评论 登录
全部评论

注册时间:2012-08-11

  • 博文量
    55
  • 访问量
    128667