SQL Server error log switching and viewing

Source: Internet
Author: User
Tags server error log

SQL Server logs and agent error days are usually automatically switched after the instance restarts, and if the instance has not been restarted for a long time, it may accumulate too many logs and is inconvenient to view.




Log switchover: (Requires permission: Member of the sysadmin fixed server role)

--"SQL Server log" toggle exec msdb.dbo.sp_cycle_errorlog--"Agent error log" toggle exec Msdb.dbo.sp_cycle_agent_errorlog

Log View:

--Log view exec Xp_readerrorlog @FileNum, @Type, @SearchText1, @SearchText2, @StartTime, @EndTime, @order @filenum: Log number @Type : Query type (1:sql Server log; 2: Agent error log) @SearchText1: Search text @searchtext2: Search text (with @SearchText1 for "and" relationship) @StartTime: Log query start time @start Time: Log query end @order: Time sort (ASC or DESC)

Example:

--View current "SQL Server log" deadlock exec xp_readerrorlog 0,1, ' deadlock victim ', NULL, ' 2015-06-01 ', ' 2015-06-30 ', ' desc '  --View second "SQL Server Log" text has "error" and "Server" row exec xp_readerrorlog, ' Error ', ' Server ', ' 2015-06-01 ', ' 2015-06-30 ', ' ASC '  --View the current "Agent error Log" text with "error" in the line exec Xp_readerrorlog 0, 2, ' Error ', null,null,null, ' desc '  



SQL Server error log switching and viewing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.