{"id":4308,"date":"2014-02-13T09:49:09","date_gmt":"2014-02-13T17:49:09","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/paul\/?p=4308"},"modified":"2017-04-13T09:54:41","modified_gmt":"2017-04-13T16:54:41","slug":"corruption-recovery-using-dbcc-writepage","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/","title":{"rendered":"Corruption recovery using DBCC WRITEPAGE"},"content":{"rendered":"<p>A couple of week ago I kicked off a <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/survey-using-dbcc-writepage\/\" target=\"_blank\">survey<\/a> about the extent of your experience with the <em>DBCC WRITEPAGE<\/em> command. Here are the results:<\/p>\n<p><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4309\" alt=\"UsingWRITEPAGE\" src=\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg\" width=\"576\" height=\"334\" \/><\/a><\/p>\n<p>The &#8220;Other&#8221; values are:<\/p>\n<ul>\n<li>9 x &#8220;Read your post on it, may practice it one day, but it&#8217;ll always be last resort to use.&#8221;<\/li>\n<li>6 x &#8220;I read your post on it.&#8221;<\/li>\n<li>4 x &#8220;I know about it (from your posts\/immersion event) and it&#8217;s in my toolbox whenever I get called in to perform disaster recovery.&#8221;<\/li>\n<li>1 x &#8220;It&#8217;s like knowing the Unix recursive delete command as root, dangerous and powerful.&#8221;<\/li>\n<li>1 x &#8220;Not since 2k pages, and then PageEdit.exe was easier.&#8221;<\/li>\n<\/ul>\n<p>For those of you who don&#8217;t know what <em>DBCC WRITEPAGE<\/em> is, it&#8217;s an undocumented command that allows you to make direct changes to data file pages. It&#8217;s an extremely powerful command that is very useful for creating corrupt databases, and in extreme cases, for helping to repair otherwise irretrievably-corrupt databases. I blogged about it a year ago <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/dbcc-writepage\/\" target=\"_blank\">in this post<\/a>.<\/p>\n<p>I never advocate using it to repair a corrupt database and then continue using that database in production, and in fact I refuse to do that if a client asks as there are just too many potential problems that could occur. I&#8217;ll only ever use it to help recover data from a damaged database, where there&#8217;s already a copy of the databases files in existence, and the client has signed an agreement acknowledging that any data file I use it on is a duplicate, is not on a production instance, and changes to it will in no way affect production.<\/p>\n<p>There are all kinds of things I&#8217;ve used <em>DBCC WRITEPAGE<\/em> for to allow data recovery to progress, and in my <a href=\"http:\/\/www.pluralsight.com\/courses\/sqlserver-advanced-corruption-recovery-techniques\" target=\"_blank\">Advanced Corruption Recovery Techniques course<\/a> on Pluralsight course I demonstrate one of them, which I&#8217;m going to describe here.<\/p>\n<p>Imagine a database that&#8217;s suffered corruption and there&#8217;s an off-row LOB data value that&#8217;s inaccessible because the owning data row is corrupt. Your mission is to retrieve the data. And to make it impractical to manually piece together the value using <em>DBCC PAGE<\/em> dumps, the LOB value is a few megabytes, so it&#8217;s stored on hundreds of linked text pages.<\/p>\n<p>The process:<\/p>\n<ul>\n<li>Create another row with an off-row LOB value (the &#8216;dummy&#8217; row)<\/li>\n<li>Find out the dummy row&#8217;s page and offset on the page<\/li>\n<li>Calculate the offset of the dummy LOB value&#8217;s in-row root in the variable-length portion of the record<\/li>\n<li>Calculate the offset of the dummy LOB in-row root&#8217;s size, text timestamp, and pointer fields<\/li>\n<li>Find the corrupt row&#8217;s LOB in-row-root&#8217;s size, text timestamp, and pointer field values<\/li>\n<li>Use <em>DBCC WRITEPAGE<\/em> to overwrite the dummy LOB in-row root fields<\/li>\n<li>Select from the dummy row and you&#8217;ll get back the LOB value you wanted to save<\/li>\n<\/ul>\n<p>Cool, eh? Desperate times call for clever measures, and with procedures like this I regularly recover data from client databases that Microsoft and other data recovery firms either can&#8217;t help with or have given up on. It&#8217;s not a fast process as it can take quite a while to figure out exactly what to modify to make things work, but when the data comes back, the clients are always ecstatic.<\/p>\n<p>And with some knowledge of the data structures in a data file, careful use of <em>DBCC WRITEPAGE<\/em>, and plenty of practice, you can do it too.<\/p>\n<p>Or <a href=\"https:\/\/www.sqlskills.com\/services\/sql-server-disaster-recovery\/\" target=\"_blank\">call us<\/a> to help you :-)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of week ago I kicked off a survey about the extent of your experience with the DBCC WRITEPAGE command. Here are the results: The &#8220;Other&#8221; values are: 9 x &#8220;Read your post on it, may practice it one day, but it&#8217;ll always be last resort to use.&#8221; 6 x &#8220;I read your post [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,30,34,35],"tags":[],"class_list":["post-4308","post","type-post","status-publish","format-standard","hentry","category-consulting","category-corruption","category-dbcc","category-disaster-recovery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Corruption recovery using DBCC WRITEPAGE - 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\/corruption-recovery-using-dbcc-writepage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Corruption recovery using DBCC WRITEPAGE - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"A couple of week ago I kicked off a survey about the extent of your experience with the DBCC WRITEPAGE command. Here are the results: The &#8220;Other&#8221; values are: 9 x &#8220;Read your post on it, may practice it one day, but it&#8217;ll always be last resort to use.&#8221; 6 x &#8220;I read your post [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-13T17:49:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T16:54:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg\" \/>\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=\"3 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\/corruption-recovery-using-dbcc-writepage\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/\",\"name\":\"Corruption recovery using DBCC WRITEPAGE - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg\",\"datePublished\":\"2014-02-13T17:49:09+00:00\",\"dateModified\":\"2017-04-13T16:54:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#primaryimage\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg\",\"contentUrl\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Corruption recovery using DBCC WRITEPAGE\"}]},{\"@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":"Corruption recovery using DBCC WRITEPAGE - 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\/corruption-recovery-using-dbcc-writepage\/","og_locale":"en_US","og_type":"article","og_title":"Corruption recovery using DBCC WRITEPAGE - Paul S. Randal","og_description":"A couple of week ago I kicked off a survey about the extent of your experience with the DBCC WRITEPAGE command. Here are the results: The &#8220;Other&#8221; values are: 9 x &#8220;Read your post on it, may practice it one day, but it&#8217;ll always be last resort to use.&#8221; 6 x &#8220;I read your post [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/","og_site_name":"Paul S. Randal","article_published_time":"2014-02-13T17:49:09+00:00","article_modified_time":"2017-04-13T16:54:41+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg","type":"","width":"","height":""}],"author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/","name":"Corruption recovery using DBCC WRITEPAGE - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg","datePublished":"2014-02-13T17:49:09+00:00","dateModified":"2017-04-13T16:54:41+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#primaryimage","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg","contentUrl":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2014\/02\/usingwritepage.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/corruption-recovery-using-dbcc-writepage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Corruption recovery using DBCC WRITEPAGE"}]},{"@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\/4308","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=4308"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/4308\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=4308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=4308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=4308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}