[转]oracle awr报告生成和分析

转自:http://blog.csdn.net/cuker919/article/details/8767328

最近由于数据库cpu占用非常高,导致VCS常常自动切换,引起很多问题。

最近学习一下数据库awr分析数据库sql执行性能的分析报告。下面将初步讲解一下:

1、先登陆数据库,生成awr报告。

linux:~ # su - oracle
oracle@linux:~> sqlplus '/as sysdba'

SQL*Plus: Release 11.1.0.6.0 - Production on Sun Apr 7 14:02:38 2013

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

2、输入分析命令
SQL> @?/rdbms/admin/awrrpt

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

   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 2045388596 UTF8                1 utf8


Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: html

3、输入要生成报告的文件格式
Type Specified:  html


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

   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
* 2045388596        1 UTF8         utf8         linux

Using 2045388596 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.


4、输入要生成报告相隔的天数
Enter value for num_days: 1

Listing the last day's Completed Snapshots

                                                        Snap
Instance     DB Name        Snap Id    Snap Started    Level
------------ ------------ --------- ------------------ -----
utf8         UTF8              2809 26 Oct 2014 00:00      1
                                 2810 26 Oct 2014 01:00      1
                                 2811 26 Oct 2014 02:00      1
                                 2812 26 Oct 2014 03:00      1
                                 2813 26 Oct 2014 04:00      1
                                 2814 26 Oct 2014 05:00      1
                                 2815 26 Oct 2014 06:00      1
                                 2816 26 Oct 2014 07:00      1
                                 2817 26 Oct 2014 08:00      1
                                 2818 26 Oct 2014 09:00      1
                                 2819 26 Oct 2014 10:00      1
                                 2820 26 Oct 2014 11:00      1
                                 2821 26 Oct 2014 12:00      1


5、输入相隔的快照之间的Snap Id开始号和结束号

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 2809

Enter value for end_snap: 2821
End   Snapshot Id specified: 2821



Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_2809_2821.html.  To use this name,
press <return> to continue, otherwise enter an alternative.

6、输入生成报告的名字:

Enter value for report_name: 20130407awr.html

拿到20130407awr.html报告后进行数据库sql语句性能分析。下面是awr概念和主要分析名称解释(网上copy的资料,不一定全部对):

在网上找到几篇不错的文章:

对于awr参数的解释,比较全的文章

http://wenku.baidu.com/view/ae2ddbc29ec3d5bbfd0a7429.html

http://468302.blog.51cto.com/458302/998786    AWR中的时间模型(db time与cpu time 具体讲解)

http://www.oracledatabase12g.com/     oracle专家刘相兵博客

http://www.askmaclean.com/archives/maclean-little-contribute.html  刘相兵相关视频和文章

http://www.5ienet.com/note/html/stat/index.shtml

http://blog.itpub.net/26686207/    大牛博客:刘盛 网名leonarding

学用ORACLE_AWR和ASH特性

http://www.5ienet.com/note/html/ash_awr/index.shtml

-------------------------------------------------

