ORACLE等待事件:read by other session
read by other session简介
官方关于read by other session的介绍如下:
when information is requested from the database, oracle will first read the data from disk into the database buffer cache. if two or more sessions request the same information, the first session will read the data into the buffer cache while other sessions wait. in previous versions this wait was classified under the "buffer busy waits" event. however, in oracle 10.1 and higher this wait time is now broken out into the "read by other session" wait event. excessive waits for this event are typically due to several processes repeatedly reading the same blocks, e.g. many sessions scanning the same index or performing full table scans on the same table. tuning this issue is a matter of finding and eliminating this contention.
当从数据库请求信息时,oracle将首先将数据从磁盘读入数据库缓冲区缓存。如果两个或多个会话请求相同的信息时,则第一个会话将数据读入buffer cache的过程中,而其他会话出现等待。在之前的数据库版本中,此等待事件被归类为“buffer busy waits”等待事件。 但是,在oracle 10.1及更高版本中,此等待时间现在划分为“read by other session”等待事件。 该等待事件的大量等待通常是由于一些进程重复读取相同的数据块,例如, 许多会话扫描同一索引或在同一个表上执行全表扫描。 调优此问题是找到并消除这种竞争。
c.3.114 read by other session的介绍
this event occurs when a session requests a buffer that is currently being read into the buffer cache by another session. prior to release 10.1, waits for this event were grouped with the other reasons for waiting for buffers under the 'buffer busy waits' event
wait time: time waited for the buffer to be read by the other session (in microseconds)
read by other session的分析
read by other session等待的出现也说明数据库存在读的竞争,等待事件read by other session 通常与等待事件db file scattered read 和db file sequential read同时出现。有时候甚至与等待事件enq: tx - row lock contention同时出现(特殊情况,一个特殊案例中遇到的,等待read by other session的会话阻塞其它会话),如下截图所示。
db file scattered read通常显示与全表扫描相关的等待。当数据库进行全表扫时,基于性能的考虑,数据会分散(scattered)读入buffer cache。如果这个等待事件比较显著,可能说明对于某些全表扫描的表,没有创建索引或者没有创建合适的索引。
db file sequential read通常显示与单个数据块相关的读取操作(如索引读取)。如果这个等待事件比较显著,可能表示在多表连接中,表的连接顺序存在问题,可能没有正确的使用驱动表;或者可能说明不加选择地进行索引。
read by other session解决
如何查看当前会话处于等待read by other session:
使用下面sql找到当前处于read by other session等待的sql语句,然后分析sql,优化sql
select s.username,
s.sid,
s.serial#,
s.osuser,
s.machine,
s.terminal,
s.program,
s.last_call_et,
s.event,
s.seconds_in_wait,
s.blocking_session,
t.sql_text
--,t.sql_fulltext
from v$session s,
v$sqlarea t
where s.sql_address = t.address
and s.sid in (select sid
from v$session_wait
where event in ( 'read by other session' ));
或
select sql_fulltext from v$sql a,v$session b where a.sql_id=b.sql_id and b.event='read by other session';
也可以通过下面sql,获取产生read by other session等待事件的sql的实际执行计划,研究执行计划后,对相关sql进行调优,例如,对于全表扫描的添加合适索引。
select distinct sql_id
from v$session
where event in('read by other session', 'db file sequential read');
select * from table(dbms_xplan.display_awr('xxxxx'));
对于非当前会话的read by other session等待事件,我们可以通过awr报告和ash结合,找到发生read by other session等待的sql语句。
1:首先分析top 5 timed events,分析read by other session、db file scattered read、db file sequential read等待事件
2:awr报告中分析segments by buffer busy waits部分内容
如下截图所示,基本上可以判断第一个表xxx就是出现
3:首先使用下面脚本找到产生了'read by other session'等待事件的sql,然后生成指定sql语句的统计报表(awrsqrpt.sql)以及接近采样点附近的ash报告
select
a.sql_id,
sql_fulltext
from
v$sql a,
dba_hist_active_sess_history b
where
a.sql_id = b.sql_id
and b.event = 'read by other session';
awr报告里面的sql ordered by reads 或sql ordered by gets中的top sql找到涉及segments by buffer busy waits中对象的sql ,然后结合ash(细粒度的报告)来判断、分析!。
另外,如果需要查看涉及对象信息,可以通过等待事件的字段p1,p2,p3来获取
select p1 "file#"
, p2 "block#"
, p3 "class#"
from v$session_wait where event = 'read by other session';
或
select p1 "file#"
,p2 "block#"
,p3 "class#"
from dba_hist_active_sess_history
where event = 'read by other session';
官方文档描述如下:
· p1 = file# absolute file# (afn)
· p2 = block#
· p3 = class# block class
· file# absolute file number (afn)
this is the file number of the data file that contains the block that the waiting session wants.
· block#
this is the block number in the above file# that the waiting session wants access to. see note:181306.1 to determine the tablespace, filename and object for this file#,block# pair.
this is the class of block being waited on. in particular:
class 1 indicates a "data block", which could be table or index
class 4 indicates a "segment header"
class >=15 indicate undo blocks
另外,下面一些sql来自惜分飞的“read by other session等待事件”,非常有用。
根据file#,block#查询热块对象
select owner, segment_name, segment_type, tablespace_name, a.partition_name
from dba_extents a
where file_id = &file_id
and &block_id between block_id and block_id + blocks – 1;
直接查找热点块对象语句
select *
from (select o.owner, o.object_name, o.object_type, sum(tch) touchtime
from x$bh b, dba_objects o
where b.obj = o.data_object_id
and b.ts# > 0
group by o.owner, o.object_name, o.object_type
order by sum(tch) desc)
where rownum <= 10
--或者
select e.owner, e.segment_name, e.segment_type
from dba_extents e,
(select *
from (select addr, ts#, file#, dbarfil, dbablk, tch
from x$bh
order by tch desc)
where rownum < 11) b
where e.relative_fno = b.dbarfil
and e.block_id <= b.dbablk
and e.block_id + e.blocks > b.dbablk
直接查找热点块操作语句 select /*+rule*/ hash_value, sql_text from v$sqltext where (hash_value, address) in (select a.hash_value, a.address from v$sqltext a, (select distinct a.owner, a.segment_name, a.segment_type from dba_extents a, (select dbarfil, dbablk from (select dbarfil, dbablk from x$bh order by tch desc) where rownum < 11) b where a.relative_fno = b.dbarfil and a.block_id <= b.dbablk and a.block_id + a.blocks > b.dbablk) b where a.sql_text like '%' || b.segment_name || '%' and b.segment_type = 'table') order by hash_value, address, piece; |
其它一些官方或英文资料:
solutions
excessive waits for this event are typically due to several processes repeatedly reading the same blocks, e.g. many sessions scanning the same index or performing full table scans on the same table.
- tune the sql statement so that it reads fewer blocks. if the top objects listed in solarwinds dpa are indexes, determine if there is a more efficient index that can be used more efficiently. if the top objects are tables, a full table scan or index randge scan is being performed. look for efficient indexing opporunties.
- increase the buffer cache so that more blocks are already in memory rather having to be read from disk. the query will still need to read the same number of blocks so tuning is the first recommendation, but if you cannot tune the statement, a query reading blocks from memory is much faster than from disk.
- increase the pctused / pctfree for the table storage parameters via alter table or rebuild. this will result in less rows per block and possibly reduce contention.
waitevent: "read by other session" reference note (文档 id 732891.1)
reducing waits typically involves application tuning and/or io tuning.
contention does not mean that there is necessarily a problem, but it is more likely that selects against the objects involved are reading more blocks than they have to. these unnecessary reads can then contend. to find such selects, look for the queries that are waiting frequently for 'read by other session'. active session history (ash) reports during the period where contention is seen are a useful source of this sort of information. alternatively look for those queries that read a lot of buffers when querying these tables; it is possible that these queries are poorly optimized and perhaps a different access path may read fewer buffers and cause less contention.
eg: if lots of sessions scan the same unselective index this can show as "read by other session" waits for "data blocks":
· the first session processes the blocks that are in the buffer cache quickly but then a block has to be read from disk
· the other sessions (scanning the same index) quickly 'catch up' and want the block which is currently being read from disk - they wait for the buffer as someone is already reading the block in.
since the 'read by other session' wait event is an indicator that the buffers being waited for are popular (and are being "read by another session"), if queries are properly optimized, then an undersized buffer cache may mean that there is insufficient space to retain all the buffers required by queries. make sure that the buffer cache is adequately sized to keep the buffers required by the current sql statements from being aged out.
resolving issues where 'read by other session' waits when i/o is slow (文档 id 1477229.1)
reducing number of waits:
- if you are seeing long delays taken to service this wait event then check the amount of i/o being performed on the device identified by the p1 argument of this wait event.
the device and / or the controller may be overloaded. if this is the case then take the standard steps of spreading the file across further devices etc. - check that the real problem isn't the amount of time that the operating system is taking to service the system call.
- find out which file numbers are causing the highest average waits and then determine which filesystem contains the file
-
determine why the filesystems are performing poorly. some common causes are:
- "hot filesystems" - too many active files on the same filesystem exhausting the i/o bandwidth
- hardware problem
- in parallel execution (px) is being used, determine if the i/o subsystem is saturated by having too many slaves in use.
参考资料:
http://www.xifenfei.com/2011/07/read-by-other-session%e7%ad%89%e5%be%85%e4%ba%8b%e4%bb%b6.html
https://docs.oracle.com/database/121/refrn/guid-dceb3fa4-57a9-4ebe-a349-bbca1ba49281.htm#refrn00610
http://www.dbdream.com.cn/2015/01/%e5%85%b3%e4%ba%8eread-by-other-session%ef%bc%8cdb-file-scattered-read%ef%bc%8cdb-file-sequential-read%e7%ad%89%e5%be%85%e6%97%b6%e9%97%b4%e7%9a%84%e4%bc%98%e5%8c%96/
上一篇: Vue学习之全局和私有组件小结(七)
下一篇: MySQL_简介