{"id":7299,"date":"2018-03-31T08:57:18","date_gmt":"2018-03-31T00:57:18","guid":{"rendered":"http:\/\/rmohan.com\/?p=7299"},"modified":"2018-03-31T08:57:18","modified_gmt":"2018-03-31T00:57:18","slug":"oracle-rman-backup","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7299","title":{"rendered":"oracle rman backup"},"content":{"rendered":"<p>How to sync standby database which is lagging behind from primary database<br \/>\nPrimary Database cluster: cluster1.rmohan.com<br \/>\nStandby Database cluster: cluster2.rmohan.com<\/p>\n<p>Primary Database: prim<br \/>\nStandby database: stand<\/p>\n<p>Database version:11.2.0.1.0<\/p>\n<p>Reason:-<br \/>\n1. Might be due to the network outage between the primary and the standby database leading to the archive<br \/>\ngaps. Data guard would be able to detect the archive gaps automatically and can fetch the missing logs as<br \/>\nsoon as the connection is re-established.<\/p>\n<p>2. It could also be due to archive logs getting missed out on the primary database or the archives getting<br \/>\ncorrupted and there would be no valid backups.<\/p>\n<p>In such cases where the standby lags far behind from the primary database, incremental backups can be used<br \/>\nas one of the methods to roll forward the physical standby database to have it in sync with the primary database.<\/p>\n<p>At primary database:-<br \/>\nSQL&gt; select status,instance_name,database_role from v$database,v$instance;<\/p>\n<p>STATUS INSTANCE_NAME DATABASE_ROLE<br \/>\n&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nOPEN prim PRIMARY<\/p>\n<p>SQL&gt; select thread#,max(sequence#) from v$archived_log group by thread#;<\/p>\n<p>THREAD# MAX(SEQUENCE#)<br \/>\n&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n1 214<\/p>\n<p>At standby database:-<br \/>\nSQL&gt; select status,instance_name,database_role from v$database,v$instance;<\/p>\n<p>STATUS INSTANCE_NAME DATABASE_ROLE<br \/>\n&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nOPEN stand PHYSICAL STANDBY<\/p>\n<p>SQL&gt; select thread#,max(sequence#) from v$archived_log group by thread#;<\/p>\n<p>THREAD# MAX(SEQUENCE#)<br \/>\n&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n1 42<br \/>\nSo we can see the standby database is having archive gap of around (214-42) 172 logs.<\/p>\n<p>Step 1: Take a note of the Current SCN of the Physical Standby Database.<br \/>\nSQL&gt; select current_scn from v$database;<\/p>\n<p>CURRENT_SCN<br \/>\n&#8212;&#8212;&#8212;&#8211;<br \/>\n1022779<\/p>\n<p>Step 2 : Cancel the Managed Recovery Process on the Standby database.<br \/>\nSQL&gt; alter database recover managed standby database cancel;<\/p>\n<p>Database altered.<\/p>\n<p>Step 3: On the Primary database, take the incremental SCN backup from the SCN that is currently recorded on the standby database (1022779)<br \/>\nAt primary database:-<\/p>\n<p>RMAN&gt; backup incremental from scn 1022779 database format &#8216;\/tmp\/rman_bkp\/stnd_backp_%U.bak&#8217;;<\/p>\n<p>Starting backup at 28-DEC-14<\/p>\n<p>using channel ORA_DISK_1<br \/>\nbackup will be obsolete on date 04-JAN-15<br \/>\narchived logs will not be kept or backed up<br \/>\nchannel ORA_DISK_1: starting full datafile backup set<br \/>\nchannel ORA_DISK_1: specifying datafile(s) in backup set<br \/>\ninput datafile file number=00001 name=\/u01\/app\/oracle\/oradata\/prim\/system01.dbf<br \/>\ninput datafile file number=00002 name=\/u01\/app\/oracle\/oradata\/prim\/sysaux01.dbf<br \/>\ninput datafile file number=00005 name=\/u01\/app\/oracle\/oradata\/prim\/example01.dbf<br \/>\ninput datafile file number=00003 name=\/u01\/app\/oracle\/oradata\/prim\/undotbs01.dbf<br \/>\ninput datafile file number=00004 name=\/u01\/app\/oracle\/oradata\/prim\/users01.dbf<br \/>\nchannel ORA_DISK_1: starting piece 1 at 28-DEC-14<br \/>\nchannel ORA_DISK_1: finished piece 1 at 28-DEC-14<br \/>\npiece handle=\/tmp\/rman_bkp\/stnd_backp_0cpr8v08_1_1.bak tag=TAG20141228T025048 comment=NONE<br \/>\nchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:25<\/p>\n<p>using channel ORA_DISK_1<br \/>\nbackup will be obsolete on date 04-JAN-15<br \/>\narchived logs will not be kept or backed up<br \/>\nchannel ORA_DISK_1: starting full datafile backup set<br \/>\nchannel ORA_DISK_1: specifying datafile(s) in backup set<br \/>\nincluding current control file in backup set<br \/>\nchannel ORA_DISK_1: starting piece 1 at 28-DEC-14<br \/>\nchannel ORA_DISK_1: finished piece 1 at 28-DEC-14<br \/>\npiece handle=\/tmp\/rman_bkp\/stnd_backp_0dpr8v12_1_1.bak tag=TAG20141228T025048 comment=NONE<br \/>\nchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01<br \/>\nFinished backup at 28-DEC-14<\/p>\n<p>We took the backup inside \/tmp\/rman_bkp directory and ensure that it contains nothing besides the incremental backups of scn.<\/p>\n<p>Step 4: Take the standby controlfile backup of the Primary database controlfile.<\/p>\n<p>At primary database:<\/p>\n<p>RMAN&gt; backup current controlfile for standby format &#8216;\/tmp\/rman_bkp\/stnd_%U.ctl&#8217;;<\/p>\n<p>Starting backup at 28-DEC-14<br \/>\nusing channel ORA_DISK_1<br \/>\nchannel ORA_DISK_1: starting full datafile backup set<br \/>\nchannel ORA_DISK_1: specifying datafile(s) in backup set<br \/>\nincluding standby control file in backup set<br \/>\nchannel ORA_DISK_1: starting piece 1 at 28-DEC-14<br \/>\nchannel ORA_DISK_1: finished piece 1 at 28-DEC-14<br \/>\npiece handle=\/tmp\/rman_bkp\/stnd_0epr8v4e_1_1.ctl tag=TAG20141228T025301 comment=NONE<br \/>\nchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01<br \/>\nFinished backup at 28-DEC-14<\/p>\n<p>Starting Control File and SPFILE Autobackup at 28-DEC-14<br \/>\npiece handle=\/u01\/app\/oracle\/flash_recovery_area\/PRIM\/autobackup\/2014_12_28\/o1_mf_s_867466384_b9y8sr8k_.bkp comment=NONE<br \/>\nFinished Control File and SPFILE Autobackup at 28-DEC-14<\/p>\n<p>Step 5: Transfer the backups from the Primary cluster to the Standby cluster.<br \/>\n[oracle@cluster1 ~]$ cd \/tmp\/rman_bkp\/<br \/>\n[oracle@cluster1 rman_bkp]$ ls -ltrh<br \/>\ntotal 24M<br \/>\n-rw-r&#8212;&#8211;. 1 oracle oinstall 4.2M Dec 28 02:51 stnd_backp_0cpr8v08_1_1.bak<br \/>\n-rw-r&#8212;&#8211;. 1 oracle oinstall 9.7M Dec 28 02:51 stnd_backp_0dpr8v12_1_1.bak<br \/>\n-rw-r&#8212;&#8211;. 1 oracle oinstall 9.7M Dec 28 02:53 stnd_0epr8v4e_1_1.ctl<\/p>\n<p>oracle@cluster1 rman_bkp]$ scp *.* oracle@cluster2:\/tmp\/rman_bkp\/<br \/>\noracle@cluster2&#8217;s password:<br \/>\nstnd_0epr8v4e_1_1.ctl 100% 9856KB 9.6MB\/s 00:00<br \/>\nstnd_backp_0cpr8v08_1_1.bak 100% 4296KB 4.2MB\/s 00:00<br \/>\nstnd_backp_0dpr8v12_1_1.bak 100% 9856KB 9.6MB\/s 00:00<\/p>\n<p>Step 6: On the standby cluster, connect the Standby Database through RMAN and catalog the copied<br \/>\nincremental backups so that the Controlfile of the Standby Database would be aware of these<br \/>\nincremental backups.<\/p>\n<p>At standby database:-<\/p>\n<p>SQL&gt;<\/p>\n<p>[oracle@cluster2 ~]$ rman target \/<br \/>\nRMAN&gt; catalog start with &#8216;\/tmp\/rman_bkp&#8217;;<\/p>\n<p>using target database control file instead of recovery catalog<br \/>\nsearching for all files that match the pattern \/tmp\/rman_bkp<\/p>\n<p>List of Files Unknown to the Database<br \/>\n=====================================<br \/>\nFile Name: \/tmp\/rman_bkp\/stnd_0epr8v4e_1_1.ctl<br \/>\nFile Name: \/tmp\/rman_bkp\/stnd_backp_0dpr8v12_1_1.bak<br \/>\nFile Name: \/tmp\/rman_bkp\/stnd_backp_0cpr8v08_1_1.bak<\/p>\n<p>Do you really want to catalog the above files (enter YES or NO)? yes<br \/>\ncataloging files&#8230;<br \/>\ncataloging done<\/p>\n<p>List of Cataloged Files<br \/>\n=======================<br \/>\nFile Name: \/tmp\/rman_bkp\/stnd_0epr8v4e_1_1.ctl<br \/>\nFile Name: \/tmp\/rman_bkp\/stnd_backp_0dpr8v12_1_1.bak<br \/>\nFile Name: \/tmp\/rman_bkp\/stnd_backp_0cpr8v08_1_1.bak<\/p>\n<p>Step 7. Shutdown the database and open it in mount stage for recovery purpose.<br \/>\nSQL&gt; shut immediate;<br \/>\nSQL&gt; startup mount;<\/p>\n<p>Step 8.Now recover the database :-<br \/>\nRMAN&gt; rman target \/<br \/>\nRMAN&gt; recover database noredo;<\/p>\n<p>Starting recover at 28-DEC-14<br \/>\nusing target database control file instead of recovery catalog<br \/>\nallocated channel: ORA_DISK_1<br \/>\nchannel ORA_DISK_1: SID=25 device type=DISK<br \/>\nchannel ORA_DISK_1: starting incremental datafile backup set restore<br \/>\nchannel ORA_DISK_1: specifying datafile(s) to restore from backup set<br \/>\ndestination for restore of datafile 00001: \/u01\/app\/oracle\/oradata\/stand\/system01.dbf<br \/>\ndestination for restore of datafile 00002: \/u01\/app\/oracle\/oradata\/stand\/sysaux01.dbf<br \/>\ndestination for restore of datafile 00003: \/u01\/app\/oracle\/oradata\/stand\/undotbs01.dbf<br \/>\ndestination for restore of datafile 00004: \/u01\/app\/oracle\/oradata\/stand\/users01.dbf<br \/>\ndestination for restore of datafile 00005: \/u01\/app\/oracle\/oradata\/stand\/example01.dbf<br \/>\nchannel ORA_DISK_1: reading from backup piece \/tmp\/rman_bkp\/stnd_backp_0cpr8v08_1_1.bak<br \/>\nchannel ORA_DISK_1: piece handle=\/tmp\/rman_bkp\/stnd_backp_0cpr8v08_1_1.bak tag=TAG20141228T025048<br \/>\nchannel ORA_DISK_1: restored backup piece 1<br \/>\nchannel ORA_DISK_1: restore complete, elapsed time: 00:00:03<\/p>\n<p>Finished recover at 28-DEC-14<br \/>\nexit.<\/p>\n<p>Step 9 : Shutdown the physical standby database, start it in nomount stage and restore the standby controlfile<br \/>\nbackup that we had taken from the primary database.<\/p>\n<p>SQL&gt; shut immediate;<br \/>\nSQL&gt; startup nomount;<\/p>\n<p>[oracle@cluster2 rman_bkp]$ rman target \/<br \/>\nRMAN&gt; restore standby controlfile from &#8216;\/tmp\/rman_bkp\/stnd_0epr8v4e_1_1.ctl&#8217;;<br \/>\necovery Manager: Release 11.2.0.1.0 &#8211; Production on Sun Dec 28 03:08:45 2014<\/p>\n<p>Copyright (c) 1982, 2009, Oracle and\/or its affiliates. All rights reserved.<\/p>\n<p>connected to target database: PRIM (not mounted)<\/p>\n<p>RMAN&gt; restore standby controlfile from &#8216;\/tmp\/rman_bkp\/stnd_0epr8v4e_1_1.ctl&#8217;;<\/p>\n<p>Starting restore at 28-DEC-14<br \/>\nusing target database control file instead of recovery catalog<br \/>\nallocated channel: ORA_DISK_1<br \/>\nchannel ORA_DISK_1: SID=20 device type=DISK<\/p>\n<p>channel ORA_DISK_1: restoring control file<br \/>\nchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01<br \/>\noutput file name=\/u01\/app\/oracle\/oradata\/stand\/stand.ctl<br \/>\noutput file name=\/u01\/app\/oracle\/flash_recovery_area\/stand\/stand.ctl<br \/>\nFinished restore at 28-DEC-14<\/p>\n<p>Step 10: Shutdown the standby database and mount the standby database, so that the standby database would<br \/>\nbe mounted with the new controlfile that was restored in the previous step.<\/p>\n<p>SQL&gt; shut immediate;<br \/>\nSQL&gt; startup mount;<\/p>\n<p>At standby database:-<br \/>\nSQL&gt; alter database recover managed standby database disconnect from session;<\/p>\n<p>At primary database:-<br \/>\nSQL&gt; select thread#,max(sequence#) from v$archived_log group by thread#;<\/p>\n<p>THREAD# MAX(SEQUENCE#)<br \/>\n&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n1 215<\/p>\n<p>At standby database:-<br \/>\nSQL&gt; select thread#,max(sequence#) from v$archived_log group by thread#;<\/p>\n<p>THREAD# MAX(SEQUENCE#)<br \/>\n&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n1 215<\/p>\n<p>Step 11.Now we will cancel the recovery to open the database<br \/>\nSQL&gt; alter database recover managed standby database cancel;<\/p>\n<p>SQL&gt; alter database open;<br \/>\nDatabase altered.<\/p>\n<p>SQL&gt; alter database recover managed standby database using current logfile disconnect from session;<br \/>\nDatabase altered.<\/p>\n<p>SQL&gt; select open_mode from v$database;<\/p>\n<p>OPEN_MODE<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nREAD ONLY WITH APPLY<\/p>\n<p>Now standby database is in sync with the Primary Database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to sync standby database which is lagging behind from primary database Primary Database cluster: cluster1.rmohan.com Standby Database cluster: cluster2.rmohan.com<\/p>\n<p>Primary Database: prim Standby database: stand<\/p>\n<p>Database version:11.2.0.1.0<\/p>\n<p>Reason:- 1. Might be due to the network outage between the primary and the standby database leading to the archive gaps. Data guard would be able to [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7299"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7299"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7299\/revisions"}],"predecessor-version":[{"id":7300,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7299\/revisions\/7300"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}