{"id":29,"date":"2012-12-04T05:35:18","date_gmt":"2012-12-04T05:35:18","guid":{"rendered":"http:\/\/www.theSQLReport.com\/?p=29"},"modified":"2013-02-06T02:04:43","modified_gmt":"2013-02-06T02:04:43","slug":"transaction-log-grows-unexpectedly-due-to-orphan-transactions","status":"publish","type":"post","link":"https:\/\/www.theSQLReport.com\/?p=29","title":{"rendered":"Transaction Log Grows Unexpectedly Due to Orphan Transactions"},"content":{"rendered":"<p>Problem:<\/p>\n<p>A SQL Server 2005 database&#8217;s transaction log file is growing.\u00a0 The transaction log file is originally 20 gigabytes in size.\u00a0 Over a three day period, the transaction log grow to 120 gigabytes in size.\u00a0 Doing the log backup does not release all the space in the transaction log.\u00a0 \u00a0 The transaction log backup would run successfully every hour, but the backup file would only be a gigabyte in size.\u00a0 In this case, after each transaction log backup the &#8220;Log Space Used (%)&#8221; never went below 95%.\u00a0 Very frustrating \ud83d\ude41<\/p>\n<p>We found the issue to be orphaned transactions in the database.<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sqlperf_logspace.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-34\" title=\"sqlperf_logspace\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sqlperf_logspace.jpg\" alt=\"\" width=\"364\" height=\"263\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sqlperf_logspace.jpg 364w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sqlperf_logspace-300x216.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sqlperf_logspace-210x151.jpg 210w\" sizes=\"(max-width: 364px) 100vw, 364px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>First Step: Identify the orphan transactions.<\/p>\n<p>When I ran sys.dm_tran_database_transactions (as seen below), I see that I have transactions that are days old that have not committed.\u00a0\u00a0 For example, transaction_id: 874532313, was created on 11\/23\/2012, and the database_transaction_state is 4 ( transaction has generated log records ).\u00a0 To state the obvious, we should not have a transaction_id that is days old like this.\u00a0\u00a0 That mean this transaction has not been commited, nor has it been rolled back.<\/p>\n<p>Please refer to this link on <a title=\"SqlServerpedia.com - sys.dm_tran_database_transactions\" href=\"http:\/\/sqlserverpedia.com\/wiki\/DM_Objects_-_Sys.dm_tran_database_transactions\" target=\"_blank\">sys.dm_tran_database_transactions<\/a> for more information on this dynamic object.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sys.dm_tran_database_transactions.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41\" title=\"sys.dm_tran_database_transactions\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sys.dm_tran_database_transactions.jpg\" alt=\"\" width=\"1176\" height=\"368\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sys.dm_tran_database_transactions.jpg 1176w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sys.dm_tran_database_transactions-300x93.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sys.dm_tran_database_transactions-1024x320.jpg 1024w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/sys.dm_tran_database_transactions-210x65.jpg 210w\" sizes=\"(max-width: 1176px) 100vw, 1176px\" \/><\/a><\/p>\n<p>Second Step:<\/p>\n<p>Run &#8220;DBCC LOGINFO&#8221;.\u00a0\u00a0\u00a0 When we ran this statement, we found that a number of the virtual log files had a status of 2, which mean that it can not be overwritten.<\/p>\n<p>Third Step:<\/p>\n<p>We queried sys.dm_tran_locks, we were able to see that the transaction_id from\u00a0sys.dm_tran_database_transactions was called request_owner_id in this dynamic object, and that the session was -2. (the picture below\u00a0 does not correspond to the pictures above, this is only reference).\u00a0\u00a0 The -2 for a session owner signifies that this transaction has been orphaned.\u00a0 The\u00a0session owner was closed or killed before the transaction could be committed or rolled back.<\/p>\n<p>On side note, we already new that the software writing to this database would produce orphan transactions when it experienced high volume of transactions.<\/p>\n<div id=\"attachment_49\" style=\"width: 873px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/SYS.DM_TRAN_LOCKS1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-49\" class=\"alignnone size-full wp-image-54\" title=\"SYS.DM_TRAN_LOCKS\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/SYS.DM_TRAN_LOCKS1.jpg\" alt=\"\" width=\"863\" height=\"455\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/SYS.DM_TRAN_LOCKS1.jpg 863w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/SYS.DM_TRAN_LOCKS1-300x158.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2012\/12\/SYS.DM_TRAN_LOCKS1-210x110.jpg 210w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/a><p id=\"caption-attachment-49\" class=\"wp-caption-text\">SYS.DM_TRAN_LOCKS - Dynamic Object<\/p><\/div>\n<p>Final Step:<\/p>\n<p>With the information in the request_owner_guid column of the\u00a0sys.dm_tran_locks, you can use the kill command rollback the orphaned transaction.<\/p>\n<p>For example: if you wanted to remove transaction_id\/request_owner_id: 1137037072, then run the following command:<\/p>\n<p>&#8212;<\/p>\n<p>KILL &#8216;4C79FC71-D1FF-402A-AB70-95BA150984EB&#8217;<\/p>\n<p>GO<\/p>\n<p>&#8212;<\/p>\n<p>See the Microsoft link for more information regarding the <a title=\"TSQL - KILL \" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190345.aspx\" target=\"_blank\">KILL<\/a> command and orphaned transactions.<\/p>\n<p>Once the orphaned transactions were killed, we were successfully able to do a transaction log backup, and the\u00a0&#8220;Log Space Used (%)&#8221; went from 95% to 0.04%.<\/p>\n<p>In the &#8220;DBCC LOGINFO&#8221;, the status of all but one line changes from 2 to 0.<\/p>\n<p>Please note that the software did have a another batch process by which we did recover all these transactions.<\/p>\n<p>Final Notes:<\/p>\n<p>Thanks to Dan who found the that the request_owner_guid in sys.dm_tran_locks could be used in the KILL statement.<\/p>\n<p>Also this post will be re-posted, when I can get screen shots of a single transaction_id to be used in all the pictures.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: A SQL Server 2005 database&#8217;s transaction log file is growing.\u00a0 The transaction log file is originally 20 gigabytes in size.\u00a0 Over a three day period, the transaction log grow &hellip; <a class=\"readmore\" href=\"https:\/\/www.theSQLReport.com\/?p=29\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":41,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-29","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql-server"],"_links":{"self":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/29"}],"collection":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=29"}],"version-history":[{"count":30,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":64,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions\/64"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/media\/41"}],"wp:attachment":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}