Automatic Workload Repository(AWR)是10g引入的一个重要组件。    在里面存贮着近期一段时间内(默认是7天)数据库活动状态的详细信息。
    1、生成awr报告
    以oracle用户登录
    sqlplus / as sysdba
    @?/rdbms/admin/awrrpt.sql
    2、分析报告
    SQL ordered by Elapsed Time
    Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
    % Total DB Time is the Elapsed Time of the SQL statement divided into the Total Database Time multiplied by 100
    Elapsed Time (s)CPU Time (s)Executions Elap per Exec (s) % Total DB TimeSQL IdSQL ModuleSQL Text
    Elapsed Time(S) : SQL 语句执行用总时长,此排序就是按照这个字段进行的。注意该时间不是单个SQL 跑的时间,而是监控范围内SQL 执行次数的总和时间。单位时间为秒。Elapsed Time = CPU Time + Wait Time
    CPU Time(s) : 为SQL 语句执行时CPU 占用时间总时长,此时间会小于等于Elapsed Time 时间。单位时间为秒。
    Executions : SQL 语句在监控范围内的执行次数总计。
    Elap per Exec(s): 执行一次SQL 的平均时间。单位时间为秒。
    % Total DB Time : 为SQL 的Elapsed Time 时间占数据库总时间的百分比。
    SQL ID: SQL 语句的ID 编号,点击之后就能导航到下边的SQL 详细列表中,点击IE 的返回可以回到当前SQL ID 的地方。
    SQL Module : 显示该SQL 是用什么方式连接到数据库执行的,如果是用SQL*Plus 或者PL/SQL 链接上来的那基本上都是有人在调试程序。一般用前台应用链接过来执行的sql 该位置为空。
    SQL Text: 简单的sql 提示,详细的需要点击SQL ID .
    SQL ordered by CPU Time
    Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
    % Total DB Time is the Elapsed Time of the SQL statement divided into the Total Database Time multiplied by 100
    CPU Time (s)Elapsed Time (s)Executions CPU per Exec (s)% Total DB TimeSQL IdSQL ModuleSQL Text
    记录了执行占CPU 时间总和时间最长的TOP SQL( 注意是监控范围内该SQL 的执行占CPU 时间总和,而不是单次SQL 执行时间) .
    SQL ordered by Gets
    Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
    Total Buffer Gets: 964,486
    Captured SQL account for 103.6% of Total
    Buffer Gets Executions Gets per Exec %TotalCPU Time (s)Elapsed Time (s)SQL IdSQL ModuleSQL Text
    记录了执行占总buffer gets( 逻辑IO ) 的TOP SQL( 注意是监控范围内该SQL 的执行占Gets 总和,而不是单次SQL 执行所占的Gets)。
    SQL ordered by Reads
    Total Disk Reads: 5,606
    Captured SQL account for 168.4% of Total
    Physical ReadsExecutionsReads per Exec %TotalCPU Time (s)Elapsed Time (s)SQL IdSQL ModuleSQL Text[nextpage]
    记录了执行占总磁盘物理读( 物理IO ) 的TOP SQL( 请注意是监控范围内该SQL 的执行占磁盘物理读总和,而不是单次SQL 执行所占的磁盘物理读) .
    SQL ordered by Executions
    Total Executions: 20,124
    Captured SQL account for 59.3% of Total
    Executions Rows ProcessedRows per ExecCPU per Exec (s)Elap per Exec (s) SQL IdSQL ModuleSQL Text
    记录了按照SQL 的执行次数 排序的TOP SQL .该排序可以看出监控范围内的SQL 执行次数。
    SQL ordered by Parse Calls
    Total Parse Calls: 14,635
    Captured SQL account for 69.0% of Total
    Parse CallsExecutions % Total ParsesSQL IdSQL ModuleSQL Text
    记录了SQL 的软解析次数 的TOP SQL .
    SQL ordered by Sharable Memory
    Only Statements with Sharable Memory greater than 1048576 are displayed
    Sharable Mem (b)Executions % TotalSQL IdSQL ModuleSQL Text
    .记录了SQL 占用library cache 的大小 的TOP SQL .
    Sharable Mem (b) : 占用 library cache 的大小。单位是byte .
    SQL ordered by Version Count
    Only Statements with Version Count greater than 20 are displayed
    Version Count Executions SQL IdSQL ModuleSQL Text
    记录了SQL 的打开子游标 的TOP SQL .

-----------------------------------------------------

手工修改awr的执行计划,同时手工生成报告

  SQL> @?/rdbms/admin/awrrpt.sql (可以去两个快照之间的awr报告)

  注:AWR默认保留数据库7天的快照,每个小时产生一个快照

一、手工修改awr的执行计划

  调整AWR产生snapshot的频率和保留策略,如将收集间隔时间改为30分钟一次。并且保留5天时间(单位都是分钟):


  SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30, retention=>5*24*60);

  

二、测试系统:

1、手工先在数据库中创建一个快照


  SQL> execute dbms_workload_repository.create_snapshot(); 
  PL/SQL procedure successfully completed.

2、打开生产系统,点击“单井汇总信息”20多秒才出来页面

3、再生产一个快照


  SQL> execute dbms_workload_repository.create_snapshot(); 
  PL/SQL procedure successfully completed.

