11g直接路径读、相关参数、10949事件介绍
转载自刘向兵老师:http://www.askmaclean.com/archives/11g-direct-path-read-10949-_small_table_threshold-_serial_direct_read.html
在11g之前串行的扫描大表默认总是先将数据读取到Oracle高速缓冲中,其等待事件常为db file scattered read。
从11g开始Oracle通过内部算法来决定串行扫描大表是通过直接路径读direct path read,还是先读入到buffer cache中,此算法依据表的大小评估。
_small_table_threshold 隐藏参数指定了 ORACLE中大表的阀值,其单位为block,即大于_small_table_threshold 所指定的块数的表被视作大表,
否之视为”small table”。 对于大表”large table”,SQL执行层认为存在直接路径读取的意义(direct path read)。 对于小表,将它缓存在buffer cache中的收益更大,所以直接路径读取不具有意义。_small_table_threshold 隐藏参数的值在实例启动时动态决定,一般为 2% * DB_CACHE_SIZE。
direct path read的优势:
1. 减少了对闩(latch)的使用,避免可能的闩争用
2.物理IO的大小不再取决于buffer_cache中所存在的块;试想某个8个块的extent中1,3,5,7号块在高速缓存中,而2,4,6,8块没有被缓存,传统的方式在读取该extent时将会是对2,4,6,8块进行4次db file sequential
read,其效率往往要比单次读取这个区间的所有8个块还要低得多,Oracle为了避免这种情况总是尽可能的不缓存大表的块(读入后总是放在队列最冷的一端);而direct path read则可以完全避免这类问题,尽可能地单次读入更多的物理块。
当然直接路径读取也会引入一些缺点:
1.即便在buffer cache足够大到可以放下整个大表的情况下,direct path read无法从高速缓冲受益,每次扫描大表均需重复等量的直接路径物理读取IO
2.在直接路径读取某段前需要对该对象进行一次段级的检查点(A segment checkpoint).
3.可能导致重复的延迟块清除操作
该11g自动判断direct path read的特性适用场景:
1. 对大表不频繁地串行全表扫描的场景
2. Db Cache Size高速缓冲大小远小于表的大小的场景
不推荐在以下场景中开启该11g自动判断direct path read特性:
1. 从运行稳定的老版本(9i、10g)升级到11g的数据库
2. 对大表频繁地串行全表扫描的场景
SQL> select * from v$version;
BANNER
——————————————————————————–
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
PL/SQL Release 11.2.0.3.0 – Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 – Production
NLSRTL Version 11.2.0.3.0 – Production
col name for a30
col value for a20
col DESCRIB for a60
set linesize 140 pagesize 1400
SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
FROM SYS.x$ksppi x, SYS.x$ksppcv y
WHERE x.inst_id = USERENV (‘Instance’)
AND y.inst_id = USERENV (‘Instance’)
AND x.indx = y.indx
AND (x.ksppinm =’_small_table_threshold’ or x.ksppinm=’_serial_direct_read’);
NAME VALUE DESCRIB
—————————— ——————– ————————————————————
_small_table_threshold 1143 lower threshold level of table size for direct reads
_serial_direct_read auto enable direct read in serial
其中_small_table_threshold 隐藏参数指定了 ORACLE中大表的阀值,其单位为block,即大于_small_table_threshold 所指定的块数的表被视作大表,
否之视为”small table”。 对于大表”large table”,SQL执行层认为存在直接路径读取的意义(direct path read)。 对于小表,将它缓存在buffer cache中的收益更大,所以直接路径读取不具有意义。
_small_table_threshold 隐藏参数的值在实例启动时动态决定,一般为 2% * DB_CACHE_SIZE。
SQL> alter system set db_cache_size=1024M scope=spfile;
System altered.
RESTART INSTANCE:
SQL> col name for a30
SQL> col value for a20
SQL> col DESCRIB for a60
SQL> set linesize 140 pagesize 1400
SQL>
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
2 FROM SYS.x$ksppi x, SYS.x$ksppcv y
3 WHERE x.inst_id = USERENV (‘Instance’)
4 AND y.inst_id = USERENV (‘Instance’)
5 AND x.indx = y.indx
6 AND (x.ksppinm =’_small_table_threshold’ or x.ksppinm=’_serial_direct_read’);
NAME VALUE DESCRIB
—————————— ——————– ————————————————————
_small_table_threshold 2522 lower threshold level of table size for direct reads
_serial_direct_read auto enable direct read in serial
2522 block = 2522 * 8k = = 19.7 M 约等于 1024 * 2%
SQL> create table tmac (t1 char(2000)) pctfree 99 pctused 1 tablespace users;
Table created.
SQL> insert into tmac select ‘MACLEAN’ from dual connect by level <=2530;
2530 rows created.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(‘SYS’,’TMAC’);
PL/SQL procedure successfully completed.
SQL> select blocks from dba_tables where table_name=’TMAC’;
BLOCKS
———-
2638
SQL> alter system flush buffer_cache;
SQL> select count(*) from tmac;
COUNT(*)
———-
2530
SQL> select vm.sid, vs.name, vm.value
2 from v$mystat vm, v$sysstat vs
3 where vm.statistic# = vs.statistic#
4 and vs.name in (‘cleanouts only – consistent read gets’,
5 ‘session logical reads’,
6 ‘physical reads’,
7 ‘physical reads direct’);
SID NAME VALUE
———- —————————————————————- ———-
135 session logical reads 2859
135 physical reads 2763
135 physical reads direct 2576
135 cleanouts only – consistent read gets 0
physical reads direct 增加说明上面的查询使用了direct path read
SQL> alter session set “_serial_direct_read”=never;
Session altered.
SQL> select count(*) from tmac;
COUNT(*)
———-
2530
SQL> select vm.sid, vs.name, vm.value
2 from v$mystat vm, v$sysstat vs
3 where vm.statistic# = vs.statistic#
4 and vs.name in (‘cleanouts only – consistent read gets’,
5 ‘session logical reads’,
6 ‘physical reads’,
7 ‘physical reads direct’);
SID NAME VALUE
———- —————————————————————- ———-
135 session logical reads 5497
135 physical reads 5339
135 physical reads direct 2576
135 cleanouts only – consistent read gets 0
SQL> select count(*) from tmac;
COUNT(*)
———-
2530
SQL> select vm.sid, vs.name, vm.value
2 from v$mystat vm, v$sysstat vs
3 where vm.statistic# = vs.statistic#
4 and vs.name in (‘cleanouts only – consistent read gets’,
5 ‘session logical reads’,
6 ‘physical reads’,
7 ‘physical reads direct’);
SID NAME VALUE
———- —————————————————————- ———-
135 session logical reads 8135
135 physical reads 5339
135 physical reads direct 2576
135 cleanouts only – consistent read gets 0
physical reads direct 不再增加说明以上2次查询未使用direct path read
隐藏参数”_serial_direct_read” 指定了是否启用串行全表扫描下的直接路径读取(direct path read),其默认值为AUTO,设置为NEVER时禁用11g自动direct path read的特性
SQL> alter session set “_serial_direct_read”=auto;
Session altered.
还原session级别的_serial_direct_read 参数
SQL> delete tmac where rownum<2000;
1999 rows deleted.
SQL> commit;
Commit complete.
SQL> alter table tmac move tablespace users pctfree 10 pctused 90;
Table altered.
SQL> exec dbms_stats.gather_table_stats(‘SYS’,’TMAC’);
PL/SQL procedure successfully completed.
SQL> select blocks from dba_tables where table_name=’TMAC’;
BLOCKS
———-
189
将TMAC表缩小到 _small_table_threshold以下
SQL> alter system flush buffer_cache;
System altered.
SQL> select count(*) from tmac;
COUNT(*)
———-
531
SQL> select vm.sid, vs.name, vm.value
2 from v$mystat vm, v$sysstat vs
3 where vm.statistic# = vs.statistic#
4 and vs.name in (‘cleanouts only – consistent read gets’,
5 ‘session logical reads’,
6 ‘physical reads’,
7 ‘physical reads direct’);
SID NAME VALUE
———- —————————————————————- ———-
135 session logical reads 524
135 physical reads 349
135 physical reads direct 0
135 cleanouts only – consistent read gets 1
以上演示证明对于small table(块数小于_small_table_threshold),SQL执行层自动并不决定使用direct path read,而是将之读取到buffer cache中并逻辑读。
结论:
其中_small_table_threshold 隐藏参数指定了 ORACLE中大表的阀值,其单位为block,即大于_small_table_threshold 所指定的块数的表被视作大表,
否之视为”small table”。 对于大表”large table”,SQL执行层认为存在直接路径读取的意义(direct path read)。 对于小表,将它缓存在buffer cache中的收益更大,所以直接路径读取不具有意义。
_small_table_threshold 隐藏参数的值在实例启动时动态决定,一般为 2% * DB_CACHE_SIZE。
隐藏参数”_serial_direct_read” 指定了是否启用串行全表扫描下的直接路径读取(direct path read),其默认值为AUTO,设置为NEVER时禁用11g自动direct path read的特性
“As of 11.2.0.2 the legal settings are
true, false, always, auto, and never
true is the same effect as always
false is the same effect as auto
Default value is “auto”
Setting event 10949 or event 10354 may also have the side effect of making oracle behave as if _serial_direct_read = never”
该参数可以动态在实例或会话级别修改,而无需重启实例。
类似的10949 EVENT事件也可以起到类似的作用。
设置event 10949可以避免采用直接路径读取方式,该事件可以在线设置,但对现有session可能不会生效:
在实例级别设置:
ALTER SYSTEM SET EVENTS ‘10949 TRACE NAME CONTEXT FOREVER’;
设置到SPFILE中:
alter system set event=’10949 TRACE NAME CONTEXT FOREVER’ scope=spfile;
在session级别设置:
ALTER SESSION SET EVENTS ‘10949 TRACE NAME CONTEXT FOREVER’;
转载自刘向兵老师:http://www.askmaclean.com/archives/11g-direct-path-read-10949-_small_table_threshold-_serial_direct_read.html
11g直接路径读、相关参数、10949事件介绍的更多相关文章
- 创建一个python类 ,self init相关参数的简单介绍
一 创建 ''' 一 使用python 语法 创建一个类, 探究self 是干啥的 1 创建一个对象 car 2 写入两个行参 3 定义两个方法 ''' class Car(): ''' 二 init ...
- [20171120]11G关闭直接路径读.txt
[20171120]11G关闭直接路径读.txt --//今天做filesystemio_options参数测试时,遇到一个关于直接路径读的问题.--//如果看以前的博客介绍,设置"_ser ...
- direct path read/write (直接路径读/写)
转载:http://www.dbtan.com/2010/04/direct-path-readwrite.html direct path read/write (直接路径读/写): 直接路径读(d ...
- Oracle收集对表收集统计信息导致全表扫描直接路径读?
direct path read深入解析 前言 最近碰到一件很奇葩的事情,因为某条SQL执行缓慢,原因是走了笛卡尔(两组大数据结果集),而且笛卡尔还是NL的一个部分,要循环31M次. 很容易发现是统计 ...
- JVM相关参数配置和问题诊断<转>
原文连接:http://blog.csdn.net/chjttony/article/details/6240457 1.Websphere JVM相关问题诊断: 由JVM引起的Websphere问题 ...
- Oracle 直接路径读
在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读的,所以不存在direct pa ...
- MySQL8常见客户端和启动相关参数
MySQL8常见客户端和启动相关参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL常见的客户端 1>.使用MySQL服务自带的mysql连接工具 2>. ...
- Linux TCP队列相关参数的总结 转
在Linux上做网络应用的性能优化时,一般都会对TCP相关的内核参数进行调节,特别是和缓冲.队列有关的参数.网上搜到的文章会告诉你需要修改哪些参数,但我们经常是知其然而不知其所以然,每次照抄过 ...
- Linux TCP队列相关参数的总结
作者:阿里技术保障锋寒 原文:https://yq.aliyun.com/articles/4252 摘要: 本文尝试总结TCP队列缓冲相关的内核参数,从协议栈的角度梳理它们,希望可以更容易的理解和记 ...
随机推荐
- 数组引用:C++ 数组做参数 深入分析
转载:https://blog.csdn.net/jiangxinyu/article/details/7767065 在 C++中,数组永远不会按值传递,它是传递第一个元素,准确地说是第 0个 的指 ...
- Python校验文件MD5值
import hashlib import os def GetFileMd5(filename): if not os.path.isfile(filename): return myHash = ...
- java_28 序列化与反序列化
1.序列化和反序列化 序列化:把对象转换为字节序列的过程称为对象的序列化.(常见的就是存文件) 反序列化:把字节序列恢复为对象的过程称为对象阿德反序列化. 2.序列化和反序列化的使用: java.io ...
- jinji2
---恢复内容开始--- part1 %d 十进制整数输出 int %f 浮点数(小数点后六位)float %c 单个字符输出 char % ...
- 转:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-j8m0mf5q/mysqlclient
错误场景 第一次部署服务器时mysqlclient安装失败 思考 初步考虑是pip没有升级,最后发现不是这个原因. 解决办法 来源:https://blog.csdn.net/mr_tia/artic ...
- Boto3
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.htmlboto3 安装pip install bot ...
- MVC Request生命周期(综合总结)
当用户在浏览器输入一个URL地址后,浏览器会发送一个请求到服务器.这时候在服务器上第一个负责处理请求的是IIS.然后IIS再根据请求的URL扩展名将请求分发给不同的处理程序处理. 流程如下: 当请求一 ...
- 微信小程序覆盖自定义组件样式
小程序官方文档明确指出,引入的第三方自定义组件,是不可以对其进行CSS样式覆盖的,但是我们还想要修改怎么办呢?自定义组件时会之定义个外部类,通过这个外部类来修改样式. 修改https://weapp. ...
- tcp拥塞控制 tahoe reno new reno sack
http://www.docin.com/p-812428366.html http://www.docin.com/p-812428366.html
- oracle 数据库去重复数据
delete from 表名 a where rowid !=(select max(rowid) from 表名 b where a.ORDER_ID=b.ORDER_ID) 例:如果重复的数据表是 ...