IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

Oracle 每天自动生成AWR报告

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

经验丰富的老员工希望能够每天为数据库生成1个AWR报告,以便于后期分析数据库的性能变化,手动生成太麻烦,查了一下资料,发现可以自动生成,过程如下。

数据库环境:11gR2 RAC(双节点)

AWR报告:由于是RAC数据库,希望生成每个节点的报告及全局报告,时间段为:第一天的0点~第二天的0点。

(1)在oracle服务器上创建路径

server2$[/home/oracle]mkdir awrreport

(2)创建directory并授权(使用sys账户执行)

create or replace directory DIR_AWRREPORT as '/home/oracle/awrreport';
grant read,write on directory DIR_AWRREPORT to mydba;                    

grant select on v_$database to mydba;
grant select on dba_hist_snapshot to mydba;
grant execute on sys.dbms_workload_repository to mydba;

(3)编写脚本(使用监控账户mydba执行)

CREATE OR REPLACE PROCEDURE auto_awrreport
AS

start_snap number;
end_snap number;
rpt_interval number := 24; 
start_time varchar2(14);
end_time varchar2(14);
awr_file utl_file.file_type;
v_dbid number;
v_dbname varchar2(20);

begin

select dbid,name into v_dbid,v_dbname from v$database;


select max(snap_id) into end_snap from dba_hist_snapshot;
start_snap := end_snap-rpt_interval;


select to_char(end_interval_time-rpt_interval/24, 'yyyymmddhh24'),to_char(end_interval_time, 'yyyymmddhh24')
into start_time,end_time
from dba_hist_snapshot
where snap_id = end_snap and instance_number = 1;


awr_file := utl_file.fopen('DIR_AWRREPORT',lower(v_dbname)||'_1_'||start_time||'_'||end_time||'.html', 'a',32767);
for awr_info in (select output from table(dbms_workload_repository.awr_report_html(v_dbid,1,start_snap,end_snap,0))) loop
UTL_FILE.put_line(awr_file,awr_info.output);
end loop;
utl_file.fclose(awr_file);


awr_file := utl_file.fopen('DIR_AWRREPORT',lower(v_dbname)||'_2_'||start_time||'_'||end_time||'.html', 'a',32767);
for awr_info in (select output from table(dbms_workload_repository.awr_report_html(v_dbid,2,start_snap,end_snap,0))) loop
UTL_FILE.put_line(awr_file,awr_info.output);
end loop;
utl_file.fclose(awr_file);


awr_file := utl_file.fopen('DIR_AWRREPORT',lower(v_dbname)||'_global_'||start_time||'_'||end_time||'.html', 'a',32767);
for awr_info in (select output from table(dbms_workload_repository.awr_global_report_html(l_dbid => v_dbid,l_inst_num => '',l_bid => start_snap,l_eid => end_snap,l_options => 0))) loop
UTL_FILE.put_line(awr_file,awr_info.output);
end loop;
utl_file.fclose(awr_file);

end auto_awrreport;

(4)授予监控用户执行procedure权限(使用sys账户)

grant execute on mydba.auto_awrreport to mydba;

(5)创建job,每天晚上12:30执行(监控账户)

declare
job1 number;
begin
sys.dbms_job.submit(job => job1,
what => 'auto_awrreport;',
next_date => sysdate,
interval => 'TRUNC(SYSDATE+1) + 30/(24*60)',
instance => 2
); 
end;

文章永久链接:https://tech.souyunku.com/?p=35210


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(61) 打赏



未经允许不得转载:搜云库技术团队 » Oracle 每天自动生成AWR报告

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367