zoukankan      html  css  js  c++  java
  • sqlserver日志提醒

     


     
    读取的日志文件来自安装目录下:MSSQLLogERRORLOG
    
    --This will hold the rows
    CREATE TABLE #ErrorLog (LogDate datetime, ProcessInfo VarChar(10), ErrorMessage VarChar(Max))
    
    -- Dump the errorlog into the table
    INSERT INTO #ErrorLog
    EXEC master.dbo.xp_readerrorlog
    
    -- Delete everything older than 5 minutes
    -- ideally you will store the max date when it ran last
    DELETE #ErrorLog
    WHERE LogDate <  DATEADD(mi,-5,GETDATE())
    
    -- Some stuff you want to check for
    -- Failed backups...you want to know this
    SELECT * FROM #ErrorLog
    WHERE ErrorMessage LIKE'BACKUP failed%'
    
    -- Why does it take so looong to grow a file, maybe rethink your settings
    SELECT * FROM #ErrorLog
    WHERE ErrorMessage LIKE'Autogrow of file%'
    
    -- What is going on any backups or statistic updates running at this time?
    SELECT * FROM #ErrorLog
    WHERE ErrorMessage LIKE'SQL Server has encountered %occurrence(s) of I/O requests taking longer than%'
    
    -- My mirror might not be up to date
    SELECT * FROM #ErrorLog
    WHERE ErrorMessage LIKE'The alert for ''unsent log'' has been raised%'
    
    DROP TABLE #ErrorLog
    
    清除日志:Exec sp_cycle_errorlog,执行当前ERRORLOG 重命名为ERRORLOG.1
    
    Exec xp_readerrorlog 2,1,Null,Null,'20130415 08:10','20130415 12:30','Asc'
    GO
    parameters:
      1.Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc... 
      2.Log file type: 1 or NULL = error log, 2 = SQL Agent log 
      3.Search string 1: String one you want to search for 
      4.Search string 2: String two you want to search for to further refine the results
      5.Search the start time
      6.Search the end time
      7.Sort order for results: N'asc' = ascending, N'desc' = descending
  • 相关阅读:
    C++ 面向对象编程3 封装 继承 多态
    C++ 面向对象编程2
    C++ 面向对象编程1
    C++开发环境和基础语法
    RTOS概述
    STM32F4 窗口看门狗(WWDG)
    STM32F407 独立看门狗 (IWDG)
    DHT11温湿度传感器
    Ubuntu20.04安装、配置、卸载QT5.9.9与QT creator以及第一个编写QT程序
    Linux,Ubuntu20.04LTS环境下安装JDK1.8和IDEA2021
  • 原文地址:https://www.cnblogs.com/heqianjin/p/5698637.html
Copyright © 2011-2022 走看看