暂无图片
暂无图片
11
暂无图片
暂无图片
暂无图片

《log file sync》 等待事件问题分析汇总

原创 布衣 2022-11-07
2226

背景

  “log file sync”是Oracle中的经典等待事件之一,做为DBA 经常在AWR报告Top 5 Timed Foreground Events版块,发现它的存在。
  在之前面试的时候也有考官问过这样的问题,引起log file sync等待事件有哪几种情况,当时脑袋里一堆问号,“log file sync不是因为频繁事务commit/rollback引导的吗?”当时我是这样回答的,考官说:“你只回答上了一部分,回头自己多查查资料吧!”。
  后来自己也查询许多的资料,想着做个整理,正好借着学习张维照老师的《Oracle DBA日常运维及应急故障处理手册》第1.1就是讲的《Oracle redo file on SSD wait event ‘log file sync’》做个笔记总结。

现象

  • 课程示例:
    image.png
    数据库的log file sync: Avg wait (ms)达500ms以上,并且CPU 负载相对空闲,IO吞吐量并不大,top event还有其它数据文件相关的I/O class wait event, 并且都是ms级别,这样的负载对于SSD存储通常应该就是在us级。

  • 我的环境:
    image.png
    我这log file sync: Avg wait (ms)也就1。一般log file sycn的等待时间都非常短 1-5ms,不会有什么问题。

log file sync理论

  • 官方的definition如下:
    When a user session(foreground process) COMMITs (or rolls back), the session’s redo information needs to be flushed to the redo logfile. The user session will post the LGWR to write all redo required from the log buffer to the redo log file. When the LGWR has finished it will post the user session. The user session waits on this wait event while waiting for LGWR to post it back to confirm all redo changes are safely on disk.

  大概的意思指前台进程从提交或回滚事务通知lgwr写redo开始,直到确认redo已成功写入redo logfile为止,期间这个过程就是log file sync等待的过程。
  所以,log file sync是每个事务commit或rollback操作都必经的过程,是否被判为异常等待,主要参考等待时间的长短、等待次数的多少。
  由于需要等待lgwr写redo logfile,因此,log file sync的等待时间涵盖了log file parallel write的时间。

原因分析汇总

1、小事务频繁提交引起:

官方的经验值是:
如果:user calls÷(user commits+user rollbacks) < 30 ,那么可以算事务太过频繁。
以我的环境为例:
image.png
image.png

SQL> select 10316411/(963806+31450) from dual; 10316411/(963806+31450) ----------------------- 10.3655853 < 30 ,那么可以算事务太过频繁。

2、Bug

commit的过程可以分为两个阶段:
第一阶段为lgwr将redo从log buffer写到redo logfile的过程;
第二阶段lgwr和user session(foreground process) 之间关于写redo logfile结果的信息交互过程。
对于第二阶段,Oracle自从11g R2开始引入了Adaptive Log File Sync的特性,该特性由参数隐含参数“ _use_adaptive_log_file_sync” 控制,决定着前台进程和lgwr之间的交互使用何种方式。
在 Oracle 11201 和 Oracle 11202的版本中,该参数默认设置为 false。从 11.2.0.3 开始默认是 true。
当设置为true启用时,Oracle 可以在两种方法之间自行切换:
Post/wait,传统发布写重做日志完成的方法。
Polling,一种新的方法,其中前台进程会检查 LGWR 是否已写完成。
本环境为11.2.0.3 隐含参数: _use_adaptive_log_file_sync

INDX NAME KSPPDESC KSPPSTVL ---------- ------------------------------ -------------------------------------------------- ---------- 1060 _use_adaptive_log_file_sync Adaptively switch between post/wait and polling TRUE

详细可查:Bug 13707904  – LGWR sometimes uses polling,sometimes post/wait.
image.png

该BUG可通过设置隐藏参数_use_adaptive_log_file_sync的默认值解决问题。

ALTER SYSTEM SET "_use_adaptive_log_file_sync"= FALSE  scope=both;

同时,此bug开始在oracle 11.2.0.4以及12.1.0.1版本中得到解决。
image.png

3、结合:log file parallel write 事件分析

  log file parallel write 事件是LGWR进程专属的等待事件,发生在LGWR将日志缓冲区(log_buffer)中的重做日志信息写入联机重做日志文件组的成员文件,LGWR在该事件上等待该写入过程的完成。该事件的等待表示重做日志所处的磁盘设备缓慢或存在争用。

  • log file parallel write出现原因
    意味着重做日志(redo log)所处的磁盘设备I/O缓慢或存在争用:
  1. 磁盘I/O性能比较差
  2. REDO文件的分布导致了I/O争用,例如,同一组的REDO成员文件放在相同的磁盘上。
  • 查看log file parallel write等待事件
select s.event as event_name
 ,s.time_waited/100 as time_waited
,s.average_wait as averge_wait
from v$system_event s
where s.event in ('log file parallel write','log file sync');

EVENT_NAME                                                       TIME_WAITED AVERGE_WAIT
---------------------------------------------------------------- ----------- -----------
log file parallel write                                           2408236.83         .03
log file sync                                                     2503386.33         .06

来自网络汇总:

  1. log file sync的平均IO较高,log file parallel write的平均IO较高,可能的IO系统问题;
  2. log file sync的平均IO较高,log file parallel write的平均IO低于5ms,远低于log file sync:可以确定IO无问题,有可能是CPU瓶颈。
  3. log file sync等待次数很高,log file parallel write的平均IO较低,可能是大量小事务频繁提交导致,这时候通常伴随着CPU使用率较高的现象出现。
  4. log file sync和log file parallel write的平均IO都较低,这不一定就代表系统没有问题,有可能是刷redo过程中出现了间隙性的性能问题,IO时间被平均了,这个需要进一步通过OS的信息诊断。

张维照老师的《Oracle DBA日常运维及应急故障处理手册》里面的第1.1就是讲的《Oracle redo file on SSD wait event ‘log file sync’》请的就是关于系统IO引起的log file sync,在此不再重复,有兴趣可以学习:https://www.modb.pro/course/article/160?lsId=6885&catalogId=1

欢迎赞赏支持或留言指正

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论