{"id":848,"date":"2009-05-29T11:09:00","date_gmt":"2009-05-29T11:09:00","guid":{"rendered":"\/blogs\/paul\/post\/Misconceptions-around-the-log-and-log-backups-how-to-convince-yourself.aspx"},"modified":"2017-04-13T12:47:36","modified_gmt":"2017-04-13T19:47:36","slug":"misconceptions-around-the-log-and-log-backups-how-to-convince-yourself","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/","title":{"rendered":"Misconceptions around the log and log backups: how to convince yourself"},"content":{"rendered":"<p>There&#8217;s still a widely held misconception that when properly in the FULL or BULK_LOGGED recovery models that full or differential backups can truncate the log. No. It *NEVER* happens. This is one of the reasons why I&#8217;m doing a whole spotlight session on this at PASS this year &#8211; the transaction log and its behavior is IMHO one of the most misunderstood parts of SQL Server.<\/p>\n<p>Notice that I said &#8216;when properly in the FULL or BULK_LOGGED recovery models&#8217;. If you switch recovery models to FULL or BULK_LOGGED, until you take the first full backup, you are still essentially in the SIMPLE recovery model, and so the log will truncate on checkpoint. Once you take that first full backup, you are then in I-will-manage-the-size-of-the-log-through-log-backups mode. After that, the ONLY thing that will allow the log to clear\/truncate is a log backup, as long as nothing else requires those transaction log records.<\/p>\n<p>If you&#8217;re not familiar with the term &#8216;log clearing&#8217; or &#8216;log truncating&#8217;, they mean exactly the same thing &#8211; part of the transaction log is marked as no longer needed and can be overwritten. Nothing is zeroed out, the log file size is not altered. Some background reading on this:<\/p>\n<ul>\n<li>My <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/2009.02.logging.aspx\">Understanding Logging and Recovery in SQL Server<\/a> article in TechNet Magazine from February 2009. This also has a screencast demo that shows the log continues to truncate-on-checkpoint after switching to FULL and before a full backup has been taken.<\/li>\n<li>An editorial I wrote in April about <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/importance-of-proper-transaction-log-size-management\/\">Importance of proper transaction log size management<\/a>.<\/li>\n<li>A pretty deep blog post I wrote about analyzing VLF sequences in the log: <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/inside-the-storage-engine-more-on-the-circular-nature-of-the-log\/\">Inside the Storage Engine: More on the circular nature of the log<\/a><\/li>\n<\/ul>\n<p>Earlier this week I was involved in a discussion about log backup size management and how to prevent a log backup following a maintenance operation to not contain details of the maintenance operation.<\/p>\n<p>There&#8217;s a very simple answer: you can&#8217;t.<\/p>\n<p>If you do an operation in the FULL or BULK_LOGGED recovery models, the next log backup will contain all information required to replay that operation. In the FULL recovery model, everything is fully logged, so the log backup will contain all the log records generated by the operation. In the BULK_LOGGED recovery model, you may perform a minimally-logged operation, which generates hardly any transaction log, but the next log *backup* will be about the same size as if the operation was fully logged &#8211; because the log backup will pick up all the data extents modified by the minimally-logged operation.<\/p>\n<p>One point in the discussion was that if you&#8217;re running in the FULL or BULK_LOGGED recovery models, and you do a full backup after the maintenance operation, and before the log backup, the full backup will contain all the changes made by the maintenance operation, yes,\u00a0and will clear the log.<\/p>\n<p>No. Never.<\/p>\n<p>A log backup is *ALL* the log generated since the last log backup. If this were not the case, how would log shipping work? You could take a full backup on the log shipping primary and suddenly you&#8217;ve broken the log backup chain and log shipping breaks. No, this is not how things work. A full backup contains only enough transaction log necessary to be able to restore that database to a transactionally consistent time &#8211; the time at which the data reading portion of the full backup completed. I blogged about this extensively previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/debunking-a-couple-of-myths-around-full-database-backups\/\">Debunking a couple of myths around full database backups<\/a>\u00a0(which also explains why the WITH STOPAT syntax exists for full and differential backups, but has no effect and is only there to allow you to put WITH STOPAT on all backups in a point-in-time restore sequence.<\/li>\n<li><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/more-on-how-much-transaction-log-a-full-backup-includes\/\">More on how much transaction log a full backup includes<\/a><\/li>\n<\/ul>\n<p>But you don&#8217;t have to believe me &#8211; it&#8217;s very simple to convince yourself. The following script will show you that a full backup has no effect on the transaction log. It does the following:<\/p>\n<ul>\n<li>Create a database and put it into the FULL recovery model, with a full backup.<\/li>\n<li>Create and populate and index.<\/li>\n<li>Take log backup 1 (just to clear things out)<\/li>\n<li>Rebuild the index.<\/li>\n<li>Take log backup 2.<\/li>\n<li>Rebuild the index.<\/li>\n<li>Take a full backup.<\/li>\n<li>Take log backup 3.<\/li>\n<\/ul>\n<p>And we will see that log backup #3 is the same size as log backup #2. The full backup will make no difference whatsoever.<\/p>\n<p>Here&#8217;s the script:<\/p>\n<pre class=\"brush: sql; gutter: true; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nUSE master;\r\nGO\r\nDROP DATABASE LogBackupTest;\r\nGO\r\nCREATE DATABASE LogBackupTest;\r\nGO\r\nUSE LogBackupTest;\r\nGO\r\n\r\nALTER DATABASE LogBackupTest SET RECOVERY FULL;\r\nGO\r\nBACKUP DATABASE LogBackupTest TO\r\nDISK = 'C:SQLskillsLogBackupTest_Full1.bak' WITH INIT;\r\nGO\r\n\r\nCREATE TABLE t1 (c1 INT IDENTITY, c2 CHAR (8000) DEFAULT 'a');\r\nGO\r\nCREATE CLUSTERED INDEX t1c1 ON t1 (c1);\r\nGO\r\nSET NOCOUNT ON;\r\nGO\r\nINSERT INTO t1 DEFAULT VALUES;\r\nGO 1000\r\n\r\nBACKUP LOG LogBackupTest TO\r\nDISK = 'C:SQLskillsLogBackupTest_Log1.bak' WITH INIT;\r\nGO\r\n\r\n-- Rebuild the index to generate some log and get a baseline\r\nALTER INDEX t1c1 ON t1 REBUILD;\r\nGO\r\nBACKUP LOG LogBackupTest TO\r\nDISK = 'C:SQLskillsLogBackupTest_Log2.bak' WITH INIT;\r\nGO\r\n\r\n-- Now do it again, but take a full backup before the log backup\r\nALTER INDEX t1c1 ON t1 REBUILD;\r\nGO\r\nBACKUP DATABASE LogBackupTest TO\r\nDISK = 'C:SQLskillsLogBackupTest_Full2.bak' WITH INIT;\r\nGO\r\nBACKUP LOG LogBackupTest TO\r\nDISK = 'C:SQLskillsLogBackupTest_Log3.bak' WITH INIT;\r\nGO\r\n<\/pre>\n<p>And here&#8217;s the result:<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg\" alt=\"\" width=\"577\" height=\"90\" \/><\/p>\n<p>Log backup #3 is the same size as log backup #2. It contains all the log generated since log backup #2 was taken. The full backup had no affect whatsoever, because that would break the log backup chain.<\/p>\n<p>If you don&#8217;t believe me, run the script yourself and you&#8217;ll see. A full backup does not and cannot affect the transaction log.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s still a widely held misconception that when properly in the FULL or BULK_LOGGED recovery models that full or differential backups can truncate the log. No. It *NEVER* happens. This is one of the reasons why I&#8217;m doing a whole spotlight session on this at PASS this year &#8211; the transaction log and its behavior [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,14,38,61,98],"tags":[],"class_list":["post-848","post","type-post","status-publish","format-standard","hentry","category-backuprestore","category-bad-advice","category-example-scripts","category-misconceptions","category-transaction-log"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Misconceptions around the log and log backups: how to convince yourself - 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\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Misconceptions around the log and log backups: how to convince yourself - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"There&#8217;s still a widely held misconception that when properly in the FULL or BULK_LOGGED recovery models that full or differential backups can truncate the log. No. It *NEVER* happens. This is one of the reasons why I&#8217;m doing a whole spotlight session on this at PASS this year &#8211; the transaction log and its behavior [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2009-05-29T11:09:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T19:47:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.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=\"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\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/\",\"name\":\"Misconceptions around the log and log backups: how to convince yourself - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg\",\"datePublished\":\"2009-05-29T11:09:00+00:00\",\"dateModified\":\"2017-04-13T19:47:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#primaryimage\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg\",\"contentUrl\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Misconceptions around the log and log backups: how to convince yourself\"}]},{\"@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":"Misconceptions around the log and log backups: how to convince yourself - 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\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/","og_locale":"en_US","og_type":"article","og_title":"Misconceptions around the log and log backups: how to convince yourself - Paul S. Randal","og_description":"There&#8217;s still a widely held misconception that when properly in the FULL or BULK_LOGGED recovery models that full or differential backups can truncate the log. No. It *NEVER* happens. This is one of the reasons why I&#8217;m doing a whole spotlight session on this at PASS this year &#8211; the transaction log and its behavior [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/","og_site_name":"Paul S. Randal","article_published_time":"2009-05-29T11:09:00+00:00","article_modified_time":"2017-04-13T19:47:36+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg","type":"","width":"","height":""}],"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\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/","name":"Misconceptions around the log and log backups: how to convince yourself - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg","datePublished":"2009-05-29T11:09:00+00:00","dateModified":"2017-04-13T19:47:36+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#primaryimage","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg","contentUrl":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-content\/uploads\/2009\/5\/logbackuptest.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-the-log-and-log-backups-how-to-convince-yourself\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Misconceptions around the log and log backups: how to convince yourself"}]},{"@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\/848","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=848"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/848\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}