{"id":2383,"date":"2012-12-28T10:00:32","date_gmt":"2012-12-28T10:00:32","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=2383"},"modified":"2013-04-15T06:47:40","modified_gmt":"2013-04-15T06:47:40","slug":"sqlserver%e6%97%a5%e5%bf%97%e6%8f%90%e9%86%92","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2012\/12\/28\/sqlserver%e6%97%a5%e5%bf%97%e6%8f%90%e9%86%92\/","title":{"rendered":"sqlserver\u65e5\u5fd7\u63d0\u9192"},"content":{"rendered":"<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n\u8bfb\u53d6\u7684\u65e5\u5fd7\u6587\u4ef6\u6765\u81ea\u5b89\u88c5\u76ee\u5f55\u4e0b\uff1aMSSQL\\Log\\ERRORLOG\r\n\r\n--This will hold the rows\r\nCREATE TABLE #ErrorLog (LogDate datetime, ProcessInfo VarChar(10), ErrorMessage VarChar(Max))\r\n \r\n-- Dump the errorlog into the table\r\nINSERT INTO #ErrorLog\r\nEXEC master.dbo.xp_readerrorlog\r\n \r\n-- Delete everything older than 5 minutes\r\n-- ideally you will store the max date when it ran last\r\nDELETE #ErrorLog\r\nWHERE LogDate &lt;  DATEADD(mi,-5,GETDATE())\r\n \r\n-- Some stuff you want to check for\r\n-- Failed backups...you want to know this\r\nSELECT * FROM #ErrorLog\r\nWHERE ErrorMessage LIKE&#39;BACKUP failed%&#39;\r\n \r\n-- Why does it take so looong to grow a file, maybe rethink your settings\r\nSELECT * FROM #ErrorLog\r\nWHERE ErrorMessage LIKE&#39;Autogrow of file%&#39;\r\n \r\n-- What is going on any backups or statistic updates running at this time?\r\nSELECT * FROM #ErrorLog\r\nWHERE ErrorMessage LIKE&#39;SQL Server has encountered %occurrence(s) of I\/O requests taking longer than%&#39;\r\n \r\n-- My mirror might not be up to date\r\nSELECT * FROM #ErrorLog\r\nWHERE ErrorMessage LIKE&#39;The alert for &#39;&#39;unsent log&#39;&#39; has been raised%&#39;\r\n \r\n \r\nDROP TABLE #ErrorLog\r\n\r\n\u6e05\u9664\u65e5\u5fd7\uff1aExec sp_cycle_errorlog\uff0c\u6267\u884c\u5f53\u524dERRORLOG \u91cd\u547d\u540d\u4e3aERRORLOG.1\r\n\r\n<\/pre>\n<pre style=\"padding: 0px; width: 875.125px; margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; color: rgb(57, 57, 57); line-height: 18px;\">\r\n<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);\">Exec<\/span> xp_readerrorlog <span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(128, 0, 0); font-weight: bold;\">2<\/span>,<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(128, 0, 0); font-weight: bold;\">1<\/span>,<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);\">Null<\/span>,<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);\">Null<\/span>,<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">&#39;<\/span><span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">20130415 08:10<\/span><span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">&#39;<\/span>,<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">&#39;<\/span><span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">20130415 12:30<\/span><span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">&#39;<\/span>,<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">&#39;<\/span><span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">Asc<\/span><span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(255, 0, 0);\">&#39;<\/span>\r\n<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);\">GO\r\n<strong style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: medium;\">parameters:<\/span><\/strong>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 1.Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc...&nbsp;<\/span>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 2.Log file type: 1 or NULL = error log, 2 = SQL Agent log&nbsp;<\/span>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 3.Search string 1: String one you want to search for&nbsp;<\/span>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 4.Search string 2: String two you want to search for to further refine the results<\/span>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 5.Search the start time<\/span>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 6.Search the end time<\/span>\r\n<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">&nbsp; 7.Sort order for results: N&#39;asc&#39; = ascending, N&#39;desc&#39; = descending<\/span><\/span><\/pre>\n<p><\/p>\n<pre style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; color: rgb(57, 57, 57); line-height: 18px;\">\r\n<span style=\"margin: 0px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);\"><span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);\">\r\n\r\n<\/span><\/span><\/pre>\n<p>\u53c2\u8003\uff1a<a href=\"http:\/\/blogs.lessthandot.com\/index.php\/DataMgmt\/DBAdmin\/MSSQLServerAdmin\/proactive-notifications\">Proactive notifications<\/a> <a href=\"http:\/\/blogs.lessthandot.com\/index.php\/DataMgmt\/DBAdmin\/MSSQLServerAdmin\/proactive-deadlock-notifications\">\u6b7b\u9501\u63d0\u9192<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bfb\u53d6\u7684\u65e5\u5fd7\u6587\u4ef6\u6765\u81ea\u5b89\u88c5\u76ee\u5f55\u4e0b\uff1aMSSQL\\Log\\ERRORLOG &#8211;This will hold the  [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2383","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=2383"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2383\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=2383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=2383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=2383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}