How to resolve archive gap between primary and standby database :
1) Check the current SCN on both primary and standby database :
On the primary:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------
1447102
On the standby:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------
1301571
2) Check the time difference also :
On the primary:
SQL> select scn_to_timestamp(1447102) from dual;
SCN_TO_TIMESTAMP(1447102)
-------------------------------
18-DEC-09 08.54.28.000000000 AM
On the standby:
SQL> select scn_to_timestamp(1301571) from dual;
SCN_TO_TIMESTAMP(1301571)
-------------------------------
15-DEC-09 07.19.27.000000000 PM
3) Chech the archive lags using below query:
On the primary:
SQL> select p.prim_max,
f.fall_max_archived,
d.dr_max_archived,
af.fall_max_applied,
ad.dr_max_applied,
p.prim_max-f.fall_max_archived archive_lag_fall,
p.prim_max-d.dr_max_archived archive_lag_dr,
p.prim_max-af.fall_max_applied applied_lag_fall,
p.prim_max-ad.dr_max_applied applied_lag_dr
from
(select max(sequence#) prim_max from v$archived_log where dest_id=1 and archived='YES') p,
(select max(sequence#) fall_max_archived from v$archived_log where standby_dest='YES' and archived='YES' and dest_id=2) f,
(select max(sequence#) dr_max_archived from v$archived_log where standby_dest='YES' and archived='YES' and dest_id=3) d,
(select max(sequence#) fall_max_applied from v$archived_log where standby_dest='YES' and archived='YES' and applied='YES' and dest_id=2) af,
(select max(sequence#) dr_max_applied from v$archived_log where standby_dest='YES' and archived='YES' and applied='YES' and dest_id=3) ad;
OR
SQL> select a.live-b.dest_id_2 as dest_id_2,a.live-c.dest_id_3 as dest_id_3,a.live-d.dest_id_4 as dest_id_4,a.live-e.dest_id_5 as dest_id_5
from (select max(sequence#) as live from v$archived_log) a,
(select max(sequence#) as dest_id_2 from v$archived_log where applied='YES' and dest_id=2) b,
(select max(sequence#) as dest_id_3 from v$archived_log where applied='YES' and dest_id=3) c,
(select max(sequence#) as dest_id_4 from v$archived_log where applied='YES' and dest_id=4) d,
(select max(sequence#) as dest_id_5 from v$archived_log where applied='YES' and dest_id=5) e;
4) Take the incremental backup on primary:
RMAN> run {
2> allocate channel c1 type disk format '/u01/backup/%U.bkp';
3> backup incremental from scn 1301571 database;
4> }
5) Take the standby controlfile backup on primary:
SQL> alter database create standby controlfile as '/u01/backup/standby_controlfile_bkp.ctl';
Database altered.
6) Copy incremental backup and standby controlfile backup to standby server
scp *.bkp *.ctl oracle@oracle123:/u02/orabkp
7) Stop the managed standby apply process:
On the standby:
SQL> alter database recover managed standby database cancel;
Database altered.
8) Shutdown the standby database and start in nomount mode :
SQL> shut immediate;
SQL> startup nomount;
9) Connect to RMAN and catalog the backup files to RMAN and follow below steps:
On the standby:
$ rman target /
RMAN> catalog start with '/u02/orabkp'
RMAN> restore standby controlfile from '/u02/orabkp/standby_controlfile_bkp.ctl'
RMAN> sql'alter database mount standby database';
10) Performe recovery :
On the standby:
RMAN> recover database;
11) Start managed recovery process :
On the standby:
SQL> alter database recover managed standby database disconnect from session;
Database altered.
12) Check the SCN in primary and standby, it should be close to each other :
On the primary:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------1447478
On the standby:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------1447474
1) Check the current SCN on both primary and standby database :
On the primary:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------
1447102
On the standby:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------
1301571
2) Check the time difference also :
On the primary:
SQL> select scn_to_timestamp(1447102) from dual;
SCN_TO_TIMESTAMP(1447102)
-------------------------------
18-DEC-09 08.54.28.000000000 AM
On the standby:
SQL> select scn_to_timestamp(1301571) from dual;
SCN_TO_TIMESTAMP(1301571)
-------------------------------
15-DEC-09 07.19.27.000000000 PM
3) Chech the archive lags using below query:
On the primary:
SQL> select p.prim_max,
f.fall_max_archived,
d.dr_max_archived,
af.fall_max_applied,
ad.dr_max_applied,
p.prim_max-f.fall_max_archived archive_lag_fall,
p.prim_max-d.dr_max_archived archive_lag_dr,
p.prim_max-af.fall_max_applied applied_lag_fall,
p.prim_max-ad.dr_max_applied applied_lag_dr
from
(select max(sequence#) prim_max from v$archived_log where dest_id=1 and archived='YES') p,
(select max(sequence#) fall_max_archived from v$archived_log where standby_dest='YES' and archived='YES' and dest_id=2) f,
(select max(sequence#) dr_max_archived from v$archived_log where standby_dest='YES' and archived='YES' and dest_id=3) d,
(select max(sequence#) fall_max_applied from v$archived_log where standby_dest='YES' and archived='YES' and applied='YES' and dest_id=2) af,
(select max(sequence#) dr_max_applied from v$archived_log where standby_dest='YES' and archived='YES' and applied='YES' and dest_id=3) ad;
OR
SQL> select a.live-b.dest_id_2 as dest_id_2,a.live-c.dest_id_3 as dest_id_3,a.live-d.dest_id_4 as dest_id_4,a.live-e.dest_id_5 as dest_id_5
from (select max(sequence#) as live from v$archived_log) a,
(select max(sequence#) as dest_id_2 from v$archived_log where applied='YES' and dest_id=2) b,
(select max(sequence#) as dest_id_3 from v$archived_log where applied='YES' and dest_id=3) c,
(select max(sequence#) as dest_id_4 from v$archived_log where applied='YES' and dest_id=4) d,
(select max(sequence#) as dest_id_5 from v$archived_log where applied='YES' and dest_id=5) e;
4) Take the incremental backup on primary:
RMAN> run {
2> allocate channel c1 type disk format '/u01/backup/%U.bkp';
3> backup incremental from scn 1301571 database;
4> }
5) Take the standby controlfile backup on primary:
SQL> alter database create standby controlfile as '/u01/backup/standby_controlfile_bkp.ctl';
Database altered.
6) Copy incremental backup and standby controlfile backup to standby server
scp *.bkp *.ctl oracle@oracle123:/u02/orabkp
7) Stop the managed standby apply process:
On the standby:
SQL> alter database recover managed standby database cancel;
Database altered.
8) Shutdown the standby database and start in nomount mode :
SQL> shut immediate;
SQL> startup nomount;
9) Connect to RMAN and catalog the backup files to RMAN and follow below steps:
On the standby:
$ rman target /
RMAN> catalog start with '/u02/orabkp'
RMAN> restore standby controlfile from '/u02/orabkp/standby_controlfile_bkp.ctl'
RMAN> sql'alter database mount standby database';
10) Performe recovery :
On the standby:
RMAN> recover database;
11) Start managed recovery process :
On the standby:
SQL> alter database recover managed standby database disconnect from session;
Database altered.
12) Check the SCN in primary and standby, it should be close to each other :
On the primary:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------1447478
On the standby:
SQL> select to_char(current_scn) from v$database;
CURRENT_SCN
-----------1447474