source :
http://dba-oracle.com/bk_recover_database_until_cancel_tips.htm
http://www.dba-oracle.com/t_oracle_open_resetlogs_tips.htm
Problem: How do I recover until cancel with Oracle when doing a roll forward?
Can someone explain why it is necessary to perform "recover database until cancel" before using "alter database open resetlogs" when you are restoring a cold backup without a backup of the redo log files ?
Solution: The Oracle documentation notes:
It is possible for RMAN to restore backups from direct ancestor incarnations and recover up to the current time as long as a continuous path of archived logs exists from the earliest backups to the desired point of recovery. This holds true even across OPEN RESETLOGS operations.
Under certain circumstances RMAN can also perform restore and recovery with orphaned backups via the restoration of a control file from an appropriate incarnation.
http://dba-oracle.com/bk_recover_database_until_cancel_tips.htm
http://www.dba-oracle.com/t_oracle_open_resetlogs_tips.htm
Problem: How do I recover until cancel with Oracle when doing a roll forward?
Can someone explain why it is necessary to perform "recover database until cancel" before using "alter database open resetlogs" when you are restoring a cold backup without a backup of the redo log files ?
I perform the following steps, which I thought would be very simple, however I get an error on opening the database.
SHUTDOWN IMMEDIATE
Restore all backup datafiles and controlfiles (OS copy)
STARTUP MOUNT
ALTER DATABASE OPEN RESETLOGS
ORA-01139: RESETLOGS option only valid after an incomplete database recovery
So I tried using:
RECOVER DATABASE UNTIL CANCEL
ALTER DATABASE OPEN RESETLOGS
Restore all backup datafiles and controlfiles (OS copy)
STARTUP MOUNT
ALTER DATABASE OPEN RESETLOGS
ORA-01139: RESETLOGS option only valid after an incomplete database recovery
So I tried using:
RECOVER DATABASE UNTIL CANCEL
ALTER DATABASE OPEN RESETLOGS
And this works, the database is opened and the new redo logs are created.
I got a trace of my controlfile and found the following..
CREATE CONTROLFILE REUSE DATABASE "TEST" NORESETLOGS NOARCHIVEMODE .....
I think it is no NORESETLOGS that is causing the problem as if I re-create the control file with RESETLOGS specified it works fine.
CREATE CONTROLFILE REUSE DATABASE "TEST" NORESETLOGS NOARCHIVEMODE .....
I think it is no NORESETLOGS that is causing the problem as if I re-create the control file with RESETLOGS specified it works fine.
Solution: The Oracle documentation notes:
"In cancel-based recovery, recovery proceeds by prompting you with the suggested filenames of archived redo log files. Recovery stops when you specify
CANCEL
instead of a filename or when all redo has been applied to the datafiles.
Cancel-based recovery is better than change-based or time-based recovery if you want to control which archived log terminates recovery. For example, you may know that you have lost all logs past sequence 1234, so you want to cancel recovery after log 1233 is applied.
You should perform cancel-based media recovery in these stages:
- Prepare for recovery by backing up the database and correct any media failures as described in "Preparing for Incomplete Recovery".
- Restore backup datafiles as described in "Restoring Datafiles Before Performing Incomplete Recovery". If you have a current control file, then do not restore a backup control file.
- Perform media recovery on the restored database backup as described in the following procedure.
To perform cancel-based recovery:
- Start SQL*Plus and connect to Oracle with administrator privileges. For example, enter:% sqlplus '/ AS SYSDBA'
- Start a new instance and mount the database:
- Begin cancel-based recovery by issuing the following command:RECOVER DATABASE UNTIL CANCEL
If you are using a backup control file with this incomplete recovery, then specify theUSING
BACKUP
CONTROLFILE
option in theRECOVER
command.
- Oracle applies the necessary redo log files to reconstruct the restored datafiles. Oracle supplies the name it expects to find from
LOG_ARCHIVE_DEST_1
and requests you to stop or proceed with applying the log file. Note that if the control file is a backup, then you must supply the names of the online logs if you want to apply the changes in these logs.
- Continue applying redo log files until the last log has been applied to the restored datafiles, then cancel recovery by executing the following command:
CANCEL
Oracle returns a message indicating whether recovery is successful. Note that if you cancel recovery before all the datafiles have been recovered to a consistent SCN and then try to open the database, you will get anORA-1113
error if more recovery is necessary for the file. You can queryV$RECOVER_FILE
to determine whether more recovery is needed, or if a backup of a datafile was not restored prior to starting incomplete recovery.
- Open the database in
RESETLOGS
mode. You must always reset the online logs after incomplete recovery or recovery with a backup control file. For example, enter:ALTER DATABASE OPEN RESETLOGS;"
Oracle RMAN Simplified Recovery Through OPEN RESETLOGS
Following an incomplete point-in-time recovery or recovery without a backup control file, it will be necessary to open the database with the OPEN RESETLOGS option as follows:
SQL> alter database open resetlogs;
The OPEN RESETLOGS operation creates a new incarnation of the database, resets the log sequence to 1 and online redo logs are given a new time stamp and SCN. Prior to Oracle 10g, the newly generated redo log files could not be used with the backups taken in the past. Therefore, it was historically important to take an immediate backup as all previous backups became invalid. Using OPEN RESETLOGS can negate the need for that backup.
Without the use of OPEN RESETLOGS, when using the RMAN catalog for future backups, the following command had to be issued to make the RMAN catalog aware of the new incarnation of the database.
RMAN> reset database;
As of Oracle 10g, it is no longer necessary to back up the database following an incomplete recovery and OPEN RESETLOGS operations.
The OPEN RESETLOGS feature is also applicable for the following two scenarios:
- Performing a recovery using a backup control file and opening the database with the RESETLOGS operation.
- Reinstantiation of the old primary database following a failover
It is possible for RMAN to restore backups from direct ancestor incarnations and recover up to the current time as long as a continuous path of archived logs exists from the earliest backups to the desired point of recovery. This holds true even across OPEN RESETLOGS operations.
Under certain circumstances RMAN can also perform restore and recovery with orphaned backups via the restoration of a control file from an appropriate incarnation.
“there is a copy of the header block in the 510th block…”.
If I’m not mistaken in ASM version 11.1.0.7 and later the second last block from allocation unit 1 is KFBTYP_DISKHEAD ( the backup copy of the ASM disk header ) !!!
By default you will get 510th block
kfdhdb.blksize: 4096
kfdhdb.ausize: 1048576
and (1048576 / 4096) * 2 – 1 = 511. The first block is 0 so you get 510th block.
Thanks to Bane Radulović )))
Indeed, in my case, it was the 510th block (or the second last block from allocation unit 1)
I have updated the post with the correct formula and the reference to Bane’s blog
Thanks.
[oracle@rac1 ~]$ echo $blksize
4096
[oracle@rac1 ~]$ ausize=`kfed read /dev/oracleasm/disks//DISK1 | grep ausize | tr -s ‘ ‘ | cut -d’ ‘ -f2`
[
[oracle@rac1 ~]$ echo $ausize
1048576
[oracle@rac1 ~]$ let n=$ausize/$blksize-2
[oracle@rac1 ~]$ echo $n
254
[oracle@oel ~]$ let n=$firstau+$ausize/$blksize-1
[oracle@oel ~]$ kfed read /dev/oracleasm/disks/ASM1 ausz=$ausize blkn=$n | grep KFBTYP
kfbh.type: 1 ; 0x002: KFBTYP_DISKHEAD
[oracle@oel ~]$ echo $n
510
[oracle@oel ~]$ kfed read /dev/oracleasm/disks/ASM1 ausz=$ausize aun=0 blkn=$n | grep KFBTYP
kfbh.type: 1 ; 0x002: KFBTYP_DISKHEAD
[oracle@rac1 ~]$
[oracle@rac1 ~]$ echo $ausize
1048576
[oracle@rac1 ~]$ blksize=`kfed read /dev/oracleasm/disks/DISK1 | grep blksize | tr -s ‘ ‘ | cut -d’ ‘ -f2`
[oracle@rac1 ~]$ echo $blksize
4096
[oracle@rac1 ~]$ let firstau=$ausize/$blksize-1
[oracle@rac1 ~]$ echo $firstau
255
– first AU is indexed from 0 to 255. In this AU, the header block is located on the AUN=0 (default in kfed), at the relative block# 0
– Next AU is indexed from 0 to 255 (absolute index: 256 to 511, but in absolute: 257th to 512th block). So the second last block is accessible in the AUN=1 in the relative block= 254 (or absolute 510). And the last block contains the heartbeat block
See above with a relative block number in the AU:
[oracle@oel ~]$ kfed read /dev/oracleasm/disks/ASM1 aun=1 ausz=$ausize blkn=254 | grep KFBTYP
kfbh.type: 1 ; 0x002: KFBTYP_DISKHEAD
[oracle@oel ~]$ kfed read /dev/oracleasm/disks/ASM1 aun=1 ausz=$ausize blkn=255 | grep KFBTYP
kfbh.type: 19 ; 0x002: KFBTYP_HBEAT
[oracle@oel ~]$ kfed read /dev/oracleasm/disks/ASM1 ausz=$ausize blkn=510 | grep KFBTYP
kfbh.type: 1 ; 0x002: KFBTYP_DISKHEAD
[oracle@oel ~]$ kfed read /dev/oracleasm/disks/ASM1 ausz=$ausize blkn=511 | grep KFBTYP
kfbh.type: 19 ; 0x002: KFBTYP_HBEAT
Regards
Sachin
Of course, it’s at your own risk, because at this level, Oracle won’t support you.