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

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:
-- 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 
相关实践学习
通过日志服务实现云资源OSS的安全审计
本实验介绍如何通过日志服务实现云资源OSS的安全审计。
相关文章
|
5月前
|
监控 安全 BI
防火墙事件日志及日志分析
在网络安全防护体系中,防火墙作为抵御外部威胁的第一道防线,其重要性不言而喻。而对防火墙日志进行分析,更是深入了解网络流量、发现潜在安全风险的关键手段。
323 1
|
11月前
|
Java Shell
「sh脚步模版自取」测试线排查的三个脚本:启动、停止、重启、日志保存
「sh脚步模版自取」测试线排查的三个脚本:启动、停止、重启、日志保存
160 1
|
8月前
|
监控 Oracle 关系型数据库
Mysql、Oracle审计日志的开启
通过上述步骤,可以在 MySQL 和 Oracle 数据库中启用和配置审计日志。这些日志对于监控数据库操作、提高安全性和满足合规性要求非常重要。确保正确配置审计参数和策略,定期查看和分析审计日志,有助于及时发现并处理潜在的安全问题。
425 11
|
10月前
|
SQL Oracle 关系型数据库
【赵渝强老师】Oracle的控制文件与归档日志文件
本文介绍了Oracle数据库中的控制文件和归档日志文件。控制文件记录了数据库的物理结构信息,如数据库名、数据文件和联机日志文件的位置等。为了保护数据库,通常会进行控制文件的多路复用。归档日志文件是联机重做日志文件的副本,用于记录数据库的变更历史。文章还提供了相关SQL语句,帮助查看和设置数据库的日志模式。
233 1
【赵渝强老师】Oracle的控制文件与归档日志文件
|
9月前
|
缓存 安全 网络协议
使用事件日志识别常见 Windows 错误
事件查看器是Windows操作系统中的标准诊断工具,用于记录系统事件,包括硬件问题、软件中断和系统行为等详细信息。通过分析这些日志,管理员能够追踪和解决系统错误。访问方法包括使用快捷键Win + R输入eventvwr.msc,或通过控制面板进入。事件查看器中的每条记录包含事件ID、来源和描述,帮助识别和解决问题。常见错误如蓝屏死机、DLL错误、驱动程序错误等,可通过更新驱动程序、运行系统诊断、使用恢复功能等方式解决。
560 4
|
9月前
|
存储 监控 安全
什么是事件日志管理系统?事件日志管理系统有哪些用处?
事件日志管理系统是IT安全的重要工具,用于集中收集、分析和解释来自组织IT基础设施各组件的事件日志,如防火墙、路由器、交换机等,帮助提升网络安全、实现主动威胁检测和促进合规性。系统支持多种日志类型,包括Windows事件日志、Syslog日志和应用程序日志,通过实时监测、告警及可视化分析,为企业提供强大的安全保障。然而,实施过程中也面临数据量大、日志管理和分析复杂等挑战。EventLog Analyzer作为一款高效工具,不仅提供实时监测与告警、可视化分析和报告功能,还支持多种合规性报告,帮助企业克服挑战,提升网络安全水平。
302 2
|
10月前
|
监控 数据挖掘 数据安全/隐私保护
Python脚本:自动化下载视频的日志记录
Python脚本:自动化下载视频的日志记录
|
10月前
|
Oracle 关系型数据库 数据库
【赵渝强老师】Oracle的参数文件与告警日志文件
本文介绍了Oracle数据库的参数文件和告警日志文件。参数文件分为初始化参数文件(PFile)和服务器端参数文件(SPFile),在数据库启动时读取并分配资源。告警日志文件记录了数据库的重要活动、错误和警告信息,帮助诊断问题。文中还提供了相关视频讲解和示例代码。
218 1
|
10月前
|
SQL Oracle 关系型数据库
【赵渝强老师】Oracle的联机重做日志文件与数据写入过程
在Oracle数据库中,联机重做日志文件记录了数据库的变化,用于实例恢复。每个数据库有多组联机重做日志,每组建议至少有两个成员。通过SQL语句可查看日志文件信息。视频讲解和示意图进一步解释了这一过程。
149 0
|
12月前
|
缓存 监控 算法
分析慢日志文件来优化 PHP 脚本的性能
分析慢日志文件来优化 PHP 脚本的性能

推荐镜像

更多