月归档:四月 2011

V$SESSION_WAIT分析

V$SESSION_WAIT displays the current or last wait for each session.

1、SID
Session identifier; maps to V$SESSION.SID

2、EVENT
session当前等待的事件,或者最后一次等待事件

3、WAIT_TIME
If the session is currently waiting, then the value is 0. If the session is not in a wait, then the value is as follows:
Value>0 – Value is the duration of the last wait in hundredths of a second
Value=-1 – Duration of the last wait was less than a hundredth of a second
Value=-2 – Parameter TIMED_STATISTICS was set to false

4、SEQ#
session等待事件将触发其值自增长

5、P1, P2, P3
等待事件中等待的详细资料

6、P1TEXT, P2TEXT, P3TEXT
解释说明p1,p2,p3事件

7、State
Wait state:
WAITING – Session is currently waiting
WAITED UNKNOWN TIME – Duration of the last wait is unknown; this is the value when the parameter TIMED_STATISTICS is set to false
WAITED SHORT TIME – Last wait was less than a hundredth of a second
WAITED KNOWN TIME – Duration of the last wait is specified in the WAIT_TIME column

8、SECONDS_IN_WAIT
If WAIT_TIME = 0, then SECONDS_IN_WAIT is the seconds spent in the current wait condition.
If WAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, and SECONDS_IN_WAIT – WAIT_TIME / 100 is the active seconds since the last wait ended.

9、Wait_time和Second_in_wait字段值与state相关
如果state值为Waiting,那么wait_time值无用。Second_in_wait值是实际的等待时间(单位:秒)。
如果state值为Wait unknow time,那么wait_time值和Second_in_wait值都无用。
如果state值为Wait short time,那么wait_time值和Second_in_wait值都无用。
如果state值为Waiting known time,那么wait_time值就是实际等待时间(单位:秒),Second_in_wait值无用。

10、应用p1,p2,p3进行等待事件的分析
v$session_wait视图的列代表的缓冲区忙等待事件如下:
P1—与等待相关的数据文件的全部文件数量。
P2—P1中的数据文件的块数量。
P3—描述等待产生原因的代码。
例:select p1 “File #”, p2 “Block #”, p3 “Reason Code”
  from v$session_wait
  where event = ‘buffer busy waits’;
如果以上查询的结果显示一个块在忙等待,以下的查询将显示这一块的名称和类型:
select owner, segment_name, segment_type
 from dba_extents
 where file_id = &P1 and &P2 between block_id and block_id + blocks -1;
我们也可以查询dba_data_files以确定等待的文件的file_name,方法是使用v$session_wait中的P1。
从v$session_wait中查询P3(原因编码)的值可以知道session等待的原因。原因编码的范围从0到300,下列为部分编码所代表的事项:
0 块被读入缓冲区。
100 我们想要NEW(创建)一个块,但这一块当前被另一session读入。
110 我们想将当前块设为共享,但这一块被另一session读入,所以我们必须等待read()结束。
120 我们想获得当前的块,但其他人已经将这一块读入缓冲区,所以我们只能等待他人的读入结束。
130 块被另一session读入,而且没有找到其它协调的块,所以我们必须等待读的结束。缓冲区死锁后这种情况也有可能产生。所以必须读入块的CR。
200 我们想新创建一个block,但其他人在使用,所以我们只好等待他人使用结束。
210 Session想读入SCUR或XCUR中的块,如果块交换或者session处于非连续的TX模式,所以等待可能需要很长的时间。
220 在缓冲区查询一个块的当前版本,但有人以不合法的模式使用这一块,所以我们只能等待。
230 以CR/CRX方式获得一个块,但块中的更改开始并且没有结束。
231 CR/CRX扫描找到当前块,但块中的更改开始并且没有结束

发表在 Oracle性能优化 | 评论关闭

Oracle AWR报告日常分析–SQL语句

1 SQL ordered by Elapsed Time
记录了执行总和时间的TOP SQL(请注意是监控范围内该SQL的执行时间总和,而不是单次SQL执行时间 Elapsed Time = CPU Time + Wait Time)。
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。

2 SQL ordered by CPU Time:
记录了执行占CPU时间总和时间最长的TOP SQL(请注意是监控范围内该SQL的执行占CPU时间总和,而不是单次SQL执行时间)。

3 SQL ordered by Gets:
记录了执行占总buffer gets(逻辑IO)的TOP SQL(请注意是监控范围内该SQL的执行占Gets总和,而不是单次SQL执行所占的Gets)。

4 SQL ordered by Reads:
记录了执行占总磁盘物理读(物理IO)的TOP SQL(请注意是监控范围内该SQL的执行占磁盘物理读总和,而不是单次SQL执行所占的磁盘物理读)。

5 SQL ordered by Executions:
记录了按照SQL的执行次数排序的TOP SQL。该排序可以看出监控范围内的SQL执行次数。

6 SQL ordered by Parse Calls:
记录了SQL的软解析次数的TOP SQL。说到软解析(soft prase)和硬解析(hard prase),就不能不说一下Oracle对sql的处理过程。

7 SQL ordered by Sharable Memory:
记录了SQL占用library cache的大小的TOP SQL。Sharable Mem (b):占用library cache的大小,单位是byte。

8 SQL ordered by Version Count:
记录了SQL的打开子游标的TOP SQL。

9 SQL ordered by Cluster Wait Time:
记录了集群的等待时间的TOP SQL

发表在 Oracle性能优化 | 评论关闭

ORACLE AWR使用

SQL> @?/rdbms/admin/awrrpt.sql

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

DB Id DB Name Inst Num Instance
———– ———— ——– ————
3393548168 XFF 1 xff

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’
输入 report_type 的值: html

Type Specified: html

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

DB Id Inst Num DB Name Instance Host
———— ——– ———— ———— ————
* 3393548168 1 XFF xff XIFENFEI-PC

Using 3393548168 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 without
specifying a number lists all completed snapshots.

输入 num_days 的值: 2[天数]

Listing the last 2 days of Completed Snapshots

Snap
Instance DB Name Snap Id Snap Started Level
———— ———— ——— —————— —–
xff XFF 119 22 4月 2011 21:22 1
120 22 4月 2011 21:40 1
121 22 4月 2011 21:40 1
122 22 4月 2011 22:02 1
123 22 4月 2011 22:30 1
124 22 4月 2011 23:00 1
125 22 4月 2011 23:30 1
126 23 4月 2011 00:00 1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入 begin_snap 的值: 120[起始快照号]
Begin Snapshot Id specified: 120

输入 end_snap 的值: 125[结束快照号]
End Snapshot Id specified: 125

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

输入 report_name 的值: xifenfei.html[文件名]

<enter>[回车执行]

查看生成awr文件

发表在 Oracle | 评论关闭