Skip to content

等待事件 - 2. page

浅谈log file sync等待事件诊断(三)

提供一个辅助诊断log file sync的脚本,该脚本有助于诊断log file sync时候锁需要的数据库相关信息的获取,具体如下:

-- NAME: LFSDIAG.SQL
-- ------------------------------------------------------------------------
-- AUTHOR: Michael Polaski - Oracle Support Services
-- ------------------------------------------------------------------------
-- PURPOSE:
-- This script is intended to provide a user friendly guide to troubleshoot
-- log file sync waits. The script will look at important parameters involved
-- in log file sync waits, log file sync wait histogram data, and the script
-- will look at the worst average log file sync times in the active session
-- history data and AWR data and dump information to help determine why those
-- times were the highest. The script will create a file called
-- lfsdiag_<timestamp>.out in your local directory.

set echo off
set feedback off
column timecol new_value timestamp
column spool_extension new_value suffix
select to_char(sysdate,'Mondd_hh24mi') timecol,
'.out' spool_extension from sys.dual;
column output new_value dbname
select value || '_' output
from v$parameter where name = 'db_name';
spool lfsdiag_&&dbname&&timestamp&&suffix
set trim on
set trims on
set lines 140
set pages 100
set verify off
alter session set optimizer_features_enable = '10.2.0.4';

PROMPT LFSDIAG DATA FOR &&dbname&&timestamp
PROMPT Note: All timings are in milliseconds (1000 milliseconds = 1 second)

PROMPT
PROMPT IMPORTANT PARAMETERS RELATING TO LOG FILE SYNC WAITS:
column name format a40 wra
column value format a40 wra
select inst_id, name, value from gv$parameter
where ((value is not null and name like '%log_archive%') or
name like '%commit%' or name like '%event=%' or name like '%lgwr%')
and name not in (select name from gv$parameter where (name like '%log_archive_dest_state%'
and value = 'enable') or name = 'log_archive_format')
order by 1,2,3;

PROMPT
PROMPT ASH THRESHOLD...
PROMPT
PROMPT This will be the threshold in milliseconds for average log file sync
PROMPT times. This will be used for the next queries to look for the worst
PROMPT 'log file sync' minutes. Any minutes that have an average log file
PROMPT sync time greater than the threshold will be analyzed further.
column threshold_in_ms new_value threshold format 999999999.999
select min(threshold_in_ms) threshold_in_ms
from (select inst_id, to_char(sample_time,'Mondd_hh24mi') minute,
avg(time_waited)/1000 threshold_in_ms
from gv$active_session_history
where event = 'log file sync'
group by inst_id,to_char(sample_time,'Mondd_hh24mi')
order by 3 desc)
where rownum <= 10;

PROMPT
PROMPT ASH WORST MINUTES FOR LOG FILE SYNC WAITS:
PROMPT
PROMPT APPROACH: These are the minutes where the avg log file sync time
PROMPT was the highest (in milliseconds).
column minute format a12 tru
column event format a30 tru
column program format a40 tru
column total_wait_time format 999999999999.999
column avg_time_waited format 999999999999.999
select to_char(sample_time,'Mondd_hh24mi') minute, inst_id, event,
sum(time_waited)/1000 TOTAL_WAIT_TIME , count(*) WAITS,
avg(time_waited)/1000 AVG_TIME_WAITED
from gv$active_session_history
where event = 'log file sync'
group by to_char(sample_time,'Mondd_hh24mi'), inst_id, event
having avg(time_waited)/1000 > &&threshold
order by 1,2;

PROMPT
PROMPT ASH LFS BACKGROUND PROCESS WAITS DURING WORST MINUTES:
PROMPT
PROMPT APPROACH: What is LGWR doing when 'log file sync' waits
PROMPT are happening? LMS info may be relevent for broadcast
PROMPT on commit and LNS data may be relevant for dataguard.
PROMPT If more details are needed see the ASH DETAILS FOR WORST
PROMPT MINUTES section at the bottom of the report.
column inst format 999
column minute format a12 tru
column event format a30 tru
column program format a40 wra
select to_char(sample_time,'Mondd_hh24mi') minute, inst_id inst, program, event,
sum(time_waited)/1000 TOTAL_WAIT_TIME , count(*) WAITS,
avg(time_waited)/1000 AVG_TIME_WAITED
from gv$active_session_history
where to_char(sample_time,'Mondd_hh24mi') in (select to_char(sample_time,'Mondd_hh24mi')
from gv$active_session_history
where event = 'log file sync'
group by to_char(sample_time,'Mondd_hh24mi'), inst_id
having avg(time_waited)/1000 > &&threshold and sum(time_waited)/1000 > 1)
and (program like '%LGWR%' or program like '%LMS%' or
program like '%LNS%' or event = 'log file sync')
group by to_char(sample_time,'Mondd_hh24mi'), inst_id, program, event
order by 1,2,3,5 desc, 4;

PROMPT
PROMPT HISTOGRAM DATA FOR LFS AND OTHER RELATED WAITS:
PROMPT
PROMPT APPROACH: Look at the wait distribution for log file sync waits
PROMPT by looking at "wait_time_milli". Look at the high wait times then
PROMPT see if you can correlate those with other related wait events.
column event format a40 wra
select inst_id, event, wait_time_milli, wait_count
from gv$event_histogram
where event in ('log file sync','gcs log flush sync',
'log file parallel write','wait for scn ack',
'log file switch completion','gc cr grant 2-way',
'gc buffer busy','gc current block 2-way') or
event like '%LGWR%' or event like '%LNS%'
order by 2 desc,1,3;

PROMPT
PROMPT ORDERED BY WAIT_TIME_MILLI
select inst_id, event, wait_time_milli, wait_count
from gv$event_histogram
where event in ('log file sync','gcs log flush sync',
'log file parallel write','wait for scn ack',
'log file switch completion','gc cr grant 2-way',
'gc buffer busy','gc current block 2-way')
or event like '%LGWR%' or event like '%LNS%'
order by 3,1,2 desc;

