{"id":462,"date":"2009-09-13T20:39:19","date_gmt":"2009-09-13T14:39:19","guid":{"rendered":"http:\/\/techsatwork.com\/blog\/?p=462"},"modified":"2016-01-07T11:31:11","modified_gmt":"2016-01-07T05:31:11","slug":"how-much-transaction-log-is-left","status":"publish","type":"post","link":"https:\/\/techsatwork.com\/?p=462","title":{"rendered":"How much transaction log is left ?"},"content":{"rendered":"<p>What if a rouge transaction gets on your system and start using my all your transaction logs, don&#8217;t you want to be altered ?<br \/>\nOnce in a while I get certain ETL or applications that goes into a update, insert loop that just keeps running without committing causing the transaction logs to get full . The worst part of this is, genuine transactions and application gets affected as well and \u00c2\u00a0the database goes through a rollback. \u00c2\u00a0But sometimes there might be multiple mass update or delete application running and if the batch size is not configured properly, it might also fill up the log. \u00c2\u00a0In \u00c2\u00a0such cases I do not want to hunt down the developer and don&#8217;t want to him to take him to &#8220;Skull Island&#8221; for a &#8220;picnic&#8221; . \u00c2\u00a0 So I wrote this script to alert me when the Percentage of transaction log usage goes above 79%, so either I can track down the application that is doing this and take appropriate actions \u00c2\u00a0:<\/p>\n<p>1. Disconnect the rogue application and book a one way ticket to skull island \u00c2\u00a0or<br \/>\n2. \u00c2\u00a0Increase the secondary log and notify the developer to resize the batch size.<\/p>\n<p>Here is the script to download \u00c2\u00a0:<a href=\"https:\/\/techsatwork.com\/blog\/wp-content\/uploads\/2009\/09\/log_usage.txt\">log_usage.sh<\/a><\/p>\n<p>Below is the script for a quick review , but I suggest you download the script from the above link<\/p>\n<pre>export PATH=$PATH:${HOME}\/sqllib\/bin\/ \r\n. ${HOME}\/sqllib\/db2profile \r\nDatetime=\"`date +%Y-%m-%d-%H:%M:%S`\" \r\nOutputDir=`echo \"\/home\/db2inst3\/report\"` \r\ndbas=\"dbas@tecshatwork.com\" \r\necho \"select 'MYDB log is greater than '||rtrim(char(int((float(total_log_used) \/\r\n float(total_log_used+total_log_available))*100)))||'%' \r\nfrom table(snapshot_database('',-1)) as sntable where int((float(total_log_used) \/\r\n float(total_log_used+total_log_available))*100) &gt;79;\" &gt; $OutputDir\/logspace_usage.sql<\/pre>\n<pre>db2 connect to MYDB; \r\nif [ \"$?\" = \"0\" ] \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 then \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 db2 -txf $OutputDir\/logspace_usage.sql &gt;&gt; $OutputDir\/logspace.tmp 2&gt; \/dev\/null \r\nelse \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0echo \"Error connecting to database -&gt; MYDB at $Datetime\" &gt;&gt; $OutputDir\/getlogspace.err \r\nfi \r\nif [ $(cat $OutputDir\/logspace.tmp|wc -l) -gt 1 ] \r\n\u00c2\u00a0then \r\n\u00c2\u00a0 \u00c2\u00a0for emailaddr in $dbas \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0do \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 echo \"alert has been send for - &gt; MYDB\" \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0 mailx -s \"Space issue in MYDB - MYSRV\" $emailaddr &lt; $OutputDir\/logspace.tmp \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0done \r\nelse \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0echo \"Yippeee its good for now !\" \r\n\u00c2\u00a0 \u00c2\u00a0 \u00c2\u00a0rm $OutputDir\/logspace.tmp \r\nfi<\/pre>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">export PATH=$PATH:${HOME}\/sqllib\/bin\/<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">. ${HOME}\/sqllib\/db2profile<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Datetime=&#8221;`date +%Y-%m-%d-%H:%M:%S`&#8221;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">OutputDir=`echo &#8220;\/home\/db2inst3\/report&#8221;`<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">dbas=&#8221;raju@tecshatwork.com&#8221;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">echo &#8220;select &#8216;MYDB log is greater than &#8216;||rtrim(char(int((float(total_log_used) \/ float(total_log_used+total_log_available))*100)))||&#8217;%&#8217; from table(snapshot_database(&#8221;,-1)) as sntable where int((float(total_log_used) \/ float(total_log_used+total_log_available))*100) &gt;79;&#8221; &gt; $OutputDir\/logspace_usage.sql<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">db2 connect to siebelpa;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">if [ &#8220;$?&#8221; = &#8220;0&#8221; ]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">then<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">db2 -txf $OutputDir\/logspace_usage.sql &gt;&gt; $OutputDir\/logspace.tmp 2&gt; \/dev\/null<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">else<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">echo &#8220;Error connecting to database -&gt; MYDB at $Datetime&#8221; &gt;&gt; $OutputDir\/getlogspace.err<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">fi<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">if [ $(cat $OutputDir\/logspace.tmp|wc -l) -gt 1 ]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">then<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">for emailaddr in $dbas<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">do<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">echo &#8220;alert has been send for &#8211; &gt; MYDB&#8221;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">mailx -s &#8220;Space issue in MYDB &#8211; MYSRV&#8221; $emailaddr &lt; $OutputDir\/logspace.tmp<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">done<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">else<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">echo &#8220;Yippeee its good for now !&#8221;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">rm $OutputDir\/logspace.tmp<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">fi<\/div>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What if a rouge transaction gets on your system and start using my all your transaction logs, don&#8217;t you want to be altered ? Once in a while I get certain ETL or applications that goes into a update, insert loop that just keeps running without committing causing the transaction logs to get full . [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[3],"tags":[],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-db2"],"_links":{"self":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=462"}],"version-history":[{"count":3,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":1529,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/462\/revisions\/1529"}],"wp:attachment":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}