{"id":863,"date":"2009-05-12T20:36:00","date_gmt":"2009-05-12T20:36:00","guid":{"rendered":"\/blogs\/paul\/post\/A-sad-tale-of-mis-steps-and-corruption-(from-today).aspx"},"modified":"2017-06-20T12:13:19","modified_gmt":"2017-06-20T19:13:19","slug":"a-sad-tale-of-mis-steps-and-corruption-from-today","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/","title":{"rendered":"A sad tale of mis-steps and corruption (from today)"},"content":{"rendered":"<p style=\"text-align: justify;\">This is a true story, and unfolded over the last few days.\u00a0It&#8217;s deliberately written this way, I&#8217;m not trying to be patronizing &#8211; just illustrating the mistakes people can make if they don&#8217;t know what not to do.<\/p>\n<p style=\"text-align: justify;\">Once upon a time (well, a few days ago), there was a security person who had access to a SQL Server 2000 instance. He saw that the server had run out of disk space, but had no SQL server knowledge. He decided that\u00a0the best thing to do was to delete the log file, instead of contact the real DBA to take corrective action. This person should not have had any access to SQL Server, or the ability to delete the log. Nevertheless, the log was deleted. And then the database became suspect. Eventually, with no other option, someone\u00a0decided to create a new transaction log file using <em>DBCC REBUILD_LOG<\/em>. This was the right thing to do. The database wasn&#8217;t being backed up so restore wasn&#8217;t an option. Some of the details of who did what are unclear, as it so often the case. Needless to say, the real DBA was kept in the dark.<\/p>\n<p style=\"text-align: justify;\">Unfortunately,\u00a0whoever rebuilt the log\u00a0didn&#8217;t run <em>DBCC CHECKDB<\/em> afterwards to find out what corruption had been caused in the database by\u00a0having the transaction log unceremoniously ripped out from under the database&#8217;s feet. Rebuilding a transaction log is one of the worst things that can happen to a database, as all active transactions are thrown away, with no chance of rolling back. This leaves the database in a transactionally inconsistent, and potentially structurally inconsistent state (see <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-last-resorts-that-people-try-first\/\">Corruption: Last resorts that people try first&#8230;<\/a><\/em>\u00a0filed under my <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/category\/bad-advice\/\">Bad Advice<\/a> category, and Q4 from <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/technet-magazine-february-2009-sql-qa-column\/\">TechNet Magazine: February 2009 SQL Q&amp;A column<\/a>: <em>Is it ever safe to rebuild a transaction log?<\/em>).<\/p>\n<p style=\"text-align: justify;\">Instead they carried on running. The real DBA thought everything was cool and even upgraded the instance from SQL 2000 to SQL 2005. To be honest, after seeing the 19000+ corruptions they had in the database, I&#8217;m surprised that the database upgraded successfully. But it did. Then he tried to rebuild some indexes, which failed with corruption errors. Which brought us to this morning, when DBCC CHECKDB was run. It reported a lot of corruption, but running from SSMS only showed the first 1000 errors (which was the inspiration for one of my previous posts today <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/how-to-get-all-the-corruption-messages-from-checkdb\/\">How to get all the corruption messages from CHECKDB<\/a><\/em>. So they started to run <em>REPAIR_ALLOW_DATA_LOSS<\/em>, which will cause data loss &#8211; we chose the name of the repair option well. I got involved at this point, and saw from the list of errors that massive data loss would be the result.<\/p>\n<p style=\"text-align: justify;\">Once they had re-run <em>DBCC CHECKDB<\/em> through the command line (luckily only 20 minutes) I could see all the errors. And I must say I was astounded. It was the *worst* case of multiply-allocated extents (see <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/inside-the-storage-engine-anatomy-of-an-extent\/\">Inside the Storage Engine: Anatomy of an extent<\/a><\/em>) that I&#8217;ve ever seen. Not only were the extents allocated by multiple IAM pages (see <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/inside-the-storage-engine-iam-pages-iam-chains-and-allocation-units\/\">Inside the Storage Engine: IAM pages, IAM chains, and allocation units<\/a><\/em>) &#8211; in other words, two objects thought they had the same pages in the database allocated, but the two objects had actually each proceeded to overwrite the other&#8217;s updates in the pages &#8211; getting the two clustered indexes hopelessly interlinked. Lots of errors (1,000s)\u00a0like:<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nMsg 8904, Level 16, State 1, Server NAMESCHANGEDTOPROTECTTHEINNOCENT, Line 1\r\nExtent (1:9528) in database ID 5 is allocated by more than one allocation object.\r\n...\r\nMsg 8978, Level 16, State 1, Server NAMESCHANGEDTOPROTECTTHEINNOCENT, Line 1\r\nTable error: Object ID 1445580188, index ID 1, partition ID 376212519911424, alloc unit ID 94737543200768 (type In-row data). Page (1:52696) is missing a reference from previous page (1:427112). Possible chain linkage problem.\r\n...\r\nMsg 8977, Level 16, State 1, Server NAMESCHANGEDTOPROTECTTHEINNOCENT, Line 1\r\nTable error: Object ID 1445580188, index ID 1, partition ID 376212519911424, alloc unit ID 94737543200768 (type In-row data). Parent node for page (1:143210) was not encountered.\r\n...\r\nMsg 2533, Level 16, State 1, Server NAMESCHANGEDTOPROTECTTHEINNOCENT, Line 1\r\nTable error: page (1:405139) allocated to object ID 1445580188, index ID 1, partition ID 376212519911424, alloc unit ID 94737543200768 (type In-row data) was not seen. The page may be invalid or may have an incorrect alloc unit ID in its header.\r\n...\r\nCHECKDB found 1653 allocation errors and 17646 consistency errors in database 'NAMESCHANGEDTOPROTECTTHEINNOCENT'.\r\n<\/pre>\n<p style=\"text-align: justify;\">The repair for all of this? Delete it all and fix up the links. MASSIVE data loss.<\/p>\n<p style=\"text-align: justify;\">Lessons to learn from this:<\/p>\n<ul style=\"text-align: justify;\">\n<li>Don&#8217;t give people with no clue about\u00a0SQL Server access to SQL Server.<\/li>\n<li>Don&#8217;t delete a transaction log to reclaim space. Cardinal sin.<\/li>\n<li>Don&#8217;t rebuild a transaction log UNLESS you run a full <em>DBCC CHECKDB<\/em> afterwards and satisfy yourself that you know the extent of the damage.<\/li>\n<li>Don&#8217;t upgrade a database without running <em>DBCC CHECKDB<\/em> first. Best case &#8211; the upgrade fails. Worst case &#8211; it upgrades and then you might not be able to fix the corruptions.<\/li>\n<li>Don&#8217;t just run repair without doing a little analysis on the errors reported, especially with a *huge* number of errors reported.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Finally, I&#8217;m really grateful to the DBA in question for letting me help him out with this, and to post this blog post &#8211; we all learn from our own and others&#8217; mistakes.<\/p>\n<p style=\"text-align: justify;\">PS And I got involved in this from Twitter &#8211; I just *love* it. After initially being skeptical of how much time I&#8217;d spend on it, I&#8217;m finding the benefits of connecting to the SQL community in &#8216;real-time&#8217; vastly outweigh the time I&#8217;m putting into it. Follow me on <a href=\"https:\/\/twitter.com\/paulrandal\">http:\/\/twitter.com\/paulrandal<\/a> and you&#8217;ll see a bunch of other SQL MVPs on there too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a true story, and unfolded over the last few days.\u00a0It&#8217;s deliberately written this way, I&#8217;m not trying to be patronizing &#8211; just illustrating the mistakes people can make if they don&#8217;t know what not to do. Once upon a time (well, a few days ago), there was a security person who had access [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,30,31,34,35,52,74,98],"tags":[],"class_list":["post-863","post","type-post","status-publish","format-standard","hentry","category-bad-advice","category-corruption","category-database-maintenance","category-dbcc","category-disaster-recovery","category-involuntary-dba","category-repair","category-transaction-log"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A sad tale of mis-steps and corruption (from today) - Paul S. Randal<\/title>\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\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A sad tale of mis-steps and corruption (from today) - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"This is a true story, and unfolded over the last few days.\u00a0It&#8217;s deliberately written this way, I&#8217;m not trying to be patronizing &#8211; just illustrating the mistakes people can make if they don&#8217;t know what not to do. Once upon a time (well, a few days ago), there was a security person who had access [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2009-05-12T20:36:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-20T19:13:19+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/\",\"name\":\"A sad tale of mis-steps and corruption (from today) - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2009-05-12T20:36:00+00:00\",\"dateModified\":\"2017-06-20T19:13:19+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A sad tale of mis-steps and corruption (from today)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A sad tale of mis-steps and corruption (from today) - Paul S. Randal","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\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/","og_locale":"en_US","og_type":"article","og_title":"A sad tale of mis-steps and corruption (from today) - Paul S. Randal","og_description":"This is a true story, and unfolded over the last few days.\u00a0It&#8217;s deliberately written this way, I&#8217;m not trying to be patronizing &#8211; just illustrating the mistakes people can make if they don&#8217;t know what not to do. Once upon a time (well, a few days ago), there was a security person who had access [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/","og_site_name":"Paul S. Randal","article_published_time":"2009-05-12T20:36:00+00:00","article_modified_time":"2017-06-20T19:13:19+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/","name":"A sad tale of mis-steps and corruption (from today) - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2009-05-12T20:36:00+00:00","dateModified":"2017-06-20T19:13:19+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sad-tale-of-mis-steps-and-corruption-from-today\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"A sad tale of mis-steps and corruption (from today)"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=863"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/863\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}