PROMPT
PROMPT REDO WRITE STATS
PROMPT
PROMPT "redo write time" in centiseconds (100 per second)
PROMPT 11.1: "redo write broadcast ack time" in centiseconds (100 per second)
PROMPT 11.2: "redo write broadcast ack time" in microseconds (1000 per millisecond)
column value format 99999999999999999999
column milliseconds format 99999999999999.999
select v.version, ss.inst_id, ss.name, ss.value,
decode(substr(version,1,4),
'11.1',decode (name,'redo write time',value*10,
'redo write broadcast ack time',value*10),
'11.2',decode (name,'redo write time',value*10,
'redo write broadcast ack time',value/1000),
decode (name,'redo write time',value*10)) milliseconds
from gv$sysstat ss, v$instance v
where name like 'redo write%' and value > 0
order by 1,2,3;

PROMPT
PROMPT AWR WORST AVG LOG FILE SYNC SNAPS:
PROMPT
PROMPT APPROACH: These are the AWR snaps where the average 'log file sync'
PROMPT times were the highest.
column begin format a12 tru
column end format a12 tru
column name format a13 tru
select dhs.snap_id, dhs.instance_number inst, to_char(dhs.begin_interval_time,'Mondd_hh24mi') BEGIN,
to_char(dhs.end_interval_time,'Mondd_hh24mi') END,
en.name, se.time_waited_micro/1000 total_wait_time, se.total_waits,
se.time_waited_micro/1000 / se.total_waits avg_time_waited
from dba_hist_snapshot dhs, wrh$_system_event se, v$event_name en
where (dhs.snap_id = se.snap_id and dhs.instance_number = se.instance_number)
and se.event_id = en.event_id and en.name = 'log file sync' and
dhs.snap_id in (select snap_id from (
select se.snap_id, se.time_waited_micro/1000 / se.total_waits avg_time_waited
from wrh$_system_event se, v$event_name en
where se.event_id = en.event_id and en.name = 'log file sync'
order by avg_time_waited desc)
where rownum < 4)
order by 1,2;

PROMPT
PROMPT AWR REDO WRITE STATS
PROMPT
PROMPT "redo write time" in centiseconds (100 per second)
PROMPT 11.1: "redo write broadcast ack time" in centiseconds (100 per second)
PROMPT 11.2: "redo write broadcast ack time" in microseconds (1000 per millisecond)
column stat_name format a30 tru
select v.version, ss.snap_id, ss.instance_number inst, sn.stat_name, ss.value,
decode(substr(version,1,4),
'11.1',decode (stat_name,'redo write time',value*10,
'redo write broadcast ack time',value*10),
'11.2',decode (stat_name,'redo write time',value*10,
'redo write broadcast ack time',value/1000),
decode (stat_name,'redo write time',value*10)) milliseconds
from wrh$_sysstat ss, wrh$_stat_name sn, v$instance v
where ss.stat_id = sn.stat_id
and sn.stat_name like 'redo write%' and ss.value > 0
and ss.snap_id in (select snap_id from (
select se.snap_id, se.time_waited_micro/1000 / se.total_waits avg_time_waited
from wrh$_system_event se, v$event_name en
where se.event_id = en.event_id and en.name = 'log file sync'
order by avg_time_waited desc)
where rownum < 4)
order by 1,2,3;

PROMPT
PROMPT AWR LFS AND OTHER RELATED WAITS FOR WORST LFS AWRs:
PROMPT
PROMPT APPROACH: These are the AWR snaps where the average 'log file sync'
PROMPT times were the highest. Look at related waits at those times.
column name format a40 tru
select se.snap_id, se.instance_number inst, en.name,
se.total_waits, se.time_waited_micro/1000 total_wait_time,
se.time_waited_micro/1000 / se.total_waits avg_time_waited
from wrh$_system_event se, v$event_name en
where se.event_id = en.event_id and (en.name in
('log file sync','gcs log flush sync',
'log file parallel write','wait for scn ack',
'log file switch completion','gc cr grant 2-way',
'gc buffer busy','gc current block 2-way')
or en.name like '%LGWR%' or en.name like '%LNS%')
and se.snap_id in (select snap_id from (
select se.snap_id, se.time_waited_micro/1000 / se.total_waits avg_time_waited
from wrh$_system_event se, v$event_name en
where se.event_id = en.event_id and en.name = 'log file sync'
order by avg_time_waited desc)
where rownum < 4)
order by 1, 6 desc;

PROMPT
PROMPT AWR HISTOGRAM DATA FOR LFS AND OTHER RELATED WAITS FOR WORST LFS AWRs:
PROMPT Note: This query won't work on 10.2 - ORA-942
PROMPT
PROMPT APPROACH: Look at the wait distribution for log file sync waits
PROMPT by looking at "wait_time_milli". Look at the high wait times then
PROMPT see if you can correlate those with other related wait events.
select eh.snap_id, eh.instance_number inst, en.name, eh.wait_time_milli, eh.wait_count
from wrh$_event_histogram eh, v$event_name en
where eh.event_id = en.event_id and
(en.name in ('log file sync','gcs log flush sync',
'log file parallel write','wait for scn ack',
'log file switch completion','gc cr grant 2-way',
'gc buffer busy','gc current block 2-way')
or en.name like '%LGWR%' or en.name like '%LNS%')
and snap_id in (select snap_id from (
select se.snap_id, se.time_waited_micro/1000 / se.total_waits avg_time_waited
from wrh$_system_event se, v$event_name en
where se.event_id = en.event_id and en.name = 'log file sync'
order by avg_time_waited desc)
where rownum < 4)
order by 1,3 desc,2,4;

PROMPT
PROMPT ORDERED BY WAIT_TIME_MILLI
PROMPT Note: This query won't work on 10.2 - ORA-942
select eh.snap_id, eh.instance_number inst, en.name, eh.wait_time_milli, eh.wait_count
from wrh$_event_histogram eh, v$event_name en
where eh.event_id = en.event_id and
(en.name in ('log file sync','gcs log flush sync',
'log file parallel write','wait for scn ack',
'log file switch completion','gc cr grant 2-way',
'gc buffer busy','gc current block 2-way')
or en.name like '%LGWR%' or en.name like '%LNS%')
and snap_id in (select snap_id from (
select se.snap_id, se.time_waited_micro/1000 / se.total_waits avg_time_waited
from wrh$_system_event se, v$event_name en
where se.event_id = en.event_id and en.name = 'log file sync'
order by avg_time_waited desc)
where rownum < 4)
order by 1,4,2,3 desc;

