轉貼:批量生成awr報告指令碼

浪漫雙魚發表於2011-06-07

awr報告批量生成工具,生成指定快照區間內每兩個快照之間的awr報告。

使用方法:

1、直接使用:SQL>@awrrpt_batch.sql start_snap end_snap,如SQL>@awrrpt_batch.sql 88 99

2、互動模式:SQL>@awrrpt_batch.sql

awr報告路徑會在輸出結果中顯示

/*
usage:
1、noninteractive:
SQL>@awrrpt_batch.sql start_snap end_snap
2、interactive:
SQL>@awrrpt_batch.sql
*/
set serveroutput on;
set feedback off;
set linesize 120;
prompt ***************************************************************;
prompt usage:;
prompt 1、noninteractive:SQL>@awrrpt_batch.sql start_snap end_snap;
prompt 2、interactive   :SQL>@awrrpt_batch.sql;
prompt ***************************************************************;
pause press enter to continue or ctrl-c to exit.;
col snap_id for 999999999;
col startup_time for a30;
col begin_interval_time for a30;
col end_interval_time for a30;
select snap_id,startup_time,begin_interval_time,end_interval_time from dba_hist_snapshot order by snap_id;
exec dbms_output.put_line(chr(13)||chr(10)||'please enter start and end snap_id:');
declare
v_dbid number;
v_instance number;
v_b_id number;
v_e_id number;
v_code number;
v_errm varchar2(300);
v_sql varchar2(300);
v_html varchar2(20000);
cur_awrrpt_html SYS_REFCURSOR;
cur_snapshot SYS_REFCURSOR;
fileID utl_file.file_type;
v_filename varchar2(30);
v_snap_id number;
v_startup_time timestamp(3);
v_begin_snap_time timestamp(3);
v_end_snap_time   timestamp(3);
v_dpath varchar2(60);
begin
v_b_id:=&1;
v_e_id:=&2;
dbms_output.put_line(chr(13)||chr(10)||'awrrpt report files:');
for k in v_b_id..v_e_id-1 loop
v_filename:='awrrpt_'||k||'_'||(k+1)||'.html';
fileID:=utl_file.fopen('DATA_PUMP_DIR',v_filename,'a',32767);
select dbid into v_dbid from v$database;
select instance_number into v_instance from v$instance;
v_sql:='select output from table(dbms_workload_repository.awr_report_html('||v_dbid||','||v_instance||','||k||','||(k+1)||',8))';
open cur_awrrpt_html for v_sql;
loop
exit when cur_awrrpt_html%notfound;
fetch cur_awrrpt_html into v_html;
utl_file.put_line(fileID,v_html);
end loop;
utl_file.fclose(fileID);
execute immediate 'select directory_path from dba_directories where directory_name=:dname' into v_dpath using 'DATA_PUMP_DIR';
dbms_output.put_line(v_dpath||v_filename);
end loop;
exception
when others then
v_code:=SQLCODE;
v_errm:=SQLERRM;
dbms_output.put_line('ERROR CODE'||v_code||':'||v_errm);
end;
/

SQL>@awrrpt_batch.sql

……………………………..
SNAP_ID STARTUP_TIME                   BEGIN_INTERVAL_TIME            END_INTERVAL_TIME
———- —————————— —————————— ——————————
96 22-2月 -11 08.22.28.000 上午   22-2月 -11 02.00.29.156 下午   22-2月 -11 03.00.58.750 下午
97 22-2月 -11 08.22.28.000 上午   22-2月 -11 03.00.58.750 下午   22-2月 -11 04.00.07.375 下午
98 22-2月 -11 08.22.28.000 上午   22-2月 -11 04.00.07.375 下午   22-2月 -11 05.00.24.750 下午
99 22-2月 -11 06.25.34.000 下午   22-2月 -11 06.25.34.000 下午   22-2月 -11 06.36.58.046 下午
100 22-2月 -11 06.25.34.000 下午   22-2月 -11 06.36.58.046 下午   22-2月 -11 07.00.29.140 下午
101 22-2月 -11 06.25.34.000 下午   22-2月 -11 07.00.29.140 下午   22-2月 -11 08.00.56.218 下午

please enter start and end snap_id:
原值   20:      v_b_id:=&1;
新值   20:      v_b_id:=94;
原值   21:      v_e_id:=&2;
新值   21:      v_e_id:=96;

awrrpt report files:
D:\oracle\admin\orcl11g\dpdump\awrrpt_94_95.html
D:\oracle\admin\orcl11g\dpdump\awrrpt_95_96.html

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11088128/viewspace-697294/,如需轉載,請註明出處,否則將追究法律責任。

相關文章