当前位置:Gxlcms > 数据库问题 > oracle之 等待事件LOG FILE SYNC (awr)优化

oracle之 等待事件LOG FILE SYNC (awr)优化

时间:2021-07-01 10:21:17 帮助过:30人阅读

-----------------------------------------------------------------------------

来自盖大师(eygle)对log file sync等待事件优化的总结,供各位puber们学习参考:

http://www.eygle.com/statspack/statspack14-LogFileSync.htm
 当一个用户提交(commits)或者回滚(rollback),session的redo信息需要写出到redo logfile中.
用户进程将通知LGWR执行写出操作,LGWR完成任务以后会通知用户进程.
这个等待事件就是指用户进程等待LGWR的写完成通知.

对于回滚操作,该事件记录从用户发出rollback命令到回滚完成的时间.

如果该等待过多,可能说明LGWR的写出效率低下,或者系统提交过于频繁.
针对该问题,可以关注:
log file parallel write等待事件
user commits,user rollback等统计信息可以用于观察提交或回滚次数

解决方案:
1.提高LGWR性能
尽量使用快速磁盘,不要把redo log file存放在raid 5的磁盘上
2.使用批量提交
3.适当使用NOLOGGING/UNRECOVERABLE等选项

可以通过如下公式计算平均redo写大小:

avg.redo write size = (Redo block written/redo writes)*512 bytes

如果系统产生redo很多,而每次写的较少,一般说明LGWR被过于频繁的激活了.
可能导致过多的redo相关latch的竞争,而且Oracle可能无法有效的使用piggyback的功能.

我们从一个statspack中提取一些数据来研究一下这个问题.

我们看到,这里log file sync和db file parallel write等待同时出现了.
显然log file sync在等待db file parallel write的完成.

这里磁盘IO肯定存在了瓶颈,实际用户的redo和数据文件同时存放在Raid的磁盘上,存在性能问题.
需要调整.

由于过渡频繁的提交,LGWR过度频繁的激活,我们看到这里出现了redo writing的latch竞争.
关于redo writing竞争你可以在steve的站点找到详细的介绍:
http://www.ixora.com.au/notes/lgwr_latching.htm

Oracle Internals Notes
LGWR Latching

When LGWR wakes up, it first takes the redo writing latch to update the SGA variable that shows whether it is active. This prevents other Oracle processes from posting LGWR needlessly. LGWR then takes the redo allocation latch to determine how much redo might be available to write (subject to the release of the redo copy latches). If none, it takes the redo writing latch again to recordthat it is no longer active, before starting another rdbms ipc message wait.
If there is redo to write, LGWR then inspects the latch recovery areas for the redo copy latches (without taking the latches) to determine whether there are any incomplete copies into the log buffer. For incomplete copies above the sync RBA, LGWR just defers the writing of that block and subsequent log buffer blocks. For incomplete copies below the sync RBA, LGWR sleeps on a LGWR wait for redo copy wait event, and is posted when the required copy latches have been released. The time taken by LGWR to take the redo writing and redo allocation latches and to wait for the redo copy latches is accumulated in the redo writer latching time statistic.

(Prior to release 8i, foreground processes held the redo copy latches more briefly because they did not retain them for the application of the change vectors. Therefore, LGWR would instead attempt to assure itself that there were no ongoing copies into the log buffer by taking all the redo copy latches.)

After each redo write has completed, LGWR takes the redo allocation latch again in order to update the SGA variable containing the base disk block for the log buffer. This effectively frees the log buffer blocks that have just been written, so that they may be reused.

 

------------------------------------------------------------------------------------

来自吕大师(vage)对log file sync等待事件优化的总结,供各位puber们学习参考:


1、Log File Sync是从提交开始到提交结束的时间。Log File Parallel Write是LGWR开始写Redo File到Redo File结束的时间。明确了这一点,可以知道,Log file sync 包含了log file parallel write。所以,log file sync等待时间一出,必先看log file parallel write。如果log file sync平均等待时间(也可称为提交响应时间)为20ms,log file parallel write为19ms,那么问题就很明显了,Redo file I/O缓慢,拖慢了提交的过程。

2、 Log File Sync的时间不止log file parallel write。服务器进程开始提交,到通知LGWR写Redo,LGWR写完Redo通知进程提交完毕,来回通知也是要消耗CPU的。除去来回通知 外,Commit还有增加SCN等等操作,如果log file sync和log file parallel write差距很大,证明I/O没有问题,但有可能是CPU资源紧张,导致进程和LGWR来回通知或其他的需要CPU的操作,得不到足够的CPU,因而产 生延迟。

这 种情况下要看一下CPU的占用率、Load,如果Load很高、CPU使用率也很高,哪就是由于CPU导致Log file sync响应时间加长。这种情况下,数据库通常会有一些并发症,比如Latch/Mutex的竞争会比平常严重些,因为CPU紧张吗,Latch /Mutex竞争一些会加巨的。

3、 log file sync和log file parallel write相差很大,但CPU使用率也不高,这种情况比较少见,这就属于疑难杂症范畴了。I/O也很快,CPU也充足,log fie parallel write响应时间很短,但log file sync响应时间确很大。这是最难定位的情况,可以全面对比下Redo相关资料(v$sysstat中的资料)、Redo相关Latch的变化情况。
比 如,redo synch time的平均响应时间,不是每次redo synch time都有提交,但每次提交必有redo synch time。如果redo synch time向应快,而log file sync慢,则说明Lgwr和进程的互相通知阶段出了问题。还有redo entries,这个Redo条目数,真正含意是进程向Log Buffer中写Redo的次数。redo log space wait time、redo log space requests资料和Log Buffer Space等待事件也要关注下。Log Buffer的大小通常不会影响Log File Sync,但通过Log Buffer的变化,可以了解Redo量的变化。
关于Log Buffer对Log File Sync的影响,

在新IMU机制下,Redo数据先在共享池中,提交时传到Log Buffer中,如果这时有等待,等待时间是Log Buffer Space。从Log Buffer到磁盘,等待事件才是log file sync。
老机制下也一样,Log Buffer之前的等待是log buffer space,log buffer之后的等待才是log file sync。

4、控制文件I/O有可能影响log file sync。
此问题还没来得及深入研究,只是以前在阿里的数据库中观察到这一现象。

5、Log File Sycn和Buffer Busy Waits。
没 有直接关系。是其他原因,比如Redo相关的Latch,导致了Log File Sync和Buffer Busy Waits同时出现。此时Log File Sync和Buffer Busy Waits都不是原凶,真正的原凶是Log Buffer访问性能下降。

6、以同步模式向远端DataGuard传送Redo,也会导致Log File Sync。

Redo是Oracle重要的优化对象,DBWR的工作原理我已经破译的差不多了,下一目标就是LGWR,可惜还没来得及搞,以后有时间再为大家详细总结。

oracle之 等待事件LOG FILE SYNC (awr)优化

标签:therefore   prevent   标志位   参考   否则   处理机   media   拷贝   atoi   

人气教程排行