PROMPT
PROMPT ASH DETAILS FOR WORST MINUTES:
PROMPT
PROMPT APPROACH: If you cannot determine the problem from the data
PROMPT above, you may need to look at the details of what each session
PROMPT is doing during each 'bad' snap. Most likely you will want to
PROMPT note the times of the high log file sync waits, look at what
PROMPT LGWR is doing at those times, and go from there...
column program format a45 wra
column sample_time format a25 tru
column event format a30 tru
column time_waited format 999999.999
column p1 format a40 tru
column p2 format a40 tru
column p3 format a40 tru
select sample_time, inst_id inst, session_id, program, event, time_waited/1000 TIME_WAITED,
p1text||': '||p1 p1,p2text||': '||p2 p2,p3text||': '||p3 p3
from gv$active_session_history
where to_char(sample_time,'Mondd_hh24mi') in (select
to_char(sample_time,'Mondd_hh24mi')
from gv$active_session_history
where event = 'log file sync'
group by to_char(sample_time,'Mondd_hh24mi'), inst_id
having avg(time_waited)/1000 > &&threshold)
and time_waited > 0.5
order by 1,2,3,4,5;

select to_char(sysdate,'Mondd hh24:mi:ss') TIME from dual;

spool off

PROMPT
PROMPT OUTPUT FILE IS: lfsdiag_&&dbname&&timestamp&&suffix
PROMPT

该脚本输出结果大致如下:

LFSDIAG DATA FOR DBM_Oct10_1307
Note: All timings are in milliseconds (1000 milliseconds = 1 second)

IMPORTANT PARAMETERS RELATING TO LOG FILE SYNC WAITS:

   INST_ID NAME                                     VALUE
---------- ---------------------------------------- ----------------------------------------
         1 commit_logging
         1 commit_point_strength                    1
         1 commit_wait
         1 commit_write
         1 log_archive_local_first                  TRUE
         1 log_archive_max_processes                4
         1 log_archive_min_succeed_dest             1
         1 log_archive_start                        FALSE
         1 log_archive_trace                        0
         2 commit_logging
         2 commit_point_strength                    1
         2 commit_wait
         2 commit_write
         2 log_archive_local_first                  TRUE
         2 log_archive_max_processes                4
         2 log_archive_min_succeed_dest             1
         2 log_archive_start                        FALSE
         2 log_archive_trace                        0

ASH THRESHOLD...

This will be the threshold in milliseconds for average log file sync
times. This will be used for the next queries to look for the worst
'log file sync' minutes. Any minutes that have an average log file
sync time greater than the threshold will be analyzed further.

THRESHOLD_IN_MS
---------------
           .000

ASH WORST MINUTES FOR LOG FILE SYNC WAITS:

APPROACH: These are the minutes where the avg log file sync time
was the highest (in milliseconds).

MINUTE          INST_ID EVENT                            TOTAL_WAIT_TIME      WAITS   AVG_TIME_WAITED
------------ ---------- ------------------------------ ----------------- ---------- -----------------
Oct01_0111            2 log file sync                               .807          1              .807
Oct02_0600            2 log file sync                              4.308          1             4.308
Oct09_0043            2 log file sync                            999.805          1           999.805

ASH LFS BACKGROUND PROCESS WAITS DURING WORST MINUTES:

APPROACH: What is LGWR doing when 'log file sync' waits
are happening? LMS info may be relevent for broadcast
on commit and LNS data may be relevant for dataguard.
If more details are needed see the ASH DETAILS FOR WORST
MINUTES section at the bottom of the report.

MINUTE       INST PROGRAM                                  EVENT                            TOTAL_WAIT_TIME      WAITS   AVG_TIME_WAITED
------------ ---- ---------------------------------------- ------------------------------ ----------------- ---------- -----------------
Oct02_0600      2 oracle@racnode1.us.oracle.com (LGWR)    log file parallel write                    4.088          1             4.088
Oct02_0600      2 oracle@racnode1.us.oracle.com (M000)    log file sync                              4.308          1             4.308
Oct09_0043      2 oracle@racnode1.us.oracle.com (LGWR)    log file parallel write                 1000.738          1          1000.738
Oct09_0043      2 sqlplus@racnode1.us.oracle.com (TNS V1- log file sync                            999.805          1           999.805
                  V3)


HISTOGRAM DATA FOR LFS AND OTHER RELATED WAITS:

APPROACH: Look at the wait distribution for log file sync waits
by looking at "wait_time_milli". Look at the high wait times then
see if you can correlate those with other related wait events.

   INST_ID EVENT                                    WAIT_TIME_MILLI WAIT_COUNT
---------- ---------------------------------------- --------------- ----------
         2 wait for scn ack                                       1          0
         2 wait for scn ack                                       2          0
         2 wait for scn ack                                       4          0
         2 wait for scn ack                                       8          1
         1 log file sync                                          1      10247
         1 log file sync                                          2        435
         1 log file sync                                          4        122
         1 log file sync                                          8         33
         1 log file sync                                         16          4
         1 log file sync                                         32          2
         1 log file sync                                         64          2
         1 log file sync                                        128          1
         1 log file sync                                        256          1
         1 log file sync                                        512          0
....................................

浅谈log file sync等待事件诊断(二)

原因3:用户提交过于频繁导致log file sync

在这种情况下,过多的 commit 活动可能会导致性能问题,因为把 redo 从日志缓冲区刷新到重做日志可能会导致等待’log file sync’。
如果’log file sync’的平均等待时间比’log file parallel write’高很多,这意味着大部分时间等待不是由于等待 redo 的写入,因而问题的原因不是 IO 慢导致。,其他时间可能是 CPU 活动竞争,而且是过多的 commit 导致的最常见的竞争。此外,如果’log file sync’的平均等待时间低,但等待次数高,那么应用程序可能 commit 过于频繁。

在 AWR 或 Statspack 报告中,如果每次 commit/rollback 的平均 user calls(”user calls/(user commits+user rollbacks)”) 小于 30, 表明 commit 过于频繁。
建议

  • 如果有很多短事务,看是否可能把这些事务组合在一起,从而减少 commit 操作。 因为每一个 commit 都必须收到相关 REDO 已写到磁盘上的确认,额外的 commit 会显著的增加开销。虽然 Oracle 可以将某些 commit 组合在一起,通过事务的批处理来减少commit的总体数量还是可以带来非常有益的效果。
  • 看看是否有操作可以使用 COMMIT NOWAIT 选项 (使用前应明白该选项会带来的后果)。
  • 看看是否有操作可以使用 NOLOGGING/ UNRECOVERABLE 选项完成(在不追求可恢复的情况下)。

 

