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.
-------------------------------------------------
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 .
2.3通过数据库脚本文件生成AWR报告,执行如下脚本
$ORACLE_HOME\RDBMS\admin\awrrpt.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,返回结果