记一种方便的awr收集方法,该脚本可以按小时收集目标时段的awr

素材:awr_generate.sql(具体脚本内容请见本文末尾)

(1)将awr_generate.sql置于数据库服务器本地路径,如F:\perf\awr下

(2)sqlplus连接数据库

C:\Users\Administrator>sqlplus / as sysdba

(3)调用SQL脚本,时段参数等

SQL> @F:\perf\awr\awr_generate.sql

Current Instance
~~~~~~~~~~~~~~~~

DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
1481259953 ORCL 1 orcl

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 1481259953 1 ORCL orcl WIN-JQK18VPJ
9K8

Using 1481259953 for database Id
Using 1 for instance number

Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing <return> without
specifying a number lists all completed snapshots.

输入 num_days 的值: 1

Listing the last day's Completed Snapshots

Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
orcl ORCL 10429 11 11月 2018 00:00 1
10430 11 11月 2018 01:00 1
10431 11 11月 2018 02:00 1
10432 11 11月 2018 03:00 1
10433 11 11月 2018 04:00 1
10434 11 11月 2018 05:00 1
10435 11 11月 2018 06:00 1
10436 11 11月 2018 07:00 1
10437 11 11月 2018 08:00 1
10438 11 11月 2018 09:00 1
10439 11 11月 2018 10:00 1
10440 11 11月 2018 11:00 1
10441 11 11月 2018 12:00 1
10442 11 11月 2018 13:00 1
10443 11 11月 2018 14:00 1
10444 11 11月 2018 15:00 1
10445 11 11月 2018 16:00 1
10446 11 11月 2018 17:00 1

10447 11 11月 2018 18:00 1
10448 11 11月 2018 19:00 1
10449 11 11月 2018 20:00 1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入 begin_snap 的值: 10447
Begin Snapshot Id specified: 10447

输入 end_snap 的值: 10449
End Snapshot Id specified: 10449

Specify output script name
~~~~~~~~~~~~~~~~~~~~~~~~~~
This script produces output in the form of another SQL script
The output script contains the commands to generate the AWR Reports

The default output file name is awr-gene.sql

Script written to awr-gene.sql - check and run in order to generate AWR report
s...

SQL> @awr-gene.sql
Beginning AWR Generation...
Creating AWR Report awrrpt_1_20181111_1800__20181111_1900.html for instance numb
er 1 snapshots 10447 to 10448

(4)从当前用户目录路径下(C:\Users\Administrator)查找对应的awr文件

awr_generate.sql      script