经过已经分析,大概可以得出一个思路,尽量结合与lgwr有关的等待事件一起结合起来定位问题,此时应该检查awr或者statspack的等待事件。

11g新特性:
在oracle 11.2版本中引入了 Adaptive Log File sync,由参数_use_adaptive_log_file_sync控制,该参数在11.2.0.1和11.2.0.2默认设置为 false。
从 11.2.0.3 开始默认是 true。 当启用时,Oracle 可以在两种方法之间切换:

Post/wait,传统发布写重做日志完成的方法
Polling,一种新的方法,其中前台进程会检查 LGWR 是否已写完成。

该特性在一定情况下也会造成log file sync等待大量增加。

当log file sync等待事件是由于RAC节点之间SCN同步引起的,其解决方法如下:
1、检查LMS进程数量是否足够。
2、检查系统CPU资源是否足够。
3、检查RAC节点之间的私有通信是否正常。
4、设置隐含参数_immediate_commit_propagation为false,禁用immediate commit propagation特性。
RAC节点之间CR块传递
Oracle为了保证Instance Recovery实例恢复机制,而要求每一个current block在本地节点local instance被修改后(modify/update) 必须要将该current block相关的redo 写入到logfile 后(要求LGWR必须完成写入后才能返回),才能由LMS进程传输给其他节点使用。

浅谈log file sync等待事件诊断(一)

最近一个压力较大的数据库log file sync等待TOP 1.经过处理后也趁着这个时间把这个等待事件的一些信息整理一次。

什么是’log file sync’等待事件?

当一个用户session commit,会话事务相关生成的redo entry会从内存刷新到redo onlinelog。
在提交时,用户会话会通知 LGWR 把日志缓冲区中的信息写到重做日志文件(当前所有未被写入磁盘的 redo 信息,包括本次会话的 redo 信息)。当 LGWR 完成写操作后,它会通知用户会话。当等待 LGWR 通知确认所有 redo 已经全部保存到磁盘的过程时,用户会话会等待’log file sync’此时用户session显示等待’log file sync’,它是用户会话通知 LGWR 和 LGWR 通知用户的写操作完成之间的时间。

应该搜集那些信息来分析’log file sync’等待事件?

1.发生log file sync时间段的AWR/SP报告
2.当时的系统负载信息(最好有OSWATCH)
3.对应时间段的Alert.log日志信息

很高的’log file sync’等待的可能原因?

通常造成这类现象的原因有3个,具体如下:

1.Oracle 已知的bug造成
2.磁盘的IO负载过高,导致LGWR将REDO写入logfile的速度受影响
3.用户提交(commit)过于频繁

原因1:关于log file sync同步的bug

NB Bug Fixed Description
14823372 11.2.0.3.BP23, 11.2.0.4, 12.1.0.1 Adaptive “log file sync” picks inaccurate polling interval on RAC
13707904 11.2.0.4, 12.1.0.1 LGWR sometimes uses polling, sometimes post/wait
12614085 11.2.0.4, 12.1.0.1 Diagnostic enhancement to add new statistics for investigating “log file sync” and “log file parallel write” relationship
P 16102401 11.2.0.3.BP16, 11.2.0.4, 12.1.0.1 identify correct effective mutiplier for sparc t5 processor
13551402 11.2.0.3.9, 11.2.0.3.BP22, 11.2.0.4, 12.1.0.1 High “log file parallel write” and “log file sync” after upgrading 11.2 with Veritas/Symantec ODM
P 12951619 11.2.0.4, 12.1.0.1 Solaris: Enhancement to allow database to use critical threads feature in Solaris
12378147 11.2.0.2.7, 11.2.0.2.BP10, 11.2.0.3, 12.1.0.1 Long broadcast ack warning messages, and/or many Log File Sync timeouts in foregrounds in RAC
9095696 11.2.0.3.7, 11.2.0.3.BP08, 11.2.0.4, 12.1.0.1 “log file sync” wait time spikes with ARCHIVE_LAG_TARGET set
13074706 11.2.0.3.BP14, 11.2.0.4, 12.1.0.1 Long “log file sync” waits in RAC not correlated with slow writes
8490879 10.2.0.4.4, 10.2.0.5, 11.1.0.7.3, 11.2.0.1 Long “log file sync” latencies due to broadcast on commit scheme
8220734 10.2.0.4.4, 10.2.0.5, 11.1.0.7.3, 11.2.0.1 Long “log file sync” wait in RAC
7716356 10.2.0.5, 11.2.0.1 Long “log file sync” latencies with broadcast on commit scheme in RAC
7643632 10.2.0.4.1, 10.2.0.5, 11.1.0.7.4, 11.2.0.1 High log file sync in Data Guard maximum availability (sync) mode
7610362 10.2.0.4.4, 10.2.0.5, 11.1.0.7.3, 11.2.0.1 Long “log file sync” waits in RAC with broadcast on commit in RAC
P 7568734 10.2.0.5, 11.2.0.1 AIX: Sporadic spikes of ‘log file sync’ on AIX with heavy commit concurrency
7452373 10.2.0.5, 11.1.0.7.1, 11.2.0.1 “log file sync” timeout is not configurable
6319685 10.2.0.4, 11.1.0.7, 11.2.0.1 LGWR posts do not scale on some platforms
6193945 10.2.0.4.1, 10.2.0.5, 11.1.0.7, 11.2.0.1 High LGWR CPU use and long ‘log file sync’ latency in RAC
9776431 11.1.0.7.4 11.1.0.7.3 fix for 8220734 is incomplete – “log file sync” timeout set to 1 second
5896963 10.2.0.4, 11.1.0.6 High LGWR CPU and longer “log file sync” with fix for bug 5065930
5147386 10.2.0.4.1, 10.2.0.5, 11.1.0.6 Long waits on “log file sync” /random ORA-27152 “attempt to post process failed”
5087592 10.2.0.4, 11.1.0.6 “log file sync” waits from read only commits
5065930 10.2.0.3, 11.1.0.6 “log file sync” timeouts can occur
5061068 10.2.0.3, 11.1.0.6 RAC using “broadcast on commit” can see delayed commit times
3311210 9.2.0.5, 10.1.0.2 Unnecessary 0.5 seconds waits for “Broadcast on commit” SCN scheme
2663122 9.2.0.5, 10.1.0.2 Unneccessarily long waits on “log file sync” can occur
2640686 9.2.0.5, 10.1.0.2 Long waits for “log file sync” with broadcast SCN in RAC

