精华内容
下载资源
问答
  • log file switch and log file sync

    千次阅读 2013-09-22 20:42:26
    10.3.15 log file switch There are two wait events commonly encountered: log file switch (archiving needed) log file switch (checkpoint incomplete) In both of the events, the LGWR is ...
    
    

    10.3.15 log file switch

    There are two wait events commonly encountered:

    • log file switch (archiving needed)

    • log file switch (checkpoint incomplete)

    In both of the events, the LGWR is unable to switch into the next online redo log, and all the commit requests wait for this event.

    10.3.15.1 Actions

    For the log file switch (archiving needed) event, examine why the archiver is unable to archive the logs in a timely fashion. It could be due to the following:

    • Archive destination is running out of free space.

    • Archiver is not able to read redo logs fast enough (contention with the LGWR).

    • Archiver is not able to write fast enough (contention on the archive destination, or not enough ARCH processes). If you have ruled out other possibilities (such as slow disks or a full archive destination) consider increasing the number of ARCn processes. The default is 2.

    • If you have mandatory remote shipped archive logs, check whether this process is slowing down because of network delays or the write is not completing because of errors.

    Depending on the nature of bottleneck, you might need to redistribute I/O or add more space to the archive destination to alleviate the problem. For the logfile switch (checkpoint incomplete) event:

    • Check if DBWR is slow, possibly due to an overloaded or slow I/O system. Check the DBWR write times, check the I/O system, and distribute I/O if necessary. See Chapter 8, "I/O Configuration and Design".

    • Check if there are too few, or too small redo logs. If you have a few redo logs or small redo logs (for example two x 100k logs), and your system produces enough redo to cycle through all of the logs before DBWR has been able to complete the checkpoint, then increase the size or number of redo logs. See "Sizing Redo Log Files".

    10.3.16 log file sync

    When a user session commits (or rolls back), the session's redo information must be flushed to the redo logfile by LGWR. The server process performing theCOMMIT or ROLLBACK waits under this event for the write to the redo log to complete.

    Actions

    If this event's waits constitute a significant wait on the system or a significant amount of time waited by a user experiencing response time issues or on a system, then examine the average time waited.

    If the average time waited is low, but the number of waits are high, then the application might be committing after every INSERT, rather than batching COMMITs. Applications can reduce the wait by committing after 50 rows, rather than every row.

    If the average time waited is high, then examine the session waits for the log writer and see what it is spending most of its time doing and waiting for. If the waits are because of slow I/O, then try the following:

    • Reduce other I/O activity on the disks containing the redo logs, or use dedicated disks.

    • Alternate redo logs on different disks to minimize the effect of the archiver on the log writer.

    • Move the redo logs to faster disks or a faster I/O subsystem (for example, switch from RAID 5 to RAID 1).

    • Consider using raw devices (or simulated raw devices provided by disk vendors) to speed up the writes.

    • Depending on the type of application, it might be possible to batch COMMITs by committing every N rows, rather than every row, so that fewer log file syncs are needed.

    展开全文
  • muduo之LogFile

    千次阅读 2019-10-28 21:04:12
    muduo之LogFileLogFile是控制日志怎么和文件打交道,其中包含常用的对日志处理的一些操作。AsyncLogging异步日志需要调用LogFile的接口将日志写入文件,其中包含了AppendFile类,相当于再AppendFile上面封装了一层...

            muduo之LogFile,LogFile是控制日志怎么和文件打交道,其中包含常用的对日志处理的一些操作。AsyncLogging异步日志需要调用LogFile的接口将日志写入文件,其中包含了AppendFile类,相当于再AppendFile上面封装了一层。

    LogFile.h

    // Use of this source code is governed by a BSD-style license
    // that can be found in the License file.
    //
    // Author: Shuo Chen (chenshuo at chenshuo dot com)
    
    #ifndef MUDUO_BASE_LOGFILE_H
    #define MUDUO_BASE_LOGFILE_H
    
    #include "muduo/base/Mutex.h"
    #include "muduo/base/Types.h"
    
    #include <memory>
    
    namespace muduo
    {
    
    namespace FileUtil
    {
    class AppendFile;
    }
    
    //控制日志怎样和文件打交道
    class LogFile : noncopyable
    {
     public:
      LogFile(const string& basename,
              off_t rollSize,
              bool threadSafe = true,
              int flushInterval = 3,
              int checkEveryN = 1024);
      ~LogFile();
    
      void append(const char* logline, int len);
      void flush();
      bool rollFile();
    
     private:
      void append_unlocked(const char* logline, int len);			//不加锁的append方式
    
      static string getLogFileName(const string& basename, time_t* now);		  //获取日志文件的名称
    
      const string basename_;		//日志文件basename
      const off_t rollSize_;		//日志文件达到rolsize生成一个新文件
      const int flushInterval_;		//日志写入间隔时间
      const int checkEveryN_;	// 每调用checkEveryN_次日志写,就滚动一次日志
    
      int count_;					// 写入的次数
    
      std::unique_ptr<MutexLock> mutex_;	//加锁
      time_t startOfPeriod_;				//开始记录日志时间
      time_t lastRoll_;						//上一次滚动日志文件时间
      time_t lastFlush_;					//上一次日志写入文件时间
      std::unique_ptr<FileUtil::AppendFile> file_;		//文件智能指针
    
      const static int kRollPerSeconds_ = 60*60*24;		//即时间一天
    };
    
    }  // namespace muduo
    #endif  // MUDUO_BASE_LOGFILE_H
    

    LogFile.cc

    // Use of this source code is governed by a BSD-style license
    // that can be found in the License file.
    //
    // Author: Shuo Chen (chenshuo at chenshuo dot com)
    
    #include "muduo/base/LogFile.h"
    
    #include "muduo/base/FileUtil.h"
    #include "muduo/base/ProcessInfo.h"
    
    #include <assert.h>
    #include <stdio.h>
    #include <time.h>
    
    using namespace muduo;
    
    控制日志怎样和文件打交道
    LogFile::LogFile(const string& basename,
                     off_t rollSize,
                     bool threadSafe,
                     int flushInterval,
                     int checkEveryN)
      : basename_(basename),
        rollSize_(rollSize),
        flushInterval_(flushInterval),
        checkEveryN_(checkEveryN),
        count_(0),
        mutex_(threadSafe ? new MutexLock : NULL),		//不是线程安全就不需要构造mutex_
        startOfPeriod_(0),
        lastRoll_(0),
        lastFlush_(0)
    {
      assert(basename.find('/') == string::npos);		//断言basename不包含'/'
      rollFile();
    }
    
    LogFile::~LogFile() = default;
    
    void LogFile::append(const char* logline, int len)
    {
      if (mutex_)
      {
        MutexLockGuard lock(*mutex_);
        append_unlocked(logline, len);
      }
      else
      {
        append_unlocked(logline, len);
      }
    }
    
    void LogFile::flush()
    {
      if (mutex_)
      {
        MutexLockGuard lock(*mutex_);
        file_->flush();
      }
      else
      {
        file_->flush();
      }
    }
    
    void LogFile::append_unlocked(const char* logline, int len)//不加锁的append方式
    {
      file_->append(logline, len);//AppendFile->append
    
      if (file_->writtenBytes() > rollSize_)
      {
        rollFile();
      }
      else
      {
        ++count_;
        if (count_ >= checkEveryN_)
        {
          count_ = 0;
          time_t now = ::time(NULL);
          time_t thisPeriod_ = now / kRollPerSeconds_ * kRollPerSeconds_;//比较事件是否相等,不等就是第二天0点,那么滚动
          if (thisPeriod_ != startOfPeriod_)
          {
            rollFile();
          }
          else if (now - lastFlush_ > flushInterval_)//判断是否超过flush间隔时间,超过了就flush,否则什么都不做
          {
            lastFlush_ = now;
            file_->flush();
          }
        }
      }
    }
    
    bool LogFile::rollFile()//滚动
    {
      time_t now = 0;
      string filename = getLogFileName(basename_, &now);获取生成一个文件名称
    
      //注意,这里先除KRollPerSeconds然后乘KPollPerSeconds表示对齐值KRollPerSeconds的整数倍,也就是事件调整到当天零点(/除法会引发取整)
      time_t start = now / kRollPerSeconds_ * kRollPerSeconds_;
    
      if (now > lastRoll_)
      {
        lastRoll_ = now;
        lastFlush_ = now;
        startOfPeriod_ = start;
        file_.reset(new FileUtil::AppendFile(filename));
        return true;
      }
      return false;
    }
    
    string LogFile::getLogFileName(const string& basename, time_t* now)//获取日志文件的名称
    {
      string filename;
      filename.reserve(basename.size() + 64);//预分配内存
      filename = basename;
    
      char timebuf[32];
      struct tm tm;
      *now = time(NULL);
      gmtime_r(now, &tm); // FIXME: localtime_r ?	//获取当前时间,UTC时间,_r是线程安全
      strftime(timebuf, sizeof timebuf, ".%Y%m%d-%H%M%S.", &tm);//格式化时间,strftime函数
      filename += timebuf;
    
      filename += ProcessInfo::hostname();
    
      char pidbuf[32];
      snprintf(pidbuf, sizeof pidbuf, ".%d", ProcessInfo::pid());
      filename += pidbuf;
    
      filename += ".log";
    
      return filename;
    }
    
    

     

    展开全文
  • log file switch completion,log file switch (archiving needed) log file switch (checkpoint incomplete) 这三个等待事件是没有参数的,在10g中,它位于configuration类下  SQL> select name,parameter1...

    log file switch completion,log file switch (archiving needed) log file switch (checkpoint incomplete)

    这三个等待事件是没有参数的,在10g中,它位于configuration类下 

    SQL> select name,parameter1,parameter2,parameter3,wait_class from v$event_name where name in( 'log file switch completion',
      2  'log file switch (checkpoint incomplete)','log file switch (archiving needed)');

    NAME                                          PARAMETER1 PARAMETER2 PARAMETER3 WAIT_CLASS
    --------------------------------------------- ---------- ---------- ---------- -------------------------------------------------------
    log file switch (checkpoint incomplete)                                        Configuration
    log file switch (archiving needed)                                             Configuration
    log file switch completion                                                     Configuration

    当这三个等待事件出现比较频繁,可能是由于事物繁忙,导致redo生成过快,日志文件过小造成的。

    这个时候可以考虑增大日志文件大小,增加日志文件组,删除以前过小的日志文件。

    另外

    log file switch (checkpoint incomplete)也有可能是dbwr写太慢,引起的,可能需要增加dbwr数量,调整I/O。

    log file switch (archiving needed) 这个等待事件也有可能是归档太慢,应该将归档日志存放在I/O快速的磁盘上,增加归档进程

    调整log_archive_max_processes归档进程。

     

    在日志切换的过程中,lgwr进程首先要关闭current日志组,然后打开下一个日志组,这个过程中任何DML操作都无法进行,直到切换完成。日志切换的时候需进行归档,checkpoint,如果归档慢,DBWR慢,必然导致前台业务等待,这个等待过程如果比较长,会导致用户响应缓慢,所以出现了上述三类等待事件,应该引起足够重视,Oracle推荐的日志切换事件一般是20分钟,当然在业务很繁忙的情况下日志切换比较频繁,可能几分钟就切换一次,如果没有引起log file switch 之类的等待事件,就不需要增大日志文件了,太大的日志文件可能导致损失过多的数据。

    展开全文
  • log buffer space log buffer space 等待事件表示某个进程等待日志缓冲区中的空间。不管是日志缓冲区过小,还是重做信息写产生过快。均使日志写入经常不能将其写入到重做日志缓冲区中。...log file switch log f

    log buffer space

    log buffer space 等待事件表示某个进程等待日志缓冲区中的空间。不管是日志缓冲区过小,还是重做信息写产生过快。均使日志写入经常不能将其写入到重做日志缓冲区中。查看log buffer大下。如果过小,适当增大size。如果log buffer已经足够大,则要考虑是否存在I/O争用


    log file switch

    log fileswitch 等待时间发生在由于一个日志文件一直没有归档而迫使一个会话等待日志文件切换的时候。这类等待事件也可能由于日志文件切换正等待某个检查点而产生。

    如果不是由于归档目标空间满了,则表示归档进程不能与重做日志归档的速度同步。在此情况下,可以增加ARCn来增加归档的速度。ARCn默认值为2  和dbwr一样 不能动态修改其值。

    还需要研究重做日志文件过小,导致频繁的日志文件切换等待。如果一个日志文件被阻止,等待一个检查点的完成,那么很显然是日志文件太小,很快就被填充满,进而需要切换日志文件。此时,可以通过增大日志文件大小 或者增加日志文件组 来缓解此类情况


    log file sync

    如果服务器进程经常等待日志写进程完成从日志缓冲区到重做日志文件的提交写事物,则将会产生log file sync等待事件。一般是由于过于频繁的提交产生的结果。可以使用批量提交而不是每个事物单个提交来缓解。 大量的 log file sync 会导致很多意想不到的连锁反应。因此需要特别关注。

    log file sync:一般此类等待事件是由于 LGWR 进程将redo log buffer 写入 redo log 中发生。如果此类事件频繁发生,可以判断为:
    1、commit 次数是否过多
    2、I/O 系统问题
    3、重做日志是否不必要被创建
    4、redo log buffer 是否过大

    展开全文
  •  When a user session commits, the session's redo information needs to be flushed to the redo logfile. The user session will post the LGWR to write the log buffer to the redo log fi
  • log4j.rootLogger=DEBUG,systemOut,logFile # log4j.appender.systemOut= org.apache.log4j.ConsoleAppender log4j.appender.systemOut.layout= org.apache.log4j.PatternLayout log4j.appender.systemOut....
  • 报错:Could not find first log file name in binary log index file 原因: 从机找不到日志文件 二. 解决方案 在从机上按ctrl+c结束当前进程,输入service mysql restart; 在主机上输入flush logs;,然后show ma....
  • 关于logfile sync

    2015-12-27 17:07:55
    1、Log File Sync是从提交开始到提交结束的时间。Log File Parallel Write是LGWR开始写Redo File到Redo File结束的时间。明确了这一点,可以知道,Log file sync 包含了log file parallel write。所以,log file ...
  • log file sync

    2014-06-02 19:06:50
    什么是log file sync等待事件呢?在一个提交(commit)十分频繁的数据库中,一般会出现log file sync等待事件,当这个等待事件出现在top5中, 这个时侯我们需要针对log file sync等待事件进行优化,一定要尽快分析并...
  • log file sync, log file parallell write

    千次阅读 2009-11-30 13:42:00
    SQL> select name,parameter1,parameter2,parameter3,wait_class from v$event_name where name in( log file sync,log file parallel write);NAME PARAMETER1 PARA
  • 关于v$log和v$logfile

    千次阅读 2017-12-29 11:48:55
    Oracle v$logfile v$log
  • 这是3月份某客户的情况,原因是server硬件故障后进行更换之后,业务翻译偶尔出现提交缓慢的情况。我们先来看下awr的情况。...从top 5event,我们能够发现,log file sync的avg wait很之高,高达124ms
  • 漫谈LOG FILE SYNC

    千次阅读 2017-02-09 19:12:02
    来新公司工作,很大的一段时间都在调优日志写,提升系统的TPS,在这方面也积累了一些理论知识和实践经验,之前零零散散在微博上也发了很多关于logfile sync的帖子,篇幅都很短,有些是自己优化系统过程中的一个心得...
  • log file sync(日志文件同步) 与 Log file parallel write 等待事件   log file sync(日志文件同步)等待事件具有一个参数:buffer#。在Oracle Database 10g中,这种等待事件位于Commit等待下面。当...
  • log file switch (archiving needed) SQL> select event#,name,parameter1,parameter2,parameter3 from v$event_name where name = 'log file switch (archiving needed)'; EVENT# NAME
  • InnoDB: Error: log file ./ib_logfile0 is of different size 0 xxxx bytes
  • ib_logfile与log-bin区别

    千次阅读 2017-09-06 10:54:40
    ib_logfile0 记录系统的回滚,重做日志。 mysql-bin.000011 系统的所有更新记录。 如果需要更详细的则建议看一下数据库原理方面的教材,应该有一个章节讲这个redo,undo 日志的。 ,ib_logfile0是重做日志,记录的...
  • log file parallel write事件

    千次阅读 2019-01-03 10:22:37
    它是一个后台等待事件,通常与IO不佳相关,它是log file sync事件的一个子过程。该等待事件共有3个参数:SQL> select PARAMETER1,PARAMETER2,PARAMETER3 from v$event_name where name='log file parallel write....
  • LOG FILE SYNC概述

    千次阅读 2015-05-04 10:23:00
    log file sycn是ORACLE里最普遍的等待事件之一,一般log file sycn的等待时间都非常短 1-5ms,不会有什么问题,但是一旦出问题,往往都比较难解决。什么时候会产生log file sync等待? 常见有以下几种: 1)...
  • MySQL误删ibdata1 ib_logfile0,ib_logfile1 恢复方法: 恢复的步骤和数据库版本没有太大关系。 在linux操作系统中,如果文件从操作系统级别别rm掉,之前打开的文件进程仍持有相应的文件句柄, 所指向的文件...
  • log4j.appender.LOGFILE.File=logs/wlanapi/client.log --- logs文件夹目录在apache-tomcat-6.0.36\bin\下 log4j.appender.LOGFILE.File=/logs/wlanapi/client.log---tomcat根目录下 log4j.appender.LOGFILE....
  • 在你修改my.cnf的innodb_log_file_size参数前,请先停止mysql服务程序的运行(mysql的停止没有出现任何错误),并把/var/lib/mysql目录下的ib_logfile0、ib_logfile1、ib_logfile2等之类的文件移除到一个安全的地方...
  • mysql ib_logfile分析

    千次阅读 2018-01-16 17:03:29
    mysql ib_logfile分析
  • sys@ORCL> select EVENT,TOTAL_WAITS,TIME_WAITED,TIME_WAITED_MICRO 2 from v$system_event 3 where event like '%log file%'; EVENT TOTAL_WAITS TIME_WAITED TIME_
  • 161104 10:11:54 InnoDB: Initializing buffer pool, size = 22.0G 161104 10:11:55 InnoDB: Completed initialization of buffer pool ...InnoDB: Error: log file ./ib_logfile2 is of different size 0 0 bytes I

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 195,748
精华内容 78,299
关键字:

logfile