ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle10g自动生成AWR分析报告的脚本

Oracle10g自动生成AWR分析报告的脚本

原创 Linux操作系统 作者:tolywang 时间:2009-09-16 16:40:44 0 删除 编辑
直接把脚本贴在下面,用Oracle的job或crontab调用shell脚本,就可以定时生成新近两次snapshot的AWR报告了.以下脚本在winxp sp1,10.2.0.1环境下通过.

awrrpt_zheng.sql:

Rem created by bill zheng 05-sep-2007 hangzhou
Rem awrrpt_zheng.sql

set echo off;
set veri off;
set feedback off;
set termout on;
set heading off;

variable rpt_options number;

define NO_OPTIONS = 0;
-- define ENABLE_ADDM = 8;

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;
begin
select max(snap_id)-1 into :bid from dba_hist_snapshot;
select max(snap_id) into :eid from dba_hist_snapshot;
select dbid into :dbid from v$database;
select instance_number into :inst_num from v$instance;
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;
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
---end---

可能用以下的shell脚本调用:

#!/usr/bin/sh
# First, we must set the environment . . . .
ORACLE_SID=zjdxhr
export ORACLE_SID
ORACLE_HOME=/oracle/app/ora10g/product/10.1.0
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
cd /oracle/app/ora10g/awr --脚本目录位置
$ORACLE_HOME/bin/sqlplus /nolog<connect / as sysdba;
@awrrpt_zheng.sql
exit
!

 

http://aimhigh.itpub.net/post/34335/392648  

 

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

请登录后发表评论 登录
全部评论
Oracle , MySQL, SAP IQ, SAP HANA, PostgreSQL, Tableau 技术讨论,希望在这里一起分享知识,讨论技术,畅谈人生 。

注册时间:2007-12-10

  • 博文量
    5595
  • 访问量
    13202646