原因2:磁盘的IO负载过高,导致LGWR将REDO写入logfile的速度受影响

情况1.比较’log file sync’和’log file parallel write’的平均等待时间结合诊断
等待事件’log file parallel write’表示 LGWR 正在等待写 redo 操作。该事件的持续时间就是等待 IO 操作部分的时间。结合事件“log file sync”看同步操作消耗在 IO 的时间,由此推断,有多少处理时间消耗在 CPU 上。

如果’log file sync’ 和 ‘log file parallel write’ 都有很高的等待时间,而且’log file sync’的时间消耗在’log file parallel write’上的比例高,那么大部分的等待时间是由于 IO(等待 redo 写入)。应该检查 LGWR 在 IO 方面的性能。Oracle官方的一个经验法则,’log file parallel write’平均时间超过 20 毫秒, 意味着 IO 子系统有问题。

这种情况下建议

  • 降低redolog所在的文件系统其他不必要的IO开销。
  • 建议redolog不放在raid5阵列上的卷组中,众所周知raid5的写惩罚是最高的。
  • 建议redolog不放在 SSD硬盘中,虽然通常情况下,SSD 写入性能好于平均水平,但是可能会遇到写峰值,从而导致大量的增加’log file sync’等待
  • 监控其他可能需要写到相同目录卷组的进程,确保该磁盘具有足够的IO吞吐量,足以应付所要求的容量。
  • 确保 LOG_BUFFER 不要太大,一个非常大的 log_buffer 的不利影响就是刷新需要更长的等待时间。当缓冲区满了的时候,它必须将所有数据写入到重做日志文件。LGWR 将一直等待,直到最后的 I/O 完成。
  • 避免redol log file member超过1个

尽管’log file parallel write’的平均等待时间可能在一个合理的区间范围内,在峰值时刻写操作时间还是可能会很长进而影响’log file sync’的等待时间。从10.2.0.4 开始如果写操作超过 500 毫秒我们会在 LGWR 的 trace 中写警告信息。这个阀值很高所以就算没有警告也不代表没有问题。警告信息如下:

*** 2012-11-13 20:13:41.718
Warning: log write elapsed time 21130ms, size 1KB
(set event 10468 level 4 to disable this warning)

*** 2012-11-13 20:13:42.929
Warning: log write elapsed time 4916ms, size 1KB
(set event 10468 level 4 to disable this warning)

注意:上面的峰值如果时间间隔的很远,可能不会对’log file parallel wait’有大的影响。 但是,如果有 100 个会话等待’log file parallel wait’完成,’log file sync’总等待可能就会很高,因为等待时间将被乘以会话的个数 100。因此,需要重点关注日志写 IO 高峰的原因。

此时建议:

  • 检查其他正在发生的可能会导致 LGWR 写磁盘峰值的操作,比如大量的导入操作,插入,或者系统级别的文件拷贝,以及大量的trace文件产生的情况
  • 当 LGWR 进程慢的时候,对其进行 Truss 操作会帮助确定时间消耗在什么方面

这些警告信息对于预防潜在问题的发生很有帮助。就算平均等待时间没问题,通过找到 I/O 性能峰值点,可以知道 LGWR 会间歇性的遇到性能问题,进而在它引发更大问题前将其解决。

情况2.redolog file 大小是否足够,这里和LGWR switch等待事件一起结合诊断

每次redolog切换到下一个日志时,会执行’log file sync’操作,以确保下一个日志开始写之前redo信息都写完。如果日志切换频繁,则预示着会产生更多的log file sync等待,这个时候就需要考虑增加redo logfile的大小,控制redolog file的切换频率保持在15分钟到20分钟左右一个。

 

 

浅谈RAC中 Gc block lost 的诊断

Oracle的RAC环境中,数据库会收集global cache 的工作负载统计信息,这些信息可以通过STATSPACK, AWRs 和 GRID CONTROL等工具。
对于每个节点,RAC都会对global cache中的数据传输信息进行监控和评估,global cache数据传输信息情况 代表了私有网络通信的包处理效率低或者包的处理存在异常。如果golbal cache与Enqueue服务的通信出现异常在相关的AWR和statspack中可以检测到相关的等待事件,这类等待事件基本为gc cr block lost 和/或 gc current block lost。数据库绝大部分的 global cache lost blocks的问题都可以直接联系到私网的故障和错误的配置。本文可以作为调查和评估常见原因(有时是非常明显)的指南。

尽管我们讨论的大部分都是性能问题,但是这些问题也有可能会导致节点或实例的驱逐。Oracle集群和RAC实例依赖于心跳来维持节点关系。如果网络心跳持续无法连通,那么实例/节点驱逐就会发生 。因此,以下的这些场景症状也和节点/实例驱逐相关。

主要现象:

“gc cr block lost” / “gc current block lost” 出现在AWR的top 5等待事件中或者产生了非常多的等待。

其次:

1.SQL traces 文件中多次出现 gc cr requests / gc current request
2.出现 gc cr multiblock requests 等待,每次等待时间都很长而且elapsed times 都一样。
3.应用的性能和吞吐量都很差
4.通过ifconfig或者其它第三方的工具能够看到网络上发送和接受包的错误
5.使用netstat命令会看到一些error/retransmits/reassembly failures
6.节点故障和节点通信错误
7.大量的CPU消耗在网络进程上

注意: 块丢失的问题通常会和gc cr multiblock requests 等待同时出现,如:等待连续的块扫描

可能的原因:

可能的原因已经在下面的诊断指南中列出(按照出现概率排序)

一.网线/网卡/交换机问题

描述: 坏掉的网线连接,错误的电缆,制作粗糙的电缆,过于冗长和错误的端口分配,有问题的交换机都会导致低下的传输率,块损坏,数据包丢失和性能问题。

解决: 敦促网络供应商对网络进行检查,更换坏掉的网络组件。集群私网应该使用CAT 5 级或者是更好的通信线缆.所有的设备都需要确保安全插牢,并且按照线缆和端口进行标识,线缆的长度需要符合供应商指定的要求。

二.UDP receive(rx) buffer sizes设置过小/UDP buffer socket溢出

