RESETLOGS and Reset of the Incarnation of the Database
RESETLOGS and Reset of the Incarnation of the Database
ld not be used with the backups taken before the RESETLOGS was performed.
Therefore, whenever a resetlogs was done, it was important to take an immediate full database b
ackup, since all previous backups became invalid.
• Archives the current online redo logs (if they are accessible) and then erases the cont
ents of the online redo logs and resets the log sequence number to 1.
• Creates the online redo log files if they do not currently exist.
• Updates all current datafiles and online redo logs and all subsequent archived redo log
s with a new RESETLOGS SCN and time stamp
Important:
To perform recovery through RESETLOGS you must have all archived logs generated after the most
recent backup.
Oracle 10g introduces a new format specification for archived log files. This new format avoids
overwriting archived redo log files with the same sequence number across incarnations.
The format specification of the log_archive_format string "%"r represents the resetlogs id. It
will ensure that a unique name is constructed for the archived redo log file during RMAN resto
re and as well as restoring via SQL*plus auto recovery mode.
Note: The database would not start if you remove the %r from the log archive format specificati
on.
What is an incarnation?
A database incarnation is created whenever you open the database with the RESETLOGS option.
The Current incarnation is the one in which the database is running at present
The incarnation from which the current incarnation branched after a ALTER DATABASE OPEN RESETLO
GS was performed is called the Parent incarnation.
If you want to go back to some SCN which is not part of the Current database incarnation, we ne
ed to use the RESET DATABASE TO INCARNATION
command as shown in the example below
An incarnation helps to identify redo streams which have the same SCN, but occurred at differen
t points in time. This prevents the possibility of applying the wrong archive log file from a p
revious incarnation which could corrupt the database.
Suppose we are at incarnation 1 and are at SCN 100 in the database. I do a resetlogs and now th
e incarnation of the database becomes 2. Suppose we do another resetlogs and it so happens that
the SCN at the time we did the resetlogs was also 100. Somewhere down the line later we want
to do a point in time recovery and want to recover the database until SCN 100. How does Oracle
know which is the correct SCN and how far back in time should the database be rolled back to a
nd which archive logs need to be applied?
This is where incarnations come in and we will see how we can set the database to a particular
incarnation to enable RMAN to do a point in time recovery.
Example
Let us now run the LIST INCARNATION OF DATABASE command from RMAN and this is the output.
CURRENT_SCN
-----------
991395
Now, let us make a change in the database which we will then try to undo by restoring and reco
vering the database to a point in time before the media failure or as in this case, a wrong tra
nsaction has happened.
SQL> conn sh/sh
Connected.
COUNT(*)
----------
918843
SQL> commit;
Commit complete.
COUNT(*)
----------
917843
We now will roll the database back to an SCN before the delete operation was performed.
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> run {
2> set until scn 991395;
3> restore database;
4> recover database;
5> }
….
….
database opened
We can now see that the deleted rows have been recovered and the number of rows in the table is
now the same as before the delete operation was performed.
COUNT(*)
----------
918843
The alert log of the database will also log this resetlogs operation and we will see lines the
ones shown below:
SQL> commit;
Commit complete.
COUNT(*)
----------
908843
Now, let us shutdown the database, startup and mount it and try the same incomplete recovery wh
ich we tried earlier until the SCN 991395
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> run {
2> set until scn 991395;
3> restore database;
4> recover database;
5> }
We get the error RMAN-20208 because since the current incarnation of the database is 3 and we t
rying to go to an SCN before this incarnation.
For this to happen, we need to change the current incarnation (3) of the database to an older i
ncarnation (2). The SCN 993195 was present during the incarnation 2.
After resetting the incarnation to 2, we now see that the restore is proceeding fine.
RMAN> run {
2> set until scn 991395;
3> restore database;
4> recover database;
5> }
archived log for thread 1 with sequence 4 is already on disk as file /u01/oradata/TEST11G/arch/
1_4_764845989.arch
archived log for thread 1 with sequence 5 is already on disk as file /u01/oradata/TEST11G/arch/
1_5_764845989.arch
archived log file name=/u01/oradata/TEST11G/arch/1_4_764845989.arch thread=1 sequence=4
archived log file name=/u01/oradata/TEST11G/arch/1_5_764845989.arch thread=1 sequence=5
media recovery complete, elapsed time: 00:00:00
Finished recover at 18-OCT-11
Now we open the database with the ALTER DATABASE OPEN RESETOGS command and see that a new incar
nation key (4) has been allocated to the database as the CURRENT incarnation and the previous i
ncarnation (3) has become an ORPHAN incarnation.
The incarnation key 5 now is the CURRENT incarnation of the database, and incarnations 3 and 4
both have become ORPHAN.
The current SCN now is 991734
CURRENT_SCN
-----------
991734
What happens if we change the structure of the database? And we do not take any new backup aft
er this change was made, but try and recover using a backup before we had changed the structure
of the database. We add another datafile to the USERS tablespace. So the current control file
has knowledge of the fact that the USERS tablespace now has not one, but two datafiles.
We now try and do the same delete of rows and try and go back to our old SCN 991395. At this po
int in time, the control file had only knowledge of the fact that the USERS tablespace has one
data file and not two and the restore and recovery process will not try to do anything with re
gards to the newly added datafile..
This is what we see in the alert log of the database. Note that datafile 6 which is the new dat
afile added is being taken offline and dropped because at SCN 991735, this datafile did not exi
st in the database.