{"id":38,"date":"2009-01-05T17:49:10","date_gmt":"2009-01-05T15:49:10","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=38"},"modified":"2020-08-18T17:01:46","modified_gmt":"2020-08-18T15:01:46","slug":"quick-oracle-dataguard-check-script","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/quick-oracle-dataguard-check-script\/","title":{"rendered":"Quick Oracle Dataguard check script"},"content":{"rendered":"<p>Oracle Dataguard has his own command-line <i>dgmgrl<\/i> to check the whole dataguard configuration status.<br \/>\nAt least you should check that the <i>show configuration<\/i> command returns <b>SUCCESS<\/b>.<\/p>\n<p>This is an hypothetic script:<\/p>\n<pre lang=\"bash\">\r\n#!\/bin\/bash\r\nexport ORACLE_HOME=\/u1\/app\/oracle\/product\/10.2.0\r\nexport ORACLE_SID=orcldg\r\nresult=`echo \"show configuration;\" | \\\r\n  $ORACLE_HOME\/bin\/dgmgrl sys\/strongpasswd | \\\r\n  grep -A 1 \"Current status for\" | grep -v \"Current status for\"`\r\nif [ \"$result\" = \"SUCCESS\" ] ; then\r\n    exit 0\r\nelse\r\n    exit 1\r\nfi\r\n<\/pre>\n<p>Another script should check for the gap between production online log and the log stream received by the standby database. This can be accomplished with v$managed_standby view.<br \/>\nThe Total Block Gap between production and standby can be calculated this way:<br \/>\nSum all blocks from v$archived_logs where seq# between  Current Standby Seq# and Current Production Seq#.  Then add current block# of the production LGWR process and subtract current block# from RFS standby process. This gives you total blocks even if there is a log sequence gap between sites.<br \/>\nThis is NOT the gap of online log APPLIED to the standby database. THIS IS THE GAP OF ONLINE LOG TRANSMITTED TO THE STANDBY RFS PROCESS and can be used to monitor your dataguard transmission from production to disaster recovery environment.<\/p>\n<p>This is an excerpt of such script (please take care that it does not check against RFS failures, so it can fails when RFS is not alive):<\/p>\n<pre lang=\"perl\">\r\n#!\/u1\/app\/oracle\/product\/10.2.0\/perl\/bin\/perl -w\r\nuse DBI;\r\nuse DBD::Oracle qw(:ora_session_modes);\r\n# DB connection #\r\nmy $prod  = \"orclprod\";\r\nmy $stby = \"orcldr\";\r\nmy $prodh;\r\nunless ($prodh = DBI->connect('dbi:Oracle:'.$prod,\r\n  'sys', 'strongpassword',\r\n  {PrintError=>0, AutoCommit => 0,\r\n  ora_session_mode => ORA_SYSDBA}))  {\r\n    print \"Error connecting to DB: $DBI::errstr\\n\";\r\n        exit(1);\r\n}\r\n$prodh->{RaiseError}=1;\r\n\r\nmy $stbyh;\r\nunless ($stbyh = DBI->connect('dbi:Oracle:'.$stby,\r\n  'sys', 'strongpassword',\r\n  {PrintError=>0, AutoCommit => 0,\r\n  ora_session_mode => ORA_SYSDBA}))  {\r\n    print \"Error connecting to DB: $DBI::errstr\\n\";\r\n        $prodh->disconnect;\r\n        exit(1);\r\n}\r\n$stbyh->{RaiseError}=1;\r\n\r\nmy $sth;\r\n### query prod\r\n$sth = $prodh->prepare( < <eosql );\r\n        select SEQUENCE#, BLOCK# from v\\$managed_standby\r\n        where process='LGWR'\r\nEOSQL\r\n$sth->execute();\r\nmy ($psequence, $pblock) = $sth->fetchrow_array();\r\n$sth->finish();\r\n### query stdby\r\n$sth = $stbyh->prepare( < <\/eosql><eosql );\r\n        select SEQUENCE#, BLOCK# from v\\$managed_standby\r\n        where process='RFS' and client_process='LGWR'\r\nEOSQL\r\n$sth->execute();\r\nmy ($ssequence, $sblock) = $sth->fetchrow_array();\r\n$sth->finish();\r\n\r\nprintf (\"PROD   : %10d %10d\\n\", $psequence, $pblock);\r\nprintf (\"STANDBY: %10d %10d\\n\", $ssequence, $sblock);\r\n\r\n$sth = $stbyh->prepare( < <\/eosql><eosql );\r\n        select nvl(sum(blocks),0)\r\n        + $pblock - $sblock as BLOCK_GAP\r\n    from v\\$archived_log\r\n        where sequence# between $ssequence and $psequence\r\nEOSQL\r\n$sth->execute();\r\nmy ($blockgap) = $sth->fetchrow_array();\r\n$sth->finish();\r\nprintf (\"%-10d blocks gap\\n\", $blockgap);\r\n\r\n$stbyh->disconnect;\r\n$prodh->disconnect;\r\n<\/eosql><\/pre>\n<p>Any comment is appreciated!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Oracle Dataguard has his own command-line dgmgrl to check the whole dataguard configuration status. At least you should check that the show configuration command returns SUCCESS. This is an hypothetic script: #!\/bin\/bash export ORACLE_HOME=\/u1\/app\/oracle\/product\/10.2.0 export ORACLE_SID=orcldg result=`echo &#8220;show configuration;&#8221; | &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/quick-oracle-dataguard-check-script\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,327,326,329,3],"tags":[22,29],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-linux","category-oracle-maa","category-oracle","category-oracle-dg","category-oracledb","tag-oracle-database","tag-oracle-dataguard"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":5,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":1996,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/38\/revisions\/1996"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}