4、可以根据上面的awr报告中,找出花费时间比较长的单条sql语句的执行计划

  如:sql id为c0yffdyps8uk9 花费了26秒时间


  SQL> @?/rdbms/admin/awrsqrpt.sql 
  Specify the Begin and End Snapshot Ids 
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Enter value for begin_snap: 1679 
  Begin Snapshot Id specified: 1679 
  Enter value for end_snap: 1680 
  End Snapshot Id specified: 1680 
  Specify the SQL Id 
  ~~~~~~~~~~~~~~~~~~ 
  Enter value for sql_id: (输入c0yffdyps8uk9)

------------------------------------------------------

1.AWR介绍

AWR(Automatic Workload Repository)是oracle 10g提供的一个内置工具,它采集与DB性能相关统计数据,以WRM$_*和WRH_*的格式命名表,所有表都存储到SYSAUX表空间中的SYS模式下;AWR报告是DBA进行数据库性能评定,发现问题SQL的重要手段.

AWR默认保存一周的数据统计信息,产生快照频率和保留时间都可以手动调整,它完全可以取代statspack.

2.AWR报告生成步骤

2.1利用工具Toad连接到AWR报告生成界面

Database->monitor->ADDM/AWRReports(OEM)


2.2选择快照生成的时间段点击绿色按钮执行生成AWR报告

2.3通过数据库脚本文件生成AWR报告,执行如下脚本

$ORACLE_HOMERDBMSadminawrrpt.sql

3.分析AWR报告

3.1 AWR报告头信息


Elapsed:采样时间段

DB Time:用户操作花费的时间

DB Time远小于Elapsed Time说明数据库比较空闲

3.2 AWR负载概要信息


Redo size:标志数据库的繁忙程度

Parses:小于300则表示正常

Hard parses:硬解析,小于100则表示正常

从以上数据可以初步说明此数据库的吞吐量与负载正常

3.3 AWR实例效率


Buffer Nowait%:内存获得数据的未等待比例

Buffer Hit%:小于80%则要加内存

Library Hit%:若低于90%,则需要调大share pool

In-memory sort%:内存排序比例,过低排序会在临时表中进行,则需调大PGA

Soft Parse%:确保大于99%,否则意味着share pool latch争用

以上数据可以说明数据库实例命中率处于正常状态

3.4 AWR TOP等待事件


在一个没有问题的数据库中,CPU time总是列在第一个位置

DB file sequential read:此等待事件为多表连接的顺序存在问题,可能没有正确的使用基表或是不加选择的使用索引

DB file scattered read:此等待事件比较显著说明存在大量的全表扫描或没有创建合适的索引

ARCH wait on SENDERQ:远程传送archivelog的等待事件

Oracle大致有100多个空闲等待事件与非空闲等待事件,
Top 5 Timed Events是DB系统中影响比较大的前五个等待事件,
CPU Time是空闲等待时间,它在排第一名说明DB比较空闲,
Db file sequentail read与scattered read表明索引的选择不是很合理,

3.5 AWR TOP SQL Tuning

对排名前几位的sql进行turning,Top sql的order by 对象有以下几种
SQL ordered by Elapsed Time: 根据sql执行时间总和排序
SQL ordered by CPU Time: 根据sql消耗CPU time总和排序
SQL ordered by Gets: 根据sql消耗逻辑IO总和排序 
SQL ordered by Reads: 根据sql消耗物理IO总和排序
SQL ordered by Executions: 根据sql执行次数排序
SQL ordered by Parse Calls: 根据sql软解析次数

主要针对ordered by Elapsed time,orderedby CPU time,orderedbygets,orderedby read排名前三SQL进行观察并调优.

Oracle对SQL处理的步骤:

1.语法检查(检查SQL的拼写语法是否正确)

2.语义检查(检查SQL中的访问对象是否存在及是否具备相应权限)

3.进行解析(parse)(利用内部算法对SQL解析,生成解析树(parsetree)及执行计划(execution plan))à软硬解析发生在此过程中

4.执行SQL,返回结果

Oracle awr和ash区别可(参考)

http://www.cnblogs.com/rootq/archive/2009/09/24/1573196.html

原文地址:https://www.cnblogs.com/shengs/p/4968091.html