批量生成awr报告

       自动生成awr脚本,@awrrpt_batch.sql start_snap end_snap 或>@awrrpt_batch.sql,生成文件在数据库服务器directory的DATA_PUMP_DIR中,可惜不能远程生成。

/*
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;
/

附:生成awr报告实际起作用的函数
select output from table(dbms_workload_repository.awr_report_text(dbid,db_num,bsnid,esnid,l_options));
select output from table(dbms_workload_repository.awr_report_html(dbid,db_num,bsnid,esnid,l_options));
select output from table(dbms_workload_repository.awr_report_html(1311728654,1,2853,2854,0));

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值