描述: Oracle RAC Global cache块的处理是突发性的,因此,操作系统需要缓冲区来接受接收(RX)数据包并等待CPU的处理,如果缓冲区设置的不合理或者过小会导致块丢失和global cache 块丢失。通过’netstat -s’ 或者 ‘netstat -su’命令可以帮助我们在unix平台上获取到UDPInoverflows,package receive errors, dropped framces 或packets dropped due to buffer full errors信息。

解决: 数据包丢失往往是由于在接收服务器上设置的UDP缓冲区不足,从而导致了块在缓冲区中溢出而产生块丢失。当OS的缓冲区设置小于128k的时候,Oracle 在打开一个socket 时会设置 UDP receive buffer 尺寸为 128k。如果OS的缓冲区设置大于128k,Oracle会采用OS 的设置。如果数据库的块尺寸大于8k,那么缓冲区会自动的进行调整,但是不会超过OS的限制。当DB参数DB_FILE_MULTIBLOCK_READ_COUNT的值大于4时,如果发现 UDP buffer overflows, packet loss 和 lost blocks,并且数据库出现了大量的”global cache cr requests”等待超时,这是由于缓冲区设置过小导致的,我们可以通过调大OS的UDP缓冲区的或者调低数据库参数DB_FILE_MULTIBLOCK_READ_COUNT来解决问题 ,这个参数可以在系统或session级别调整。

对于大部分的unix平台,我们可以通过以下的一些命令来判断是否出现UDP缓冲区溢出或者block loss,执行:

‘netstat -s’ 或 ‘netstat -su’,并根据具体平台查看 “udpInOverflowsudpInOverflows”, “packet receive errors”, “fragments dropped” 或 “outgoing packet drop” 信息

注意:UDP丢包通常会引起更多的延迟,网络带宽减少,更高的CPU使用率(kernel 和user),以及消耗更多的内存来处理这些包的重传。
在系统运行时,如果工作节点(运行负载的节点)对应的远程节点上命令netstat –s的输出中 “outgoing packets dropped”值显著的增加,同时增加wmem_default 和 wmem_max到4M(Linux平台)可以解决问题。

UDP发送和接收缓冲区参数是和操作系统有关的,它们可以滚动(rolling)修改(例如:每次1个节点)。

三.私网性能差并且CPU使用率高,`netstat -s` 出现packet reassembly failures

描述: 根据MTU(Maximum Transmission Unit)的尺寸,大的UDP数据包可能被分片,并在多个帧中发送。这些零散的数据包需要在接收节点上重新组合。高CPU使用率(持续的或者是频繁的峰值),过小的reassembly buffer或者UDP buffer也会导致块重组失败。在接收节点’netstat -s’输出的 “IP Statistics”部分提示有大量的Internet Protocol (IP)上的”reassembles failed” 和 “fragments dropped after timeout”信息。分片的报文需要在指定时间(time-to-live)内完成重组(reassemble)。没有能够完成重组的分片报文会被丢弃并要求重传。已经收到,但是由于空间不足没有进行重组的数据分片会被直接丢弃。

`netstat -s` IP stat counters:
3104582 fragments dropped after timeout
34550600 reassemblies required
8961342 packets reassembled ok
3104582 packet reassembles failed.

解决: 增加reassemble buffer尺寸,给重组分配更多的空间。增加reassemble的时间,增加UDP receive buffer以避免由于网络延迟导致的reassemble失败,并找到对网络数据包处理产生负面影响的高CPU 利用率原因.
注意: 增加以下设置的同时也会增加内存的使用

LINUX:
我们可以通过以下设置来修改reassemble buffer大小
/proc/sys/net/ipv4/ipfrag_low_thresh (default = 196608)
/proc/sys/net/ipv4/ipfrag_high_thresh (default = 262144)

我们可以通过以下设置来修改reassemble的时间:
/proc/sys/net/ipv4/ipfrag_time (default = 30)

请参考OS文档了解不同平台的对应命令语法。

四.网络传输坏块(corruption)导致的UDP checksum errors 和/或 send (tx) / receive (rx) transmission errors

描述: UDP包传输的过程中,接受进程会读取数据包头的校验值。任何校验值损坏都会使这个包被丢弃,并导致重发,这会增加CPU的使用率并且延缓数据包处理。

解决: 使用 tcpdump,snoop等网络工具来捕获数据包的dump,定位这些checksum错误并确认checksum corruption。敦促OS或者网络管理员查找产生corruption的原因。 已知的问题是由于网卡上开启了Checksum offloading 导致了checksum 错误,如果出现这样的问题请检查checksum offloading的功能是否被禁用,测试后考虑关闭网卡上的该项功能。在Linux系统上执行ethtool -K rx off tx off可以关闭该功能.

五.在通信通道中设置了不匹配的MTU的值

描述: 不匹配的MTU大小设置会导致传输过程中出现 “packet too big” 错误并丢失数据包,导致global cache block丢失和大量的重传(retransmission)申请。.
解决: MTU 是”Maximum Transmission Unit” 或者是私网通信过程中帧的尺寸.

对于以太网(Ethernet),大多数UNIX平台的默认值是1500字节。私网链路中所有设备都应该定义相同的MTU。请确认并监控私网链路中的所有的设备。为ping ,tracepath,traceroute命令指定大的,非默认尺寸,ICMP probe 包来检查MTU设置是否存在不一致。使用ifconfig或者厂商推荐的工具为服务器网卡(NIC)的MTU设置合适的值。关于JUMBO Frames的设置,请见第12点的介绍。

注意:私网中不一致的MTU值会导致节点无法加入集群的问题。

六.使用非专用的私网链接

描述: 共享的公网和私网配置会导致应用性能低下,网络拥堵,在一些极端的情况下会导致global cache block loss.
解决:数据库/集群私网应该使用独占的VLAN,并定义在non-routed子网中。私网的交换机需要独立于其他的交换机,例如,私网交换机不应该是从接入层的交换机扩展出来,私网的交换机不应该和公网或者NAS的交换机共享。如果使用了VLANs,那么私网应该被划分在单独的VLAN中,并且位于独占的 ,non-routed 子网,独立于公网或者NAS网络。

七.服务器/交换机缺少“邻接”(adjacency)配置

描述: 通常,如果网络上的设备能够通过单跳链接,我们称为“邻接”(adjacency).多跳的配置会增加网络上的延迟,也会增加更多的节点故障风险.
解决: 所有的 GbE(千兆以太网)服务器的私网链接都应该邻接在交换机或者交换机组(如果配置了交换机冗余)上。在私网链路中,不应该出现中间网络设备,例如:路由器。在Unix平台上,我们可以通过tracetroute命令来确定“邻接”问题。
配置了 IPFILTER

