【Oracle】 检查log fie sysnc 等待事件的脚本

-- 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_.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&×tamp&&suffix 

set trim on 

set trims on 

set lines 130 

set pages 100 

set verify off 

alter session set optimizer_features_enable = '10.2.0.4'; 

PROMPT LFSDIAG DATA FOR &&dbname&×tamp 

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 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 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 <= 5;

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 event format a30 tru 

column program format a35 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 event format a30 tru 

column program format a35 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 (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 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)

 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&×tamp&&suffix 

PROMPT 

时间: 2024-12-24 20:10:16

【Oracle】 检查log fie sysnc 等待事件的脚本的相关文章

[20161228]奇怪log file sync等待事件.txt

[20161228]奇怪log file sync等待事件.txt --这个来自链接:http://www.itpub.net/thread-2073857-1-1.html的讨论,很奇怪的问题: Top 10 Foreground Events by Total Wait Time Event                                              Waits    Total Wait Time (sec)    Wait Avg(ms)    % DB t

Oracle 12c的一些新等待事件

编辑手记:本文介绍12C中一些新的等待事件,大家有更多发现或者总结的欢迎留言或者在大讲堂群交流讨论. 作者简介:何剑敏  Oracle ACS华南区售后团队,首席技术工程师.多年从事第一线的数据库运维工作,有丰富项目经验.维护经验和调优经验,专注于数据库的整体运维. 今天用swingbench加载数据的时候,发现了一些之前没有看过的等待事件,列举一下: (1)LGWR worker group idle这是因为12c默认是以adaptive方式启用scalable lgwr,即会在自动的在 si

&quot;log file sync&quot;等待事件-2

"log file sync"有三个参数: P1 = buffer# P2 = 未使用 P3 = 未使用 buffer# 这个buffer编号(在日志缓冲区中)的所有改变必须刷新到磁盘,写操作的完成保证了交易COMMIT的执行,即使实例crash也会保证COMMIT.因此LGWR的等待就是刷新这个buffer#. 等待时间: 这种等待完全依赖于LGWR写出所有必要的redo块,确保完成后返回给用户session.等待时间包括了日志缓冲写操作和提交操作.等待的时候,每秒都会增加序列号.

&quot;log file sync&quot;等待事件-1

"log file sync"是等待事件中非常常见的一种,他排在AWR的top5中有时是正常情况,有时则需要格外注意.昨天也听了一次Oracle的网络研讨会,介绍的是AWR相关的分析,从中学习到最重要的一点,就是对于AWR报告中若干信息的判断不能独立地看,需要综合起来,一个参数值大,不一定代表有问题,也可能是正常的,需要具体问题具体分析,其实和日常生活是一样的,头疼,不一定是感冒,也可能是缺少睡眠. WAITEVENT: "log file sync" Refere

Oracle中常见的33个等待事件小结

在Oracle 10g中的等待事件有872个,11g中等待事件1116个. 我们可以通过v$event_name 视图来查看等待事件的相关信息   一. 等待事件的相关知识 1.1 等待事件主要可以分为两类,即空闲(IDLE)等待事件和非空闲(NON-IDLE)等待事件. 1). 空闲等待事件指ORACLE正等待某种工作,在诊断和优化数据库的时候,不用过多注意这部分事件. 2). 非空闲等待事件专门针对ORACLE的活动,指数据库任务或应用运行过程中发生的等待,这些等待事件 是在调整数据库的时候

【等待事件之二】log 相关的等待

SQL> select * from v$version; BANNER                                                                           -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.1.0.6.0

oracle等待事件11——重做缓冲区上的等待事件

1.latch:redo writing  , latch :redo allocation  ,latch:redo copy oracle 为了保护将重做记录复制到重做缓冲区的一连串过程,使用以下三个锁存器: 1)rodo writing 锁存器:为了占有重做缓冲区内的空间,向LGWR请求写入工作的进程需要获得redo writing锁存器.因为LGWR的写入工作不能同时执行,所以自然在整个实例上只有一个.redo writing锁存器是因为独立锁存器,所以可以通过v$latch_paren

Oracle OWI 等待事件历史视图及相关视图

    Oracle提供的等待事件视图使得我们可以获取指定session以及实例级别等待事件的详细信息,这些视图分别是v$session_wait,v$session_event,以及v$system_event.然而这几个视图对于历史等待事件无能为力.对此,Oracle也提供了历史等待事件视图v$session_wait_history,同时视图v$session_wait_class,v$system_wait_class也提供了基于等待类别的性能分析,下面是基于Oracle 10g对此展开

【等待事件】等待事件系列(1)--User I/O类型

[等待事件]等待事件系列(1)--User I/O类型 1  BLOG文档结构图     2  前言部分   2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ①  等待事件系列(1)--User I/O类型     Tips: ① 本文在ITpub(http://blog.itpub.net/26736162).博客园(http://www.cnblogs.com/lhrbest)和微信公众号(xiaomaim