Professional Documents
Culture Documents
html
How to Recover Standby Database from a Missing Archive Log by applying the
Incremental backup from Production Database
Resync the standby database using an incremental RMAN backup from the primary database.
Advantages:
----------* This does not require a full rebuild of the standby database
* Time saving.
Scenario:
--------Primary Database - pdb
Standby Database - sdb
One of the archivelog files is missing and there is no backup of that archivelog. Primary database
and Standby database are not in SYNC. There is an archival gap.
Resyncing the standby data using RMAN incremental backup taken from the primary database.
On Primary Database:
-------------------connect as sys user and check the archive log list
SQL> conn sys/oracle@sdb as sysdba
Connected.
SQL> select instance_name from v$instance;
INSTANCE_NAME
-------------sdb
SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mode
Enabled
/vol1/pdb/arch
23
25
25
Archive Mode
Enabled
/vol1/pdb/arch
24
26
26
ON Standby database:
-------------------SQL> conn sys/oracle@sdb as sysdba
Connected.
SQL> select instance_name from v$instance;
INSTANCE_NAME
---------------sdb
Archive Mode
Enabled
/vol2/sdb/arch
24
0
26
ON Primary Database:
-------------------Create a user, connect to that user, create table and insert records in it.
SQL> conn veera/veera@pdb
Connected.
SQL>
SQL> select * from tab;
no rows selected
SQL>
SQL>
SQL> create table emp (empid number(4), emp_name varchar2(12));
Table created.
SQL> insert into emp values(&empid,'&emp_name');
Enter value for empid: 1111
Enter value for emp_name: veera
old
1: insert into emp values(&empid,'&emp_name')
new
1: insert into emp values(1111,'veera')
1 row created.
SQL> /
Enter value for
Enter value for
old
1: insert
new
1: insert
empid: 1309
emp_name: suresh
into emp values(&empid,'&emp_name')
into emp values(1309,'suresh')
1 row created.
SQL> commit;
Commit complete.
SQL> select * from emp;
EMPID
---------1111
1309
EMP_NAME
-----------veera
suresh
You can see that we connected to a user "veera", created a table "emp" and inserted rows in to it.
ON Standby Database:
-------------------connect to the standby database and check whether the table has been replicated or not.
SQL> conn sys/oracle@sdb as sysdba
Connected.
SQL> archive log list
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
/vol2/sdb/arch
Oldest online log sequence
25
Next log sequence to archive
0
Current log sequence
27
SQL> select * from veera.emp;
EMPID
---------1111
1309
EMP_NAME
-----------veera
suresh
From the above we can see that the data has been replicated to the standby database from the primary
database.
On Primary Database:
-------------------Insert in to the same table two more rows.
SQL> insert into emp values(&empid,'&emp_name');
Enter value for empid: 1234
Enter value for emp_name: mannoj
old
1: insert into emp values(&empid,'&emp_name')
new
1: insert into emp values(1234,'mannoj')
1 row created.
SQL> insert into emp values(&empid,'&emp_name');
Enter value for empid: 9876
Enter value for emp_name: thiyagu
old
1: insert into emp values(&empid,'&emp_name')
new
1: insert into emp values(9876,'thiyagu')
1 row created.
SQL> commit;
Commit complete.
SQL> select * from veera.emp;
EMPID
---------1111
1309
1234
9876
EMP_NAME
-----------veera
suresh
mannoj
thiyagu
Archive Mode
Enabled
/vol1/pdb/arch
26
28
28
Now remove this archivelog file physically from the production database.
SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mode
Enabled
/vol1/pdb/arch
26
28
28
Archive Mode
Enabled
/vol1/pdb/arch
27
29
29
ON Standby Database:
-------------------The archivelog file with sequence# 27 will be moved to standby database. Since the media recovery
process has been canceled the archivelog will not be applied to the standby database.
Now remove that archivelog with sequence# 27 physically from standby server also.
Once after deleting the archivelog file from both production and standby database servers, enable the
media recovery process in standby database.
alter database recover managed standby database disconnect from session;
SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mo
Enabled
/vol2/sdb/arch
26
0
28
EMP_NAME
-----------veera
suresh
1309 suresh
SQL> archive log list
Database log mode
Archive Mo
Automatic archival
Enabled
Archive destination
/vol2/sdb/arch
Oldest online log sequence
26
Next log sequence to archive
0
Current log sequence
28
SQL>
SQL>
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> archive log list
Database log mode
Archive Mo
Automatic archival
Enabled
Archive destination
/vol2/sdb/arch
Oldest online log sequence
27
Next log sequence to archive
0
Current log sequence
29
SQL>
SQL>
SQL> archive log list
Database log mode
Archive Mo
Automatic archival
Enabled
Archive destination
/vol2/sdb/arch
Oldest online log sequence
27
Next log sequence to archive
0
Current log sequence
29
SQL>
SQL>
SQL>
SQL> select sequence#,archived,applied from v$archived_log;
SEQUENCE#
---------2
3
4
5
6
7
8
9
10
11
12
ARC
--YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
APPLIED
--------YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
SEQUENCE#
---------13
14
15
16
17
18
19
20
21
22
23
ARC
--YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
APPLIED
--------YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
24
25
26
27
28
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
27 rows selected.
SQL> select * from veera.emp;
EMPID
---------1111
1309
EMP_NAME
-----------veera
suresh
From the above we can clearly see that there is an archival gap sequence# 27 has not been applied to
the standby database. But the archivelogs are moving to the standby database location but not
applying.
ON Primary Database:
-------------------SQL> insert into veera.emp values(&empid,'&emp_name');
Enter value for empid: 2345
Enter value for emp_name: vivek
old
1: insert into veera.emp values(&empid,'&emp_name')
new
1: insert into veera.emp values(2345,'vivek')
1 row created.
SQL> insert into veera.emp values(&empid,'&emp_name');
Enter value for empid: 3456
Enter value for emp_name: shek
old
1: insert into veera.emp values(&empid,'&emp_name')
new
1: insert into veera.emp values(3456,'shek')
1 row created.
SQL> commit;
Commit complete.
SQL> select * from veera.emp;
EMPID
---------1111
1309
1234
9876
2345
3456
EMP_NAME
-----------veera
suresh
mannoj
thiyagu
vivek
shek
6 rows selected.
SQL> alter system switch logfile;
System altered.
SQL> select * from veera.emp;
EMPID
---------1111
1309
1234
9876
2345
3456
EMP_NAME
-----------veera
suresh
mannoj
thiyagu
vivek
shek
6 rows selected.
On Standby Database:
-------------------SQL> select * from veera.emp;
EMPID
---------1111
1309
EMP_NAME
-----------veera
suresh
SEQUENCE#
---------2
3
4
5
6
7
8
9
10
11
12
ARC
--YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
APPLIED
--------YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
SEQUENCE#
---------13
14
15
16
17
18
19
20
21
22
23
ARC
--YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
APPLIED
--------YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
SEQUENCE#
---------24
25
26
27
28
29
ARC
--YES
YES
YES
YES
YES
YES
APPLIED
--------YES
YES
YES
NO
NO
NO
28 rows selected.
SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mode
Enabled
/vol2/sdb/arch
28
0
30
Overall Scenario:
----------------Archivelog with sequence# 27 is missing from primary and also from standby database. Due to this
there is an archival gap between primary database and standby database. The synchronization between
primary database and standby database has been lost.
We have to recover / resync the standby database with the primary database.
The steps to resync the standby database using an incremental RMAN backup from the primary database
are as follows.
---------------------------------------------------------------------------------------------------1. Get the current scn of the standby database.,
SQL> select current_scn from v$database;
CURRENT_SCN
----------1053647
2. Connect to the primary database as the RMAN target and create an incremental backup from the
current SCN (for a standby
lagging far behind the primary):
primary:/vol1 />rman catalog rman/rman@pdb target sys/oracle@pdb
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Mar 13 15:54:00 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates.
connected to target database: PDB (DBID=3232692579)
connected to recovery catalog database
Archive Mode
Enabled
/vol1/pdb/arch
31
33
33
ON Standby :
-----------SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mode
Enabled
/vol2/sdb/arch
31
0
33
j. Cancel the recovery mode in Standby Database and open the database for read only access. Start the
media recovery process.
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> select sequence#,archived,applied from v$archived_log;
SEQUENCE# ARC APPLIED
---------- --- --------32 YES YES
ON Primary Database:
-------------------SQL> alter system switch logfile;
System altered.
SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mode
Enabled
/vol1/pdb/arch
31
33
33
ON Standby Database:
-------------------SQL> select sequence#,archived,applied from v$archived_log;
SEQUENCE#
---------32
33
ARC
--YES
YES
APPLIED
--------YES
NO
ARC
--YES
YES
APPLIED
--------YES
NO
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select sequence#,archived,applied from v$archived_log;
SEQUENCE#
---------32
33
ARC
--YES
YES
APPLIED
--------YES
IN-MEMORY
ARC
--YES
YES
APPLIED
--------YES
YES
Archive Mode
Enabled
/vol1/pdb/arch
32
34
34
ON Standby Database:
-------------------SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
Archive Mode
Enabled
/vol2/sdb/arch
32
0
34
From the above check, we can clearly see that both primary and standby databases are in sync.