Sunday, May 17, 2015

How to approach RMAN error  "UNTIL CHANGE is before RESETLOGS change"

A problem simulation and solution approach :-
First take your full database backup including archivelogs of your database,

RMAN> backup database plus archivelog;
Starting backup at 05-FEB-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=8 RECID=39 STAMP=870706643
channel ORA_DISK_1: starting piece 1 at 05-FEB-15
channel ORA_DISK_1: finished piece 1 at 05-FEB-15
piece handle=C:\RMAN\11PUH46H_1_1 tag=TAG20150205T145721 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=40 STAMP=870879410
input archived log thread=1 sequence=2 RECID=41 STAMP=870879441
channel ORA_DISK_1: starting piece 1 at 05-FEB-15
channel ORA_DISK_1: finished piece 1 at 05-FEB-15
piece handle=C:\RMAN\12PUH46I_1_1 tag=TAG20150205T145721 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 05-FEB-15
Starting backup at 05-FEB-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=C:\ORADATA\DB11\SYSTEM01.DBF
input datafile file number=00002 name=C:\ORADATA\DB11\SYSAUX01.DBF
input datafile file number=00003 name=C:\ORADATA\DB11\UNDOTBS01.DBF
input datafile file number=00004 name=C:\ORADATA\DB11\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 05-FEB-15
channel ORA_DISK_1: finished piece 1 at 05-FEB-15
piece handle=C:\RMAN\13PUH46M_1_1 tag=TAG20150205T145726 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
Finished backup at 05-FEB-15
Starting backup at 05-FEB-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=42 STAMP=870879532
channel ORA_DISK_1: starting piece 1 at 05-FEB-15
channel ORA_DISK_1: finished piece 1 at 05-FEB-15
piece handle=C:\RMAN\14PUH49C_1_1 tag=TAG20150205T145852 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-FEB-15
Starting Control File and SPFILE Autobackup at 05-FEB-15
piece handle=C:\RMAN\C-1400701463-20150205-00 comment=NONE
Finished Control File and SPFILE Autobackup at 05-FEB-15
RMAN> exit
Recovery Manager complete.

