{"id":818,"date":"2017-03-09T06:00:37","date_gmt":"2017-03-09T14:00:37","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/erin\/?p=818"},"modified":"2017-04-13T09:19:55","modified_gmt":"2017-04-13T16:19:55","slug":"sqlskills-101-the-sql-server-errorlog","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/","title":{"rendered":"SQLskills SQL101: The SQL Server ERRORLOG"},"content":{"rendered":"<p>One of the most useful logs you can review when there\u2019s a problem in SQL Server is the ERRORLOG.\u00a0 It may not always be the answer to your problem, but it\u2019s a good place to start.<\/p>\n<p>When you initially install SQL Server it only keeps the most recent six (6) ERRORLOG files, in addition to the current, active one.\u00a0 A new ERRORLOG file is generated when the instance restarts, or when you run <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/ms182512(v=sql.110).aspx\">sp_cycle_errorlog<\/a>.\u00a0 There are drawbacks to this default configuration.\u00a0 If you do not regularly restart your instance (which is perfectly fine), then one ERRORLOG file could contain months, maybe even a year or more, of information.\u00a0 That\u2019s a lot of entries to read through if you\u2019re looking for patterns or unusual errors.\u00a0 In addition, if you happen to run into a scenario where you restart the instance multiple times in succession \u2013 three or four times for example \u2013 you could potentially lose months of history.<\/p>\n<p>The solution is to recycle the ERRORLOG on a regular basis (I like to do this weekly), and increase the number of files retained.\u00a0 To recycle the ERRORLOG every week, set up an Agent job that calls sp_cycle_errorlog.\u00a0 I\u2019ve included code at the end of this post to create the Agent job and weekly schedule.<\/p>\n<p>Next, increase the number of ERRORLOG files you keep.\u00a0 You can do this through Management Studio.\u00a0 Expand the instance, then <strong>Management<\/strong>, right-click on <strong>SQL Server Logs<\/strong> and select <strong>Configure<\/strong>.\u00a0 Enable the option <strong>Limit the number of error log files before they are recycled<\/strong> and then enter a number for <strong>Maximum number of error log files:<\/strong>\u00a0 I like to keep 30 around.\u00a0 That usually equates to about six months of time, including a few unplanned restarts.<\/p>\n<figure id=\"attachment_819\" aria-describedby=\"caption-attachment-819\" style=\"width: 625px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2017\/03\/errorlog.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-819\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2017\/03\/errorlog.jpg\" alt=\"Configure SQL Server to keep 30 ERRORLOG files\" width=\"625\" height=\"258\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2017\/03\/errorlog.jpg 625w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2017\/03\/errorlog-300x124.jpg 300w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/a><figcaption id=\"caption-attachment-819\" class=\"wp-caption-text\">Configure SQL Server to keep 30 ERRORLOG files<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>You can also make this change with T-SQL:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nUSE &#x5B;master];\r\nGO\r\nEXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\\Microsoft\\MSSQLServer\\MSSQLServer', N'NumErrorLogs', REG_DWORD, 30;\r\nGO\r\n<\/pre>\n<p>Checking the ERRORLOG configuration is always something we do as part of a health audit, and I\u2019m always happy when I find systems with at least a few months\u2019 worth of files that are less than a few MB in size (I think the largest ERRORLOG I\u2019ve seen is 4GB&#8230;that one took a long time to open).\u00a0 If this isn\u2019t something you\u2019ve configured on your SQL Server instances yet, take a few minutes and knock it out.\u00a0 You won\u2019t regret having this information when a problem comes up, or when you\u2019re looking to see if a problem occurred a few months ago but maybe no one realized it.<\/p>\n<p>If you\u2019re interested in other posts in our <strong>SQLskills SQL101<\/strong> series, check out <a href=\"https:\/\/www.SQLskills.com\/help\/sql101\">SQLskills.com\/help\/SQL101.<\/a><\/p>\n<p>Additional reading:<\/p>\n<ul>\n<li><a href=\"http:\/\/sqlblog.com\/blogs\/jonathan_kehayias\/archive\/2010\/03\/03\/setting-sql-server-errorlog-retention-and-rollover-with-powershell.aspx\" class=\"broken_link\">Setting SQL Server ErrorLog Retention and Rollover with Powershell <\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Code to create a SQL Agent job to run sp_cycle_errorlog weekly (Sundays at 12:01 AM):<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nUSE &#x5B;msdb];\r\nGO\r\n\/****** Object:\u00a0 Job &#x5B;SQLskills Cycle ERRORLOG Weekly] ******\/\r\nBEGIN TRANSACTION\r\nDECLARE @ReturnCode INT\r\nSELECT @ReturnCode = 0\r\n\/****** Object:\u00a0 JobCategory &#x5B;Database Maintenance] ******\/\r\nIF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Maintenance' AND category_class=1)\r\nBEGIN\r\nEXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Maintenance'\r\nIF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback\r\nEND\r\nDECLARE @jobId BINARY(16)\r\nEXEC @ReturnCode =\u00a0 msdb.dbo.sp_add_job @job_name=N'SQLskills Cycle ERRORLOG Weekly',\r\n@enabled=1,\r\n@notify_level_eventlog=0,\r\n@notify_level_email=0,\r\n@notify_level_netsend=0,\r\n@notify_level_page=0,\r\n@delete_level=0,\r\n@description=N'Cycle the ERRORLOG once a week.',\r\n@category_name=N'Database Maintenance',\r\n@owner_login_name=N'sa', @job_id = @jobId OUTPUT\r\nIF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback\r\n\/****** Object:\u00a0 Step &#x5B;Cycle ERRORLOG] PM ******\/\r\nEXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Cycle ERRORLOG',\r\n@step_id=1,\r\n@cmdexec_success_code=0,\r\n@on_success_action=1,\r\n@on_success_step_id=0,\r\n@on_fail_action=2,\r\n@on_fail_step_id=0,\r\n@retry_attempts=0,\r\n@retry_interval=0,\r\n@os_run_priority=0, @subsystem=N'TSQL',\r\n@command=N'EXEC sp_cycle_errorlog;\r\nGO',\r\n@database_name=N'msdb',\r\n@flags=0\r\nIF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback\r\nEXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1\r\nIF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback\r\nEXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Weekly cycle of ERRORLOG',\r\n@enabled=1,\r\n@freq_type=8,\r\n@freq_interval=1,\r\n@freq_subday_type=1,\r\n@freq_subday_interval=0,\r\n@freq_relative_interval=0,\r\n@freq_recurrence_factor=1,\r\n@active_start_date=20170301,\r\n@active_end_date=99991231,\r\n@active_start_time=100,\r\n@active_end_time=235959,\r\n@schedule_uid=N'23a32e3e-c803-451f-b85a-b77d5b97ab3a'\r\nIF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback\r\nEXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'\r\nIF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback\r\nCOMMIT TRANSACTION\r\nGOTO EndSave\r\nQuitWithRollback:\r\nIF (@@TRANCOUNT &gt; 0) ROLLBACK TRANSACTION\r\nEndSave:\r\nGO\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most useful logs you can review when there\u2019s a problem in SQL Server is the ERRORLOG.\u00a0 It may not always be the answer to your problem, but it\u2019s a good place to start. When you initially install SQL Server it only keeps the most recent six (6) ERRORLOG files, in addition to [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45,47],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQLskills SQL101: The SQL Server ERRORLOG - Erin Stellato<\/title>\n<meta name=\"description\" content=\"The SQL Server ERRORLOG default configuration is not ideal for most installations - this post shows how to change it to provide what you need down the road.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQLskills SQL101: The SQL Server ERRORLOG - Erin Stellato\" \/>\n<meta property=\"og:description\" content=\"The SQL Server ERRORLOG default configuration is not ideal for most installations - this post shows how to change it to provide what you need down the road.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/\" \/>\n<meta property=\"og:site_name\" content=\"Erin Stellato\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-09T14:00:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T16:19:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2017\/03\/errorlog.jpg\" \/>\n<meta name=\"author\" content=\"Erin Stellato\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Erin Stellato\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/\",\"name\":\"SQLskills SQL101: The SQL Server ERRORLOG - Erin Stellato\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\"},\"datePublished\":\"2017-03-09T14:00:37+00:00\",\"dateModified\":\"2017-04-13T16:19:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\"},\"description\":\"The SQL Server ERRORLOG default configuration is not ideal for most installations - this post shows how to change it to provide what you need down the road.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQLskills SQL101: The SQL Server ERRORLOG\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\",\"name\":\"Erin Stellato\",\"description\":\"The SQL Sequel\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\",\"name\":\"Erin Stellato\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g\",\"caption\":\"Erin Stellato\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/erin\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/author\/erin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQLskills SQL101: The SQL Server ERRORLOG - Erin Stellato","description":"The SQL Server ERRORLOG default configuration is not ideal for most installations - this post shows how to change it to provide what you need down the road.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/","og_locale":"en_US","og_type":"article","og_title":"SQLskills SQL101: The SQL Server ERRORLOG - Erin Stellato","og_description":"The SQL Server ERRORLOG default configuration is not ideal for most installations - this post shows how to change it to provide what you need down the road.","og_url":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/","og_site_name":"Erin Stellato","article_published_time":"2017-03-09T14:00:37+00:00","article_modified_time":"2017-04-13T16:19:55+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2017\/03\/errorlog.jpg"}],"author":"Erin Stellato","twitter_misc":{"Written by":"Erin Stellato","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/","name":"SQLskills SQL101: The SQL Server ERRORLOG - Erin Stellato","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website"},"datePublished":"2017-03-09T14:00:37+00:00","dateModified":"2017-04-13T16:19:55+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158"},"description":"The SQL Server ERRORLOG default configuration is not ideal for most installations - this post shows how to change it to provide what you need down the road.","breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/sqlskills-101-the-sql-server-errorlog\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/erin\/"},{"@type":"ListItem","position":2,"name":"SQLskills SQL101: The SQL Server ERRORLOG"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/","name":"Erin Stellato","description":"The SQL Sequel","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/erin\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158","name":"Erin Stellato","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g","caption":"Erin Stellato"},"sameAs":["http:\/\/3.209.169.194\/blogs\/erin"],"url":"https:\/\/www.sqlskills.com\/blogs\/erin\/author\/erin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/818"}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/comments?post=818"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/818\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/media?parent=818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/categories?post=818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/tags?post=818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}