--   Script for creating multiple consecutive Oracle AWR/ADDM Reports
-- between the specificed start and end snapshot IDs, for all instances
--
-- See GitHub repository at https://github.com/flashdba/scripts
--
-- modify by falent for get multiple awr report using snap time
--
set feedback off
set echo off
set verify off
set timing off -- Set AWR_FORMAT to "text" or "html"
--define AWR_FORMAT = 'text'
define AWR_FORMAT = 'html'
define DEFAULT_OUTPUT_FILENAME = 'awr-gene.sql'
define DEFAULT_ADDM_FILENAME = 'addm-gene.sql'
define NO_ADDM = 8 -- Get values for dbid and inst_num before calling awrinput.sql set echo off heading on
column inst_num heading "Inst Num" new_value inst_num format 99999;
column inst_name heading "Instance" new_value inst_name format a12;
column db_name heading "DB Name" new_value db_name format a12;
column dbid heading "DB Id" new_value dbid format 9999999999 just c; prompt
prompt Current Instance
prompt ~~~~~~~~~~~~~~~~ select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
from v$database d,
v$instance i; -- Call the Oracle common input script to setup start and end snap ids
@@?/rdbms/admin/awrinput.sql -- Ask the user for the name of the output script
prompt
prompt Specify output script name
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt This script produces output in the form of another SQL script
prompt The output script contains the commands to generate the AWR Reports
prompt
prompt The default output file name is &DEFAULT_OUTPUT_FILENAME
prompt set heading off
--column outfile_name new_value outfile_name noprint;
--select 'Using the output file name ' || nvl('&outfile_name','&DEFAULT_OUTPUT_FILENAME'), nvl('&outfile_name','&DEFAULT_OUTPUT_FILENAME') outfile_name from sys.dual; set linesize 800
set serverout on
set termout off -- spool to outputfile
spool &DEFAULT_OUTPUT_FILENAME -- write script header comments
prompt REM Temporary script created
prompt REM Used to create multiple AWR reports between two snapshots
select 'REM Created by user '||user||' on '||sys_context('userenv', 'host')||' at '||to_char(sysdate, 'DD-MON-YYYY HH24:MI') from dual; set heading on -- Begin iterating through snapshots and generating reports
DECLARE c_dbid CONSTANT NUMBER := :dbid;
c_inst_num CONSTANT NUMBER := :inst_num;
c_start_snap_id CONSTANT NUMBER := :bid;
c_end_snap_id CONSTANT NUMBER := :eid;
c_awr_options CONSTANT NUMBER := &&NO_ADDM;
c_report_type CONSTANT CHAR(4):= '&&AWR_FORMAT';
v_awr_reportname VARCHAR2(120);
v_report_suffix CHAR(5); CURSOR c_snapshots IS
select inst_num, start_snap_id, end_snap_id,start_snap_time,end_snap_time
from (
select s.instance_number as inst_num,
s.snap_id as start_snap_id,
lead(s.snap_id,1,null) over (partition by s.instance_number order by s.snap_id) as end_snap_id,
to_char(s.end_interval_time,'YYYYMMDD_HH24MI') start_snap_time,
lead(to_char(s.end_interval_time,'YYYYMMDD_HH24MI'),1,null) over (partition by s.instance_number order by s.snap_id) as end_snap_time from dba_hist_snapshot s
where s.dbid = c_dbid
and s.snap_id >= c_start_snap_id
and s.snap_id <= c_end_snap_id
)
where end_snap_id is not null
order by inst_num, start_snap_id; BEGIN
--awr rpt
dbms_output.put_line('');
dbms_output.put_line('prompt Beginning AWR Generation...'); dbms_output.put_line('set heading off feedback off lines 800 pages 5000 trimspool on trimout on'); -- Determine report type (html or text)
IF c_report_type = 'html' THEN
v_report_suffix := '.html';
ELSE
v_report_suffix := '.txt';
END IF; -- Iterate through snapshots
FOR cr_snapshot in c_snapshots
LOOP
-- Construct filename for AWR report
v_awr_reportname := 'awrrpt_'||cr_snapshot.inst_num||'_'||cr_snapshot.start_snap_time||'__'||cr_snapshot.end_snap_time||v_report_suffix; dbms_output.put_line('prompt Creating AWR Report '||v_awr_reportname
||' for instance number '||cr_snapshot.inst_num||' snapshots '||cr_snapshot.start_snap_id||' to '||cr_snapshot.end_snap_id);
dbms_output.put_line('prompt'); -- Disable terminal output to stop AWR text appearing on screen
dbms_output.put_line('set termout off'); -- Set spool to create AWR report file
dbms_output.put_line('spool '||v_awr_reportname); -- call the table function to generate the report
IF c_report_type = 'html' THEN
dbms_output.put_line('select output from table(dbms_workload_repository.awr_report_html('
||c_dbid||','||cr_snapshot.inst_num||','||cr_snapshot.start_snap_id||','||cr_snapshot.end_snap_id||','||c_awr_options||'));');
ELSE
dbms_output.put_line('select output from table(dbms_workload_repository.awr_report_text('
||c_dbid||','||cr_snapshot.inst_num||','||cr_snapshot.start_snap_id||','||cr_snapshot.end_snap_id||','||c_awr_options||'));');
END IF; dbms_output.put_line('spool off'); -- Enable terminal output having finished generating AWR report
dbms_output.put_line('set termout on'); END LOOP; dbms_output.put_line('set heading on feedback 6 lines 100 pages 45'); dbms_output.put_line('prompt AWR Generation Complete'); END;
/ spool off
set termout on prompt
prompt Script written to &DEFAULT_OUTPUT_FILENAME - check and run in order to generate AWR reports...
prompt --clear columns sql
undefine AWR_FORMAT
undefine DEFAULT_OUTPUT_FILENAME
undefine NO_ADDME
undefine DEFAULT_ADDM_FILENAME
undefine TASK_NAME set feedback 6 verify on lines 200 pages 999