描述:配置主机防火墙或网络地址转换(NAT)软件– IPFILTER (IPF)也是导致私网通信问题的原因之一。IPF还会导致严重的应用程序性能下降,丢包以及global cache block loss问题.
解决: 禁用 IPFILTER

八.过时的网卡驱动程序(Network driver)或者是网卡固件(firmware)

描述: 过时的网卡驱动程序或固件,是已知的私网数据包传输问题原因。不兼容的网卡驱动程序会导致节点间通信过程中数据包处理延迟,延迟增加和丢包。
解决: 所有节点上的网卡应该采用相同的制造商和型号,相同的性能参数,和对称的插槽(slot) ID。集群中所有节点的私网网卡固件和驱动程序都应该是一致的(最新的)。

九.特殊的私网链接和网络协议

描述: 非标准的,专享的网络协议,如LLT ,HMP等已经被证明是不稳定的而且很难debug。使用非标准的,专享的网络协议会导致应用的性能下降,丢包和节点重启等故障。
解决: Oracle使用1GbE UDP 作为传输和通信协议,这已经被证明是稳定的,可靠的和高性能的。请避免使用特别的和非标准的通信协议。 在一些平台上,基于Inifiniband 的IP和RDS协议是可用的并且是Oracle支持的,而且10GbE已经被认证(详细信息请参见OTN) – Oracle还在进行这方面的认证工作。
.
十.错误配置的网卡绑定/链路聚合

描述:服务器上错误的网卡绑定或链路聚合配置,邻接的私网交换机上错误的聚合配置会导致性能下降,出现由”port flapping”导致的block loss,交换机上构成私网端口的聚合链路发生频繁的”UP”/”DOWN”状态切换。
解决: 如果在集群服务器上为私网配置了链路聚合,那么交换机上的端口也应该支持这种配置,并按照聚合配置来配合私网的通信。交换机上构成私网端口的聚合链路配置错误会导致 ‘port flapping’,交换机端口会被随机删除,导致丢包.对于绑定和聚合,请参考驱动器(driver)文档进行配置,并且在有工作负载的环境下进行测试。 有很多公开的工具和软件可以协助进行带宽和性能延迟的测试(请参考iperf)。我们应该通过评估OS,网络和网络驱动器的统计数据来确定绑定的性能.

十一.错误的巨帧(Jumbo Frame)配置

描述: 错误的Jumbo Frames配置会产生之前提到的不一致的MTU问题

解决:Jumbo Frames 并不是IEEE 标准配置,所以配置的时候应该很小心。单个Jumb Frame的大小是9000 bytes左右。Frame 的大小取决于网络设备供应商,在不同的通信设备上的大小可能是不一致的。如果默认的MTU 尺寸不是9000bytes,请保证通信路径中的所有设备(例如:交换机/网络设备/网卡)都能够支持一个统一的MTU值,在操作的过程中必须把Frame Size(MTU Size)配置成这个值。不合适的MTU设置,例如:交换机上配置MTU=1500,但是服务器上的私网网卡配置成MTU=9000,这样会造成丢包,包的碎片和重组的错误,这些都会导致严重的性能问题和节点异常宕机。大部分的平台上我们都可以通过netstat –s命令的‘IP stats’输出发现包的碎片和重组的错误。大部分的平台上我们可以通过ifconfig –a命令找到frame size的设置。关于交换机上的配置查询,需要查看交换机提供商的文档来确定。

十二.网卡双工( Duplex)模式不匹配

描述:网卡的双工模式不匹配是指,在同一个交互的链路上,一端使用的是全双工模式,另外一端使用的是半双工模式。这通常是是手动配置错误导致的 或者是一端配置被修改成半双工模式时,另外一端配置成了auto-negotiate引起的。双工模式不匹配会导致严重的私网通信性能问题

解决: 集群中所有节点的私网网卡和交换机上的私网线路对应的双工模式都应该配置为auto-negotiate。千兆以太网标准要求auto-negotiate 设置为”on”。双工模式不匹配可能会导致严重的网络性能下降,数据冲突和丢包的情况出现。 每次进行网络硬件和软件升级后都应该检查auto-negotiate设置, Auto-negotiate 在所有的设备上都应该是1000全双工模式。

十三.私网通信链路流量控制(Flow-control)不匹配

描述: 流量控制是指,当一台服务器传输的速度比接收节点(或者是网络设备)的接受速度快 。接收设备会发送“暂停”帧来请求发送端暂时停止发送数据包.
解决:交换机和服务器网卡之间Flow-control设置不匹配的时候会导致丢包和严重的网络性能问题。大部分的情况下,默认的设置”ON”是最好的结果。例如:

tx flow control should be turned on
rx flow control should be turned on
tx/rx flow control should be turned on for the switch(es)

尽管如此,对于一些特殊的案例(例如 note 400959.1),例如一些OS或交换机固件的bug,设置成OFF(所有的网络路径)会有更好的结果。

注意:Flow control的设置在固件/网络驱动程序升级后会发生变化,网卡/交换机的设置应该在升级后重新检查。如果没有设备提供商的其它建议值,请使用默认的值。

十四.OS,网卡,交换机层面的数据包丢弃

描述:任何被OS,网卡或者交换机提示的包丢弃信息都应该被彻底的调查和解决。包丢失会导致私网性能降低,CPU使用过高以及节点异常宕机等情况

解决:具体的工具会帮助我们确定包或帧丢失问题发生在那个层面(process/OS/network/switch)。netstat ,ifconfig,ethtool,kstat(依赖于OS的平台)命令输出和交换机端口状态是首先要进行检查和评估的。您需要一些网络嗅探器(sniffer)跟踪点对点数据通信来排查问题(常见的工具:snoop/wireshare/ethereal).

注意:从底层来理解丢包的原因是我们找到根本原因不可缺少的步骤。在网络环境中,过小的网卡ring buffers或者receive queues是已知的导致网络上异常丢包的原因,比如:在所有层面都没有提示发生了丢包。请查看下面的网卡驱动问题和Kernel queue长度.这种情况,需要联系系统管理员和网络工程师来确定根本的原因.

十五.网卡驱动/固件配置问题