Create some objects and do some action(DML and DDL) and note down the respective SCN after every statement.
C:\Users\mahekarthya>sqlplus sys as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 5 15:04:36 2015
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
SQL> create
2 table test
3 as select * from
4 all_objects;
Table created.
SQL> select
2 current_scn
3 from
4 v$database;
CURRENT_SCN
-----------
1045503 -------------------- SCN Before delete
SQL> delete from test;
68604 rows deleted.
SQL> commit;
Commit complete.
SQL>
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
1048517 --------------------- SCN after delete
SQL> drop table test;
Table dropped.
SQL>
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
1048584
SQL>
SQL> alter system switch logfile;
System altered.
SQL>
SQL> select incarnation#, resetlogs_change#,status from v$database_incarnation;
INCARNATION# RESETLOGS_CHANGE# STATUS
------------ ----------------- -------
1 1 PARENT
2 834328 PARENT
3 838675 PARENT
4 1026219 PARENT
5 1028060 CURRENT --------- 1028060 is the CURRENT RESETLOGS_CHANGE#
SQL>
shutdown immediate
SQL>
C:\Users\mahekarthya>rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Feb 5 15:26:01 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> run
2> {
3> startup mount;
4> set until scn=1048517; -----recovering to a point after delete statement is fired.
5> restore database;
6> recover database;
7> }
Oracle instance started
database mounted
Total System Global Area 626327552 bytes
Fixed Size 2178336 bytes
Variable Size 478151392 bytes
Database Buffers 138412032 bytes
Redo Buffers 7585792 bytes
executing command: SET until clause
Starting restore at 05-FEB-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=133 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to C:\ORADATA\DB11\SYSTEM01.DBF
channel ORA_DISK_1: restoring datafile 00002 to C:\ORADATA\DB11\SYSAUX01.DBF
channel ORA_DISK_1: restoring datafile 00003 to C:\ORADATA\DB11\UNDOTBS01.DBF
channel ORA_DISK_1: restoring datafile 00004 to C:\ORADATA\DB11\USERS01.DBF
channel ORA_DISK_1: reading from backup piece C:\RMAN\13PUH46M_1_1
channel ORA_DISK_1: piece handle=C:\RMAN\13PUH46M_1_1 tag=TAG20150205T145726
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 05-FEB-15
Starting recover at 05-FEB-15
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 05-FEB-15
RMAN> alter database open resetlogs;
database opened
RMAN>
As we opened the database using the resetlogs option, a new incarnation has been created. Below, is the new incarnation and the recovered table:
SQL> select incarnation#, resetlogs_change#,status from v$database_incarnation;
INCARNATION# RESETLOGS_CHANGE# STATUS
------------ ----------------- -------
1 1 PARENT
2 834328 PARENT
3 838675 PARENT
4 1026219 PARENT
5 1028060 PARENT --------- 1028060 became PARENT
6 1048518 CURRENT --------- & 1048518 became CURRENT(one SCN higher than what we provided in until SCN ,ie 1048517+1
6 rows selected.
SQL> select * from test;
no rows selected
SQL>
After this operation, I tried to recover the database up to the delete command(ie state before delete command has been fired against the table) issued as follows:
SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
C:\Users\mahekarthya>rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Feb 5 15:39:23 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> run
2> {
3> startup mount;
4> set until scn=1045503;
5> restore database;
6> recover database;
7> }
Oracle instance started
database mounted
Total System Global Area 626327552 bytes
Fixed Size 2178336 bytes
Variable Size 478151392 bytes
Database Buffers 138412032 bytes
Redo Buffers 7585792 bytes
executing command: SET until clause
Starting restore at 05-FEB-15
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 02/05/2015 15:40:47
RMAN-20208: UNTIL CHANGE is before RESETLOGS change
RMAN>

I got this error , because I am trying to recover my database to a SCN(1045503) ie lower than the CURRENT resetlog SCN(1048518 ).Now I checked the list of all the database incarnations from RMAN, and I resets the database to the previous incarnation and performs an incomplete recovery as follows:
RMAN> list incarnation of database;
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 1 DB11 1400701463 PARENT 1 13-JAN-15
2 2 DB11 1400701463 PARENT 834328 14-JAN-15
3 3 DB11 1400701463 PARENT 838675 14-JAN-15
4 4 DB11 1400701463 PARENT 1026219 03-FEB-15
5 5 DB11 1400701463 PARENT 1028060 04-FEB-15
6 6 DB11 1400701463 CURRENT 1048518 05-FEB-15
RMAN> shutdown immediate;
database dismounted
Oracle instance shut down
RMAN> startup mount
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 626327552 bytes
Fixed Size 2178336 bytes
Variable Size 478151392 bytes
Database Buffers 138412032 bytes
Redo Buffers 7585792 bytes
RMAN> reset database to incarnation 5;
database reset to incarnation 5
RMAN> run
2> {
3> set until scn=1045503;
4> restore database;
5> recover database;
6> }
executing command: SET until clause
Starting restore at 05-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=133 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to C:\ORADATA\DB11\SYSTEM01.DBF
channel ORA_DISK_1: restoring datafile 00002 to C:\ORADATA\DB11\SYSAUX01.DBF
channel ORA_DISK_1: restoring datafile 00003 to C:\ORADATA\DB11\UNDOTBS01.DBF
channel ORA_DISK_1: restoring datafile 00004 to C:\ORADATA\DB11\USERS01.DBF
channel ORA_DISK_1: reading from backup piece C:\RMAN\13PUH46M_1_1
channel ORA_DISK_1: piece handle=C:\RMAN\13PUH46M_1_1 tag=TAG20150205T145726
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 05-FEB-15
Starting recover at 05-FEB-15
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file C:\ORADATA\DB11\ARCHIVE\LOG
archived log for thread 1 with sequence 4 is already on disk as file C:\ORADATA\DB11\ARCHIVE\LOG
archived log file name=C:\ORADATA\DB11\ARCHIVE\LOG1_3_870795195.ARC thread=1 sequence=3
archived log file name=C:\ORADATA\DB11\ARCHIVE\LOG1_4_870795195.ARC thread=1 sequence=4
media recovery complete, elapsed time: 00:00:02
Finished recover at 05-FEB-15
RMAN> alter database open resetlogs;
database opened
RMAN> list incarnation of database;
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 1 DB11 1400701463 PARENT 1 13-JAN-15
2 2 DB11 1400701463 PARENT 834328 14-JAN-15
3 3 DB11 1400701463 PARENT 838675 14-JAN-15
4 4 DB11 1400701463 PARENT 1026219 03-FEB-15
5 5 DB11 1400701463 PARENT 1028060 04-FEB-15
7 7 DB11 1400701463 CURRENT 1045504 05-FEB-15
6 6 DB11 1400701463 ORPHAN 1048518 05-FEB-15
RMAN> exit
Recovery Manager complete.
C:\Users\mahekarthya>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 5 15:48:08 2015
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(1) from test;
COUNT(1)
----------
68604
SQL>

The table recovered to the previous incarnation successfully and a new incarnation has been created.

No comments:

Post a Comment