Oracle快速收集AWR的方案的更多相关文章

  1. Oracle 11g快速收集全库统计信息

    环境:Oracle 11.2.0.4 采用并行的方式,快速收集全库统计信息,多用于跨版本升级之后,对全库的统计信息重新进行快速收集: --开启计时 set timing on --设置并行收集 exe ...

  2. Oracle中的AWR,全称为Automatic Workload Repository

    Oracle中的AWR,全称为Automatic Workload Repository,自动负载信息库.它收集关于特定数据库的操作统计信息和其他统计信息,Oracle以固定的时间间隔(默认为1个小时 ...

  3. Oracle 10g收集数据库统计信息

    1.需求概述 2.实施步骤 3.回退方案 1.需求概述 某数据库由于整体统计信息不准确,多次出现部分业务SQL选错执行计划,从而导致性能下降影响到最终用户体验,目前通过SQL_PROFILE绑定执行计 ...

  4. (Oracle)自定义调用AWR

    Oracle->自动发送AWR报告 2016年9月21日 09:31 需求描述: 每日或定期手动使用AWR报告来检查Oracle数据库状态不仅耗时也费力,需求使用脚本自动收集AWR报告.   分 ...

  5. oracle 快速删除大批量数据方法(全部删除,条件删除,删除大量重复记录)

    oracle 快速删除大批量数据方法(全部删除,条件删除,删除大量重复记录) 分类: ORACLE 数据库 2011-05-24 16:39 8427人阅读 评论(2) 收藏 举报 oracledel ...

  6. [Oracle]快速构造大量数据的方法

    [Oracle]快速构造大量数据的方法: create table tab001(id integer primary key, val varchar2(100)); insert into tab ...

  7. oracle 快速复制表结构、表数据

      1.情景展示 根据现有的表,建一个新的表,要求:新表的结构与原有表的表结构一模一样,如何快速实现? 根据现有的表,建一个新的表,要求:新表的结构.数据与原表一模一样,如何实现快速复制旧表? 2.解 ...

  8. oracle 快速备份表数据

      oracle 快速备份表数据 CreateTime--2018年2月28日17:04:50 Author:Marydon UpdateTime--2017年1月20日11:45:07 1.1.9. ...

  9. (Oracle)自定义调用AWR&ADDM

    Oracle->自定义调用AWR&ADDM 需求描述: 前面设定每天自动生成AWR用于提供前一天的数据库状态信息,但因数据库和信息过多不利于直观检查.此次新增ADDM诊断. ADDM诊断 ...

随机推荐

  1. Uncaught TypeError: str.replace is not a function

    在做审核页面时,点击审核通过按钮不执行 后来F12控制台查看发现有报错 是因为flisnullandxyzero未执行 然后找出这个方法,此方法为公共方法,将这个方法复制出来 然后使用console. ...

  2. pig常用命令

    一.pig: pig提供了一个基于Hadoop的并行地执行数据流处理的引擎.它包含了一种脚本语言,称为Pig Latin.(类似SQL) 二.Pig Latin: 1.注释: 单行:-- 多行:/* ...

  3. POJ 1088 滑雪(简单的记忆化dp)

    题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...

  4. swift--如何设置子视图alpha不同于父视图

    //1.2加入商家标题评分容器 let titleWarp=UIView(frame: CGRectMake(, , screenObject.width, )); titleWarp.backgro ...

  5. Python - 三大器 迭代器,生层器,装饰器

    目录 Python - 三大器 迭代器,生层器,装饰器 一. 容器 二. 可迭代对象(iterable) 三. 迭代器 四. 生成器 五. 装饰器 1. 定义 六. 闭包 Python - 三大器 迭 ...

  6. 微信小程序如何引用iconfont图标

    最近在研究微信小程序,自己写demo的时候想要引用巴里巴巴图标库的图标,于是: @font-face { font-family: 'iconfont'; src: url('iconfont.eot ...

  7. 【Codeforces 158A】Next Round

    [链接] 我是链接,点我呀:) [题意] 让你找到排名的前k名,并列的话,如果分数大于0那么就算晋级 问你最后有多少人可以晋级. [题解] 按照题意模拟就好, 先按照a[max] = a[k]的规则找 ...

  8. hdu_1018_Big Number_201308191556

    Big NumberTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  9. hibernate之多对多映射

    目录 第一章 多对多的应用场景 第二章 多对多的映射配置案例 2-1 创建项目和表 2-2 创建持久化类和映射文件 2-3 配置映射文件 2-4 测试 第三章 总结 源码地址:https://gith ...

  10. 1.7-BGP⑤

    BGP Attributes/BGP属性 (通过BGP的属性,实现对BGP路由的选择/操纵) BGP Route Selection/BGP的选路原则: 1: The BGP forwarding t ...