{"id":252,"date":"2017-10-11T15:40:34","date_gmt":"2017-10-11T13:40:34","guid":{"rendered":"https:\/\/blog.kurschies.de\/?p=252"},"modified":"2019-10-15T14:49:21","modified_gmt":"2019-10-15T12:49:21","slug":"recover-standby-database","status":"publish","type":"post","link":"https:\/\/blog.kurschies.de\/index.php\/2017\/10\/11\/recover-standby-database\/","title":{"rendered":"recover standby database"},"content":{"rendered":"<p>well, oracle dataguard in general is rock solid (if configured well &#8211; but you will find a lot of guides in the internet how to do so)&#8230; but as always, sometimes something is not working as it should and the standby is out of sync afterwards (i.e. a network outage between the servers, and to avoid archiver stuck on the primary site you are forcing a delete of the archive logs).<\/p>\n<p>OK, the network is working again, so how to solve the gap? If only a few archivelogs are missing, my first choice would be a restore of the archivelogs from backup. But what if thousends of archivelogs are missing? restore them all from tape? Based on my experiences, this could be a very time consuming procedure, in worst case the tape drive is not fast enough to catch up with the primary. In this case you may consider rebuilding the standby (rman&gt; duplicate database for standby from active database;) &#8230; have you ever tried to do this with a 50 TB database? The solution might be an incremental recovery! If you consider some peculiarities, it&#8217;s not so complicated&#8230;<\/p>\n<ol>\n<li>stop redo apply (it&#8217;s not working anyway)<\/li>\n<\/ol>\n<p>you cannot apply an incremental backup while the apply is running, so let&#8217;s stop it:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndgmgrl \/\r\nedit database 'ORCLRB' set state='APPLY-OFF';\r\n<\/pre>\n<ol start=\"2\">\n<li>evaluate what&#8217;s missing<\/li>\n<\/ol>\n<p>Then we have to figure out where our incremental backup shoud start&#8230; the easy way is to query the v$database view to get the current scn &#8211; but this only returns the information stored in the controlfile, sometimes the headers of the datafiles do have a lower scn and rman refuses to start the recovery. so the sql must be like this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# execute on standby!\r\nsqlplus \/ as sysdba\r\nset linesize 200\r\nSELECT 'BACKUP INCREMENTAL FROM SCN '||min(SCN)||' DATABASE FORMAT ''\/tmp\/recover_standby_%U'';' FROM (\r\n   select current_scn SCN from V$DATABASE\r\n   union all\r\n   select min(checkpoint_change#) from v$datafile_header \r\n   where file# not in (select file# from v$datafile where enabled = 'READ ONLY')\r\n);\r\n<\/pre>\n<ol start=\"3\">\n<li>start backup<\/li>\n<\/ol>\n<p>well, just execute the output of the above sql on the primary database&#8230; and when it is finished, you also need a fresh standby controlfile:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# execute on primary!\r\nsqlplus \/ as sysdba\r\nALTER DATABASE CREATE STANDBY CONTROLFILE AS '\/tmp\/stby.ctl';\r\n<\/pre>\n<ol start=\"4\">\n<li>start recover<\/li>\n<\/ol>\n<p>First you have to make the backup availeble on the standby site&#8230; either mount as NFS device or copy the backup files via scp to the standby site. Then catalog the files and start recovery&#8230;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# execute on standby!\r\nrman target \/\r\ncatalog start with '\/tmp\/recover_standby';\r\nrecover database noredo;\r\n<\/pre>\n<ol start=\"5\">\n<li>restore controlfile<\/li>\n<\/ol>\n<p>now we have to &#8220;update&#8221; the controlfile&#8230; since this is not possible, we are doing a full restore.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# execute on standby!\r\nrman target \/\r\nshutdown immediate;\r\nstartup nomount;\r\nrestore controlfile from '\/tmp\/stby.ctl';\r\nalter database mount;\r\nexit;\r\n<\/pre>\n<p>if the structure of the database is not exactly the same as on the primary site, you have to populate the the new file and folder names:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nrman target \/\r\ncatalog start with '+U01\/ORCLRB\/DATAFILE';\r\nswitch database to copy;\r\n<\/pre>\n<ol start=\"5\">\n<li>enable redo apply<\/li>\n<\/ol>\n<p>almost finished, now we only have to enable the dataguard process again&#8230;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndgmgrl \/\r\nedit database 'ORCLRB' set state='APPLY-ON';\r\n<\/pre>\n<p>done&#8230; just check the alert.log if the standby is receiving and applying the last few archivelogs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>well, oracle dataguard in general is rock solid (if configured well &#8211; but you will find a lot of guides in the internet how to do so)&#8230; but as always, sometimes something is not working as it should and the &hellip; <a href=\"https:\/\/blog.kurschies.de\/index.php\/2017\/10\/11\/recover-standby-database\/\">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":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[14,7],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-dataguard","tag-oracle"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8m6YC-44","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":9,"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/posts\/252\/revisions\/385"}],"wp:attachment":[{"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kurschies.de\/index.php\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}