描述:不合适的配置或者网卡中一些可调属性的不恰当的默认也会导致丢包并增加重传的请求.

解决:大部分网络设备供应商提供的默认出厂配置是可以满足应用要求的。尽管如此,一些网络供应商提供的网卡设备需要修改interrupt coalescence设置和ring buffers描述符数量。interrupt coalescence是CPU发送和接受数据包的中断率。ring buffer在 CPU中断之间持有需要处理的rx 包。不合适的配置会导致在这个层面丢失数据包,诊断这个层面的问题需要系统管理员以及OS/设备提供商的参与。

十六.网卡发送(tx)和接受(rx)队列的长度

描述:设置过小的网卡tx/rx队列长度会导致在队列满的时候出现丢包的情况,这会导致gc block loss,增加重传并且降低私网的效率。

解决:在内核网络子系统(kernel network subsystem)和网络接口设备驱动程序之间移动数据时,发送(TX)和接收(Rx)队列用来实现对数据包的传输和处理进行管理.这些队列的大小是可以配置的。针对产生的网络流量或者配置了MTU的情况,如果这些队列的配置不合适或者过小,队列填满后会导致数据包的丢失或溢出。取决于设备的驱动程序和搜集到的统计信息数量,这类丢包是不容易被发现的,诊断这个层面的问题需要系统管理员和OS/设备的提供商的介入。(通常在linux上我们设置参数:iftxtqueue 和netdev_max_backlog)

十七.有限的负载能力和过于饱和的带宽

描述: 过载的网络使用也会导致私网的性能问题和丢包。

解决: 私网配置的最佳实践是您需要知道您的网络使用情况和带宽。这需要通过定期的监控来获取使用的趋势,瞬时值和恒定的值。私网上突然增加的使用请求可能是应用程序调整或异常导致的,如性能很差的SQL语句或者异常产生的数据流量。找到产生带宽饱和的原因并解决它。

十八.过度的CPU申请和调度延迟

描述: 持续的高负载和网络堆栈的调度延迟也会对私网的数据包传输产生负面的影响并且会导致私网的性能下降,丢包,gc block loss和节点的重启问题。

解决: 持续的高CPU使用率导致的调度延迟也会导致网络上数据包的延迟处理。过度,持续的延迟会导致严重的性能下降,并可能导致群集节点故障。关键是要找到持续的高CPU使用率的原因。使用uptime命令能够列出大部分操作系统的平均负载情况,和网络堆栈处理相关的CPU问题,可以通过NIC interrupt coalescence或者绑定网络到单个CPU得到缓解,请和网络设备的供应商一起来进行此类的优化。调度延迟会导致数据包重组错误。请参见本文的第2点。

十九.和交换机相关的数据包处理问题

描述:交换机的端口缓冲区溢出,交换机拥堵和配置问题,比如MTU大小,网络聚合和VLANS 都能导致低效率的数据包处理和集群节点故障。

解决:Oracle私网需要一个包含交换机的以太网网络。交换机是私网中点对点通信至关重要的组成部分。作为一个网络设备,这个交换机会受到多种因素的影响并导致私网通信性能和高可用性出现异常。监控交换机的异常,数据包处理事件,临时的或持续的吞吐量信息是非常重要的。交换机的状态统计信息,应该定期进行检查并评估是否正常,并找出异常情况。

二十.QoS对私网数据包处理产生的负面影响

描述:在交换机上定义的QoS会共享私网通信的带宽并影响私网处理能力,导致私网性能的下降。

解决: 如果私网布置在共享交换机的VLAN上,QoS应该通过优先级配置来避免对私网通信产生负面的影响。任何QoS的定义在布置前都应该进行评估,确保不会影响私网通信.

二十一.重聚(reconvergence)过程中生成树(Spanning tree)限电

描述:以太网使用生成树协议(STP)来避免网络环路,确保交换机和冗余的交换机能直接路由到服务器。任何包含在STP拓扑中的设备故障都会导致重新计算路由到主机的重聚。如果STP协议在局域网中被起用,但是配置的有
问题或未经优化,网络重聚事件可能需要长达1分钟或者更长的时间(取决于网络的规模和参与设备)。这种延迟会导致私网问题和集群范围的中断。

解决:很多交换机供应商提供优化的扩展,使STP能够实现更快的网络重聚。例如: Rapid Spanning Tree (RSTP), Per-VLAN Spanning Tree (PVST)和Multi-Spanning Tree (MSTP) 可以避免集群大范围的异常出现。

二十二.STREAMS队列的sq_max_size 配置太小

描述: AWR 提示 “gc cr block lost” 和/或”gc current block lost”等待时间很高。 netstat 并没有提示有任何数据包处理的错误. `kstat -p -s ‘*nocanput*` 返回非0值. nocanput 说明streaming message队列已满,并且包被丢弃。 客户在Solaris平台RAC环境下使用STREAMS。
解决: 增加UDP max buffer space,并且把STREAMS队列设置成unlimited能够解决问题,并且消除”nocanput” lost messges。以下是Solaris平台下对应的命令:
`ndd -set /dev/udp udp_max_buf `
set sq_max_size to 0 (unlimited) in /etc/system. Default = 2

udp_max_buf 控制UDP socket发送和接受缓冲区的大小,默认值是262,144 bytes,这个值对于使用STREAMS的应用来说是不够用的。sq_max_size 控制message的队列的长度。

二十三.VIPA和DGD设置不正确(仅限Aix平台)

如果您在AIX平台上使用了VIPA(Virtual IP Address),那么Dead Gateway Detection (DGD)必须配置成允许UDP failover模式。

默认的DGD参数可以作为配置起始值,但是在一些客户的环境中,这些参数可能需要调整,但是无论何种情况,都必须设置成大于1的值。默认的设置如下:
dgd_packets_lost = 3
dgd_ping_time = 5
dgd_retry_time = 5

更多配置信息,请参考文章Using VIPA and Dead Gateway Detection on AIX for High Availability Networks, including Oracle RAC: http://www-03.ibm.com/support/techdocs/atsmastr.nsf/WebIndex/WP102177

Solaris+Vertis LLT的环境上,交换机的错误配置

当VCS命令lltstat的输出显示”Snd retransmit data”增加时,gc block lost 也会增加。把私网交换机的速度从fixed修改成auto-negotiate,更均匀地分布电缆到每个模块的链接,这样有助于解决”gc blocks lost”的问题