- 浏览: 402607 次
- 性别:
- 来自: 上海
最新评论
-
liuwenlong62555:
...
Linux防火墙的关闭和开启 -
baolong101010:
永久关闭:chkconfig --level 2345 ipt ...
Linux防火墙的关闭和开启 -
lijie1819:
3)查看防火墙状态chkconfig iptables --l ...
Linux防火墙的关闭和开启 -
Annah:
总结的很好,谢谢
Vector和ArrayList区别 -
celavi:
非常好的文章,谢谢分享!
ORACLE SQL TUNING
在Oracle中,Latch的概念是非常重要的,v$latch表的每一行包括了对不同类型latch的统计,每一列反映了不同类型的latch请求的活动情况。不同类型的latch请求之间的区别在于,当latch不可立即获得时,请求进程是否继续进行。按此分类,latch请求的类型可分为两类:willing-to-wait和immediate。
latch free,相信跟大家并不陌生,在v$session_wait和Top5中会出现,当然出现类似的内容,就证明Latch产生了竞争,并且已经影响到了你的系统性能。
首先我们来列举一下Latch出现竞争的几种常见情况:
1、cache buffers chains
2、shared pool
3、library cache
当然,我们需要一个一个来进行解释和分析,首先我们先来说下cache buffers chains
关于LATCH产生得解释:
Blocks in the buffer cache are placed on linked lists(cache buffer chains) which hang off a hash table.
The hash chain that a block is placed on is based on the DBA and CLASS of the block. Each hash chain is
protected by a single child latch. Processes need to get the relevant latch to allow them the scan a hash chain for a buffer so that the linked list does not change underneath them.
Contention for these latches can be caused by:
- Very long buffer chains.
- very very heavy access to the same blocks.
现在对数据库的实际操作过程:
SQL> select count(*)
from v$latch_children
where misses > 0
and name = 'cache buffers chains';
COUNT(*)
----------
2048
SQL> select addr, name, misses
from v$latch_children
where misses > 0
and name = 'cache buffers chains'
order by misses desc;
ADDR NAME MISSES
-------- ---------------------------------------------------------------- ----------
69CC28BC cache buffers chains 1591
69A3CF1C cache buffers chains 1591
69CBDDFC cache buffers chains 1589
69B92DFC cache buffers chains 1586
69C5DEBC cache buffers chains 1585
69AB0354 cache buffers chains 1585
69A70F9C cache buffers chains 1585
69A81F54 cache buffers chains 1585
SQL> select bh.addr, obj.name obj_name, bh.tch touch
from x$bh bh,
sys.file$ f,
v$datafile fl,
sys.obj$ obj,
sys.ts$ ts
where fl.file# = f.file#
and bh.file# = fl.file#
and obj.dataobj# = bh.obj
and bh.ts# = ts.ts#
and bh.HLADDR in(
select addr from v$latch_children where misses>0 and name='cache buffers chains'
)
and bh.tch > 0
order by bh.tch desc;
ADDR OBJ_NAME TOUCH
-------- ------------------------------ ----------
B6FD3078 IDX_GCTID_IUID_GM634 24
B6FD3078 REG_LOG 8
B6FD2F9C AGENT_CARD_TYPE 7
B6FD3078 RESELLER_AGENTCARD_PRICE 6
B6FD3078 RESELLER_LOG 6
B6FD3078 IDX_ACL_AGENTID_LOGTIME 6
B6FD3078 RESELLER_LOG 6
就是上面涉及到的这些对象,造成LATCH
SQL> select COUNT(*)
from x$bh bh, sys.file$ f, v$datafile fl, sys.obj$ obj, sys.ts$ ts
where fl.file# = f.file#
and bh.file# = fl.file#
and obj.dataobj# = bh.obj
and bh.ts# = ts.ts#
and bh.HLADDR = [x$bh.addr] --物理地址
and bh.tch > 0;
COUNT(*)
----------
51
一段文档资料:
Under 8.0, the default was next_prime(db_block_buffers/4), and the
number of _db_block_hash_latches was 1:1 with the number of buckets.
Under 8i, the world changed a lot. The default number of hash buckets
is 2 * db_block_buffers, but the latches work differently. It's
really not necessary to have one latch per hash chain, so, Oracle made
them a pooled resource. When you need to interrogate a hash chain,
you grab a latch from the pool and assign it to a hash chain. That
prevents anyone else from modifying the chain or it's contents while
your process is using it. So, in 8i, the size of the latch pool is
dynamic but is set to 1024 for most cases. It's smaller for very
small buffer caches and larger for very large buffer caches. The
formula is:
if (db_block_buffers < 2052) then
db_block_hash_latches = 2^trunc(log(2,db_block_buffers - 4) - 1)
else if(2052 =< db_block_buffers <= 131075) then
db_block_hash_latches = 1024
else if(db_block_buffers > 131075)
db_block_hash_latches = 2^trunc(log(2,db_block_buffers - 4) - 6)
end if
So, under 8i, you probably don't need to touch _db_block_hash_buckets,
as 2 * db_block_buffers is almost certainly more than adequate. And
unless you're dealing huge numbers of concurrent users and a
relatively small buffer cache, you probably don't need to mess with
_db_block_hash_latches, either.
增大 _db_buffer_hash_latches 可以更快速的查找到 blocks 并且降低 cache buffer chains 等待
我的操作系统是9I,db_block_buffers 为DB_CACHE_SIZE,如果我调整此参数,那么我应该是采取
db_block_hash_latches = 2^trunc(log(2,DB_CACHE_SIZE - 4) - 6)
SQL> show parameter db_cache_size;
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
db_cache_size big integer 1073741824
SQL> select name,
value,
decode(isdefault, 'TRUE', 'Y', 'N') as "Default",
decode(ISEM, 'TRUE', 'Y', 'N') as SesMod,
decode(ISYM, 'IMMEDIATE', 'I', 'DEFERRED', 'D', 'FALSE', 'N') as SysMod,
decode(IMOD, 'MODIFIED', 'U', 'SYS_MODIFIED', 'S', 'N') as Modified,
decode(IADJ, 'TRUE', 'Y', 'N') as Adjusted,
description
from ( --GV$SYSTEM_PARAMETER
select x.inst_id as instance,
x.indx + 1,
ksppinm as name,
ksppity,
ksppstvl as value,
ksppstdf as isdefault,
decode(bitand(ksppiflg / 256, 1), 1, 'TRUE', 'FALSE') as ISEM,
decode(bitand(ksppiflg / 65536, 3),
1,
'IMMEDIATE',
2,
'DEFERRED',
'FALSE') as ISYM,
decode(bitand(ksppstvf, 7), 1, 'MODIFIED', 'FALSE') as IMOD,
decode(bitand(ksppstvf, 2), 2, 'TRUE', 'FALSE') as IADJ,
ksppdesc as description
from x$ksppi x, x$ksppsv y
where x.indx = y.indx
and substr(ksppinm, 1, 1) = '_'
and x.inst_id = USERENV('Instance'))
where name = '_db_block_hash_latches'
order by name;
NAME VALUE
------------------------------ ---------------
_db_block_hash_latches 2048
SQL> select power(2,trunc(log(2,1073741824 - 4) - 6)) from dual;
POWER(2,TRUNC(LOG(2,1073741824-4)-6))
-------------------------------------
8388608
总得来说,LATCH产生得原因还是从应用入手,不要期望通过调整某些参数达到立杆见影的效果,热块、大的逻辑读和物理读,全表扫描都是会导致产生LATCH得原因。
latch free,相信跟大家并不陌生,在v$session_wait和Top5中会出现,当然出现类似的内容,就证明Latch产生了竞争,并且已经影响到了你的系统性能。
首先我们来列举一下Latch出现竞争的几种常见情况:
1、cache buffers chains
2、shared pool
3、library cache
当然,我们需要一个一个来进行解释和分析,首先我们先来说下cache buffers chains
关于LATCH产生得解释:
Blocks in the buffer cache are placed on linked lists(cache buffer chains) which hang off a hash table.
The hash chain that a block is placed on is based on the DBA and CLASS of the block. Each hash chain is
protected by a single child latch. Processes need to get the relevant latch to allow them the scan a hash chain for a buffer so that the linked list does not change underneath them.
Contention for these latches can be caused by:
- Very long buffer chains.
- very very heavy access to the same blocks.
现在对数据库的实际操作过程:
SQL> select count(*)
from v$latch_children
where misses > 0
and name = 'cache buffers chains';
COUNT(*)
----------
2048
SQL> select addr, name, misses
from v$latch_children
where misses > 0
and name = 'cache buffers chains'
order by misses desc;
ADDR NAME MISSES
-------- ---------------------------------------------------------------- ----------
69CC28BC cache buffers chains 1591
69A3CF1C cache buffers chains 1591
69CBDDFC cache buffers chains 1589
69B92DFC cache buffers chains 1586
69C5DEBC cache buffers chains 1585
69AB0354 cache buffers chains 1585
69A70F9C cache buffers chains 1585
69A81F54 cache buffers chains 1585
SQL> select bh.addr, obj.name obj_name, bh.tch touch
from x$bh bh,
sys.file$ f,
v$datafile fl,
sys.obj$ obj,
sys.ts$ ts
where fl.file# = f.file#
and bh.file# = fl.file#
and obj.dataobj# = bh.obj
and bh.ts# = ts.ts#
and bh.HLADDR in(
select addr from v$latch_children where misses>0 and name='cache buffers chains'
)
and bh.tch > 0
order by bh.tch desc;
ADDR OBJ_NAME TOUCH
-------- ------------------------------ ----------
B6FD3078 IDX_GCTID_IUID_GM634 24
B6FD3078 REG_LOG 8
B6FD2F9C AGENT_CARD_TYPE 7
B6FD3078 RESELLER_AGENTCARD_PRICE 6
B6FD3078 RESELLER_LOG 6
B6FD3078 IDX_ACL_AGENTID_LOGTIME 6
B6FD3078 RESELLER_LOG 6
就是上面涉及到的这些对象,造成LATCH
SQL> select COUNT(*)
from x$bh bh, sys.file$ f, v$datafile fl, sys.obj$ obj, sys.ts$ ts
where fl.file# = f.file#
and bh.file# = fl.file#
and obj.dataobj# = bh.obj
and bh.ts# = ts.ts#
and bh.HLADDR = [x$bh.addr] --物理地址
and bh.tch > 0;
COUNT(*)
----------
51
一段文档资料:
Under 8.0, the default was next_prime(db_block_buffers/4), and the
number of _db_block_hash_latches was 1:1 with the number of buckets.
Under 8i, the world changed a lot. The default number of hash buckets
is 2 * db_block_buffers, but the latches work differently. It's
really not necessary to have one latch per hash chain, so, Oracle made
them a pooled resource. When you need to interrogate a hash chain,
you grab a latch from the pool and assign it to a hash chain. That
prevents anyone else from modifying the chain or it's contents while
your process is using it. So, in 8i, the size of the latch pool is
dynamic but is set to 1024 for most cases. It's smaller for very
small buffer caches and larger for very large buffer caches. The
formula is:
if (db_block_buffers < 2052) then
db_block_hash_latches = 2^trunc(log(2,db_block_buffers - 4) - 1)
else if(2052 =< db_block_buffers <= 131075) then
db_block_hash_latches = 1024
else if(db_block_buffers > 131075)
db_block_hash_latches = 2^trunc(log(2,db_block_buffers - 4) - 6)
end if
So, under 8i, you probably don't need to touch _db_block_hash_buckets,
as 2 * db_block_buffers is almost certainly more than adequate. And
unless you're dealing huge numbers of concurrent users and a
relatively small buffer cache, you probably don't need to mess with
_db_block_hash_latches, either.
增大 _db_buffer_hash_latches 可以更快速的查找到 blocks 并且降低 cache buffer chains 等待
我的操作系统是9I,db_block_buffers 为DB_CACHE_SIZE,如果我调整此参数,那么我应该是采取
db_block_hash_latches = 2^trunc(log(2,DB_CACHE_SIZE - 4) - 6)
SQL> show parameter db_cache_size;
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
db_cache_size big integer 1073741824
SQL> select name,
value,
decode(isdefault, 'TRUE', 'Y', 'N') as "Default",
decode(ISEM, 'TRUE', 'Y', 'N') as SesMod,
decode(ISYM, 'IMMEDIATE', 'I', 'DEFERRED', 'D', 'FALSE', 'N') as SysMod,
decode(IMOD, 'MODIFIED', 'U', 'SYS_MODIFIED', 'S', 'N') as Modified,
decode(IADJ, 'TRUE', 'Y', 'N') as Adjusted,
description
from ( --GV$SYSTEM_PARAMETER
select x.inst_id as instance,
x.indx + 1,
ksppinm as name,
ksppity,
ksppstvl as value,
ksppstdf as isdefault,
decode(bitand(ksppiflg / 256, 1), 1, 'TRUE', 'FALSE') as ISEM,
decode(bitand(ksppiflg / 65536, 3),
1,
'IMMEDIATE',
2,
'DEFERRED',
'FALSE') as ISYM,
decode(bitand(ksppstvf, 7), 1, 'MODIFIED', 'FALSE') as IMOD,
decode(bitand(ksppstvf, 2), 2, 'TRUE', 'FALSE') as IADJ,
ksppdesc as description
from x$ksppi x, x$ksppsv y
where x.indx = y.indx
and substr(ksppinm, 1, 1) = '_'
and x.inst_id = USERENV('Instance'))
where name = '_db_block_hash_latches'
order by name;
NAME VALUE
------------------------------ ---------------
_db_block_hash_latches 2048
SQL> select power(2,trunc(log(2,1073741824 - 4) - 6)) from dual;
POWER(2,TRUNC(LOG(2,1073741824-4)-6))
-------------------------------------
8388608
总得来说,LATCH产生得原因还是从应用入手,不要期望通过调整某些参数达到立杆见影的效果,热块、大的逻辑读和物理读,全表扫描都是会导致产生LATCH得原因。
发表评论
-
一次oracle无法open的解决
2009-01-16 13:59 3714这几天因为公司的复杂查询出现性能的问题(说实话本来就没设计好, ... -
Oracle10g 自动共享内存管理
2009-01-14 13:25 39275.6 自动共享内存管理 从Oracle 10g开始,Or ... -
如何改善Oracle的索引
2009-01-12 16:40 15761、速度因素 PARALLEL选项:当创建索引时,O ... -
PX Deq: Execute Reply 案例说明
2009-01-03 09:55 30801 背景:Oracle 数据库在执行sql时,会自动的选择较 ... -
MySQL优化经验——第一讲
2008-12-28 19:41 1407今天突然想起自己 ... -
oracle中对workarea_size_policy和sort_area_size的总结
2008-12-19 12:06 8926在实际的工作中,想必很多人会对SORT_AREA_SIZE和s ... -
Oracle专用服务器与共享服务器的区别
2008-12-19 11:51 3386在建立Oracle数据库的时候,应该会在数据库建立助手向导上面 ... -
CBO学习笔记
2008-12-18 23:09 1456cost of b-tree access 这 ... -
Oracle高级SQL调优:CLUSTER_FACTOR案例研究
2008-12-18 22:27 1860大家在大型数据库生产系统的运维中可能会遇到这样一个问题,一条查 ... -
Oracle分析函数RANK()|ROW_NUMBER()|LAG()使用详解
2008-12-16 14:58 3117ROW_NUMBER()的使用方法: ROW_NUMB ... -
index和rowid的一点关系
2008-12-16 14:18 1510相信很多朋友在rowid和index之间都会有些疑问,今天在w ... -
关于MySQL的查询缓存收
2008-12-13 21:21 1206关于MySQL的查询缓存收 原理 QueryCache(下面简 ... -
oracle 被锁,解锁,阻塞语句
2008-12-12 18:35 2684//查询被锁的表 select A.s ... -
通过Oracle10g的FLASHBACK_TRANSACTION_QUERY指定事务的历史信息
2008-12-12 13:05 3186在数据库操作中,我们经常会遇到余下情况: 1.莫名其妙数据被D ... -
对于Oracle中DML使用UNDO的一些看法
2008-12-11 17:53 1251insert操作回滚段中只记录这些记录的ROWID updat ... -
oracle中x$ksppi和x$ksppcv详解
2008-12-09 17:22 3441SQL> desc x$ksppi 名称 ... -
ORA-600 [2103]错误及CF enqueue竞争
2008-12-09 17:21 1252昨天,客户的一套Oracle 10.2.0.3 RAC环境遇到 ... -
Oracle的redo 和undo的区别
2008-12-05 15:26 2623redo--> undo-->datafile i ... -
从 v$session 视图获取客户端 IP 地址
2008-11-18 19:42 2676缺省从 v$session 中不能直接获得客户端 IP ... -
oracle中聚合函数RANK和dense_rank的使用
2008-04-18 17:23 1380聚合函数RANK 和 dense_rank ...
相关推荐
**V$LATCH视图**提供了自实例启动以来latch的统计信息,有助于诊断和优化数据库性能,特别是当在v$session_wait视图中发现latch竞争时。这个视图包含以下列: 1. **NAME**: latch的名称,标识不同的数据结构保护...
1. Latch:用于多线程环境下的同步,过多的 latch 竞争可能成为性能瓶颈。 2. 锁管理:理解不同类型的锁(如行级锁、表级锁)及其行为,避免死锁。 七、硬件与操作系统优化 1. I/O优化:高速磁盘、RAID配置、固态...
本文提供了Oracle RDBMS如何利用锁(latches)保护共享内存(SGA)的概述、常见的锁竞争原因及其解决方案,并总结了Quest Software进行的一些研究,该研究表明调整(现在是未公开的参数)`_spin_count`能够有效地缓解...
描述部分提到了针对Oracle数据库中的Latch Contention(闩锁竞争)进行的最佳实践调优方法。具体问题为高CPU使用率伴随应用性能不佳,通过Statspack报告发现存在大量的Latch Free Wait事件,并且数百个会话正在等待...
《Oracle8i Internal Services for Waits, Latches, Locks, and Memory》是一本深入探讨Oracle数据库内部机制的专业书籍,对于想要深入了解Oracle数据库性能调优的读者而言具有很高的参考价值。通过掌握书中的知识点...
在Oracle数据库中,等待事件是指数据库实例在执行某个操作过程中由于资源竞争或限制而处于等待状态的情况。这些等待事件可能导致数据库性能下降,进而影响到整体的应用性能。因此,理解和分析这些等待事件对于优化...
Oracle数据库运行过程中,由于资源竞争、I/O延迟等原因,会存在各种各样的等待事件。这些等待事件直接影响到数据库的响应时间和整体性能。因此,对等待事件进行监控和分析是提高数据库性能的重要手段之一。 #### 二...
- 调整`SHARED_POOL_SIZE`以减少Library Cache latch竞争。 - 使用`DBMS_STATS`定期收集统计信息,确保CBO(Cost-Based Optimizer)做出准确的决策。 - **2.1.3 Session Snap** - Session Snap是一种性能监控...
共享池是Oracle SGA的一个重要组成部分,管理好其中的对象对于减少资源竞争和提高响应时间至关重要。 ### 总结 以上九个动态性能视图是Oracle数据库性能优化的核心工具。通过对它们的深入理解和应用,可以有效地...
Oracle 数据库中的数据字典是一系列系统表和视图的集合,用于存储数据库元数据。这些元数据包括了数据库对象(如表、视图、索引等)的定义、权限信息、以及数据库的状态信息等。下面列举了一些常用的数据字典条目...
- **竞争调优**:解决回滚段、锁、latch等问题。 - **操作系统调优**:调整共享内存段大小、文件缓存大小等。 ### 三、Oracle性能优化的“供需关系” - **平衡策略**:Oracle性能优化的本质在于实现资源间的平衡,...
Latch Contention查询返回最大的关键闩锁竞争百分比,即在所有关键闩锁中,哪一个具有最高的竞争率。高竞争率可能表明并发控制机制存在瓶颈,需要调整初始化参数或优化代码逻辑,以减少资源竞争,提高事务处理能力。...
例如,频繁的 latch 等待可能意味着锁竞争问题,而 buffer busy waits 则可能提示数据块竞争或缓存不足等问题。 7. **索引和分区策略**: - 正确使用索引可以大幅减少查询所需的时间。同时,通过分区技术可以将大...
本文将围绕“Java代码绑定时间”这一主题,深度剖析在Java程序中使用Oracle绑定变量的必要性及其对数据库性能的影响。 #### 一、硬解析与软解析:数据库性能的双刃剑 在Oracle数据库中,SQL语句的执行通常涉及两个...
- **数据库Latch监控**:监控Latch竞争,提升并发处理能力。 - **Redo日志监控**:确保redo log的健康状态,防止数据丢失。 测试过程中,Foglight展示了强大的数据库监控能力,能够实时报警、生成性能图表,并...
3. **性能监控**:通过Oracle的AWR(Automatic Workload Repository)报告来监控系统的性能问题,发现Buffer Cache的使用率高,存在Latch竞争等问题。 4. **解决方案**:为了解决上述问题,研究团队采取了多种策略,...