{"id":4482,"date":"2015-03-18T12:13:40","date_gmt":"2015-03-18T19:13:40","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/paul\/?p=4482"},"modified":"2015-03-23T12:46:11","modified_gmt":"2015-03-23T19:46:11","slug":"incomplete-checkpoints-and-recovery","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/","title":{"rendered":"Incomplete checkpoints and recovery"},"content":{"rendered":"<p>Back in 2009 I blogged about how checkpoints work (see <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/how-do-checkpoints-work-and-what-gets-logged\/\" target=\"_blank\">How do checkpoints work and what gets logged<\/a>) and I received a question in email on Monday that I thought would make a good little blog post.<\/p>\n<p>The question is (paraphrased): <em>What happens if a checkpoint starts but doesn&#8217;t finish before a crash occurs? Will that checkpoint be used for crash recovery?<\/em><\/p>\n<p>The answer is no, it won&#8217;t. Now if I left it at that, that really would be a little blog post, so let me explain my answer :-)<\/p>\n<p>The purpose of a checkpoint is to bring the pages in the data files up-to-date with what&#8217;s in the transaction log. When a checkpoint ends, there&#8217;s a guarantee that as of the LSN of the <em>LOP_BEGIN_CKPT <\/em>log record, all changes from log records before that point are persisted in the data files on disk. There&#8217;s no guarantee about logged changes after that point, only before it. In other words, all the log records before the LSN of the <em>LOP_BEGIN_CKPT<\/em> log record are no longer required for crash recovery, unless there&#8217;s a long running transaction that started before that LSN.<\/p>\n<p>When the checkpoint ends, the boot page of the database (page 9 in file 1 &#8211; see <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/search-engine-qa-20-boot-pages-and-boot-page-corruption\/\" target=\"_blank\">here<\/a> for some more info) is updated with the beginning LSN of the checkpoint (and then if in the SIMPLE recovery mode, any log clearing\/truncating can occur).<\/p>\n<p>So if a checkpoint started but didn&#8217;t end before a crash, it&#8217;s LSN would not be in the boot page and so crash recovery would start from the previous checkpoint. This is good, because an incomplete checkpoint means there&#8217;s no guarantee about which logged changes are persisted in the data files, and so crash recovery wouldn&#8217;t be able to work correctly from only starting at the beginning of the incomplete checkpoint.<\/p>\n<p>A corollary question could be: <em>How does SQL Server guarantee that there&#8217;s always one complete checkpoint in the active portion of the log, in case a crash occurs?<\/em><\/p>\n<p>The answer is that log clearing\/truncation of a VLF containing an <em>LOP_BEGIN_CKPT<\/em> log record cannot happen\u00a0until another complete checkpoint has occurred. In other words, a complete checkpoint has to occur since the last log clearing\/truncation before the next one can happen. If a checkpoint hasn&#8217;t occurred, the <em>log_reuse_wait_desc<\/em> for the database in <em>sys.databases<\/em> will return <em>CHECKPOINT<\/em>. It&#8217;s not common to see this occur, but you might see it if there&#8217;s a very long running checkpoint (e.g. a very large update on a system with a slow I\/O subsystem so the flushing of data file pages takes a long time) and very frequent log backups, so two log backups occur over the time taken by\u00a0a single checkpoint operation. It could also happen if you&#8217;ve messed with the <em>sp_configure<\/em> recovery interval and set it higher than the default.<\/p>\n<p>Interesting, eh?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in 2009 I blogged about how checkpoints work (see How do checkpoints work and what gets logged) and I received a question in email on Monday that I thought would make a good little blog post. The question is (paraphrased): What happens if a checkpoint starts but doesn&#8217;t finish before a crash occurs? Will [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,48,62,98],"tags":[],"class_list":["post-4482","post","type-post","status-publish","format-standard","hentry","category-checkpoint","category-inside-the-storage-engine","category-on-disk-structures","category-transaction-log"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Incomplete checkpoints and recovery - 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\/incomplete-checkpoints-and-recovery\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Incomplete checkpoints and recovery - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"Back in 2009 I blogged about how checkpoints work (see How do checkpoints work and what gets logged) and I received a question in email on Monday that I thought would make a good little blog post. The question is (paraphrased): What happens if a checkpoint starts but doesn&#8217;t finish before a crash occurs? Will [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2015-03-18T19:13:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-03-23T19:46:11+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=\"2 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\/incomplete-checkpoints-and-recovery\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/\",\"name\":\"Incomplete checkpoints and recovery - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2015-03-18T19:13:40+00:00\",\"dateModified\":\"2015-03-23T19:46:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Incomplete checkpoints and recovery\"}]},{\"@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":"Incomplete checkpoints and recovery - 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\/incomplete-checkpoints-and-recovery\/","og_locale":"en_US","og_type":"article","og_title":"Incomplete checkpoints and recovery - Paul S. Randal","og_description":"Back in 2009 I blogged about how checkpoints work (see How do checkpoints work and what gets logged) and I received a question in email on Monday that I thought would make a good little blog post. The question is (paraphrased): What happens if a checkpoint starts but doesn&#8217;t finish before a crash occurs? Will [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/","og_site_name":"Paul S. Randal","article_published_time":"2015-03-18T19:13:40+00:00","article_modified_time":"2015-03-23T19:46:11+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/","name":"Incomplete checkpoints and recovery - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2015-03-18T19:13:40+00:00","dateModified":"2015-03-23T19:46:11+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/incomplete-checkpoints-and-recovery\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Incomplete checkpoints and recovery"}]},{"@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\/4482","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=4482"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/4482\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=4482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=4482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=4482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}