{"id":874,"date":"2009-05-04T16:04:00","date_gmt":"2009-05-04T16:04:00","guid":{"rendered":"\/blogs\/paul\/post\/Do-transactions-rollback-when-DBCC-CHECKDB-runs.aspx"},"modified":"2013-05-20T15:10:58","modified_gmt":"2013-05-20T22:10:58","slug":"do-transactions-rollback-when-dbcc-checkdb-runs","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/","title":{"rendered":"Do transactions rollback when DBCC CHECKDB runs?"},"content":{"rendered":"<p><span style=\"font-family: verdana, geneva; font-size: small;\">Recently there&#8217;s been a spate of people noticing strange behavior from active transactions when <span style=\"font-family: 'courier new', courier;\">DBCC CHECKDB<\/span> (or any of the other <span style=\"font-family: 'comic sans ms', sand;\">DBCC<\/span> consistency checking commands run).<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">For example, I&#8217;ve create a database call <span style=\"font-family: 'courier new', courier;\">DbccTest<\/span> with a single table. In one connection I do:<\/span><\/p>\n<blockquote><p><span style=\"font-family: verdana, geneva; font-size: small;\"><span style=\"font-family: 'courier new', courier;\">BEGIN TRAN<br \/>\nINSERT INTO t1 VALUES (1, 1);<br \/>\nGO<br \/>\n<\/span><\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">And in another connection I do:<\/span><\/p>\n<blockquote><p><span style=\"font-family: verdana, geneva; font-size: small;\"><span style=\"font-family: 'courier new', courier;\">DBCC CHECKDB (DbccTest) WITH ALL_ERRORMSGS, NO_INFOMSGS;<br \/>\nGO<\/span>\u00a0<\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">Look what gets printed in the error log:<\/span><\/p>\n<blockquote><p><span style=\"font-family: 'courier new', courier; font-size: small;\">2009-05-04 16:03:21.55 spid54\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>1 transactions rolled back in database &#8216;DbccTest&#8217; (14)<\/strong>. This is an informational message only. No user action is required.<br \/>\n2009-05-04 16:03:21.91 spid54\u00a0\u00a0\u00a0\u00a0\u00a0 DBCC CHECKDB (DbccTest) WITH all_errormsgs, no_infomsgs executed by ROADRUNNERPR\\paul found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.<\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">I&#8217;ve highlighted the weird part in bold &#8211; it looks like crash recovery ran on the <span style=\"font-family: 'courier new', courier;\">DbccTest<\/span> database. What&#8217;s going on?<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">Well, crash recovery *DID* run on the <span style=\"font-family: 'courier new', courier;\">DbccTest<\/span> database &#8211; only it ran crash recovery into a hidden database snapshot. In the first part of the very long (well, 13 pages &#8211; not as long as the 70 page description in the 2008 internals book) post on how <span style=\"font-family: 'courier new', courier;\">DBCC CHECKDB<\/span> works (see <\/span><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/checkdb-from-every-angle-complete-description-of-all-checkdb-stages\/\"><span style=\"font-family: verdana, geneva; font-size: small;\">CHECKDB From Every Angle: Complete description of all CHECKDB stages<\/span><\/a><span style=\"font-family: verdana, geneva; font-size: small;\">), I explain why <span style=\"font-family: 'courier new', courier;\">DBCC CHECKDB<\/span> needs a transactionally-consistent, point-in-time view of the database to run consistency checks on. In 2005 I changed the code to use a database snapshot &#8211; which by it&#8217;s very nature provides a point-in-time, transactionally-consistent view of the database. When\u00a0a database snapshot is created on a database, the transaction log of that database is examined, and crash-recovery is run on it, but *into the database snapshot* &#8211; the source database is totally unaffected. The message in the error log is from <span style=\"font-family: 'courier new', courier;\">DBCC CHECKDB<\/span>&#8216;s hidden database snapshot starting up &#8211; but it&#8217;s pretty misleading, I must admit.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">The database ID in parentheses is the database ID of the database snapshot, not the actual database &#8211; further confusing things.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">One more twist to this behavior is that if there is a very long-running transaction in the database being consistency-checked, the database snapshot creation could take hours (because it has to wait for the long-running transaction to rollback, in the snapshot). If you think that the consistency check has hung, and try to kill it, you won&#8217;t be able to and the SPID will appear as if it&#8217;s in rollback. This is confusing because <span style=\"font-family: 'courier new', courier;\">DBCC CHECKB<\/span> doesn&#8217;t do anything &#8211; so shouldn&#8217;t have anything to rollback &#8211; but it&#8217;s the database snapshot creation that&#8217;s the problem. Once crash recovery has started on the database snapshot, it can&#8217;t be interrupted &#8211; so you have to wait for it to finish (and the database snapshot to be created) before the <span style=\"font-family: 'courier new', courier;\">DBCC<\/span> command will actually stop, and remove the database snapshot. It&#8217;s a weird side-effect, but a necessary one unfortunately. The recovery code could be changed to check for attention signals every so often I suppose, but I&#8217;m not holding-my-breath for that change.<\/span><\/p>\n<p><span style=\"font-size: small;\">Hope this helps.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently there&#8217;s been a spate of people noticing strange behavior from active transactions when DBCC CHECKDB (or any of the other DBCC consistency checking commands run). For example, I&#8217;ve create a database call DbccTest with a single table. In one connection I do: BEGIN TRAN INSERT INTO t1 VALUES (1, 1); GO And in another [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,31,33,34,52],"tags":[],"class_list":["post-874","post","type-post","status-publish","format-standard","hentry","category-checkdb-from-every-angle","category-database-maintenance","category-database-snapshots","category-dbcc","category-involuntary-dba"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Do transactions rollback when DBCC CHECKDB runs? - 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\/do-transactions-rollback-when-dbcc-checkdb-runs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Do transactions rollback when DBCC CHECKDB runs? - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"Recently there&#8217;s been a spate of people noticing strange behavior from active transactions when DBCC CHECKDB (or any of the other DBCC consistency checking commands run). For example, I&#8217;ve create a database call DbccTest with a single table. In one connection I do: BEGIN TRAN INSERT INTO t1 VALUES (1, 1); GO And in another [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2009-05-04T16:04:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-05-20T22:10:58+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\/do-transactions-rollback-when-dbcc-checkdb-runs\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/\",\"name\":\"Do transactions rollback when DBCC CHECKDB runs? - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2009-05-04T16:04:00+00:00\",\"dateModified\":\"2013-05-20T22:10:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Do transactions rollback when DBCC CHECKDB runs?\"}]},{\"@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":"Do transactions rollback when DBCC CHECKDB runs? - 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\/do-transactions-rollback-when-dbcc-checkdb-runs\/","og_locale":"en_US","og_type":"article","og_title":"Do transactions rollback when DBCC CHECKDB runs? - Paul S. Randal","og_description":"Recently there&#8217;s been a spate of people noticing strange behavior from active transactions when DBCC CHECKDB (or any of the other DBCC consistency checking commands run). For example, I&#8217;ve create a database call DbccTest with a single table. In one connection I do: BEGIN TRAN INSERT INTO t1 VALUES (1, 1); GO And in another [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/","og_site_name":"Paul S. Randal","article_published_time":"2009-05-04T16:04:00+00:00","article_modified_time":"2013-05-20T22:10:58+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\/do-transactions-rollback-when-dbcc-checkdb-runs\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/","name":"Do transactions rollback when DBCC CHECKDB runs? - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2009-05-04T16:04:00+00:00","dateModified":"2013-05-20T22:10:58+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/do-transactions-rollback-when-dbcc-checkdb-runs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Do transactions rollback when DBCC CHECKDB runs?"}]},{"@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\/874","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=874"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/874\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}