zoukankan      html  css  js  c++  java
  • 批量生成AWR报告(转载总结)

    【前提】

       对Oracle进行性能分析其中一个“帮手”就是Oracle的AWR报告

       PS:Oracle的企业版才有AWR报告,标准版是没有的{可以导出来,但是没有数据显示}

    【需求】

        当需要针对某个月的Oracle性能进行分析时,就需要查看AWR报告,需要“一个小时生成一个报告,连续一个月”这样的计划任务

        这里涉及到的建议是: 如果AWR报告的时间间隔太久{比如:导出的是今日的00:00后日的12:00的AWR报告},这样的报告没办法确切的分析到Oracle数据库在高峰(或发生问题时)的原因,或是状况,所以最好能够保持AWR报告的时间长度为1小时

    【导出的机制】

         Oracle的AWR报告在生成时是从一个表中进行抓取的,但是需要提供参数来调取需要的部分,以下为AWR导出的SQL:

      -- call the table function to generate the report
        select output from table(dbms_workload_repository.&fn_name( :dbid,
                                                                    :inst_num,
                                                                    :bid, :eid,
                                                                    :rpt_options ));
    

    【批量导出AWR报告脚本】

         以下为其余博主改造的脚本,贴来这记录一下,并学习学习:

        set serveroutput on;
        set feedback off;
        set linesize 300;
        prompt ***************************************************************;
        prompt usage:
        prompt 1.noninteractive : SQL>@awrrpt_batch.sql dbid instance_num start_snap end_snap;
        prompt 2.interactive : SQL>@awrrpt_batch.sql;
        prompt author : Darren_Guo
        prompt ***************************************************************;
        pause press enter to continue or ctrl-c to exit.;
        col snap_id for 999999999;
        col snap dbid 9999999999;
        col startup_time for a30;
        col begin_interval_time for a30;
        col end_interval_time for a30;
        select dbid,snap_id,instance_number,startup_time,begin_interval_time,end_interval_time from dba_hist_snapshot order by dbid,instance_number,snap_id,;
        exec dbms_output.put_line(chr(13)||chr(10)||'please enter dbid,inst_number,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_dbid:=&1;
        v_instance:=&2;
        v_b_id:=&3;
        v_e_id:=&4;
        dbms_output.put_line(chr(13)||chr(10)||'awrrpt report files:');
        for k in v_b_id..v_e_id-1 loop
        v_filename:='gyl_'||k||'_'||(k+1)||'.html';
        fileID:=utl_file.fopen('DATA_PUMP_DIR',v_filename,'a',32767);
        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;
        /
    
  • 相关阅读:
    leetcode-String to Integer (atoi)
    2014薪水
    Ubunt下的软件集
    ubuntu常用软件
    python模块安装
    ubuntu下玩三国杀
    递归函数
    匿名函数
    装饰器函数
    生成器
  • 原文地址:https://www.cnblogs.com/frankielf0921/p/7659123.html
Copyright © 2011-2022 走看看