Question :
While recovering database how can we know that upto how much archives we have to apply for getting the database sync(sync all datafiles headers with same SCN).
Where I can get the info while recovering the database;
Answer :
It depends on failure scenario , the two scenario comes into mind and not able to claim that in others scenario what happened.The following two scenario here.
Scenario 1
I lost all data file but my control file is intact at the same location where it was , before lost datafiles i have backed up the data files, controlfile and archive logs.
If you are just restoring the data files and not control files then you may know how much archive log sequence required for yours recovery after the backup taken using archived log repository.
RMAN> backup database;
Starting backup at 02-OCT-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=128 device type=DISK
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=/u01/app/oracle/oradata/his/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/his/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/his/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/his/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-OCT-09
channel ORA_DISK_1: finished piece 1 at 02-OCT-09
piece handle=/u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T112226_5dc712wg_.bkp tag=TAG20091002T112226 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 02-OCT-09
Starting Control File and SPFILE Autobackup at 02-OCT-09
piece handle=/u01/app/oracle/flash_recovery_area/HIS/autobackup/2009_10_02/o1_mf_s_699189791_5dc72j13_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 02-OCT-09
RMAN> sql 'alter system archive log current';
using target database control file instead of recovery catalog
sql statement: alter system archive log current
RMAN> sql 'alter system archive log current';
sql statement: alter system archive log current
RMAN> sql 'alter system archive log current';
sql statement: alter system archive log current
RMAN> exit
Recovery Manager complete.
[oracle@khurram his]$ sqlplus / as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Oct 2 11:24:04 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select name,sequence#
2 from v$archived_log
3 where status='A'
4 /
NAME SEQUENCE#
-------------------------------------------------------------------------------- ----------
/u01/app/oracle/product/11.1.0/db_1/dbs/arch1_2_699187272.dbf 2
/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_2_5dc73qw2_.arc 2
/u01/app/oracle/product/11.1.0/db_1/dbs/arch1_3_699187272.dbf 3
/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_3_5dc73vgm_.arc 3
/u01/app/oracle/product/11.1.0/db_1/dbs/arch1_4_699187272.dbf 4
/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_4_5dc740d7_.arc 4
6 rows selected.
You may know if yours control file intact (not lost or restored from backup), you may know how much recovery will go so far by knowing archived logs repository.From above v$archived_log archveilog repository you are seeing that after backup there are sequence required for the archive logs are 2,3 and 4 for recovering the restored backup which you have taken as above.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@khurram his]$ cd /u01/app/oracle/oradata/his/*.dbf
bash: cd: /u01/app/oracle/oradata/his/sysaux01.dbf: Not a directory
[oracle@khurram his]$ rm -rf /u01/app/oracle/oradata/his/*.dbf
[oracle@khurram his]$ sqlplus / as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Oct 2 11:28:01 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1620115456 bytes
Fixed Size 2144864 bytes
Variable Size 922748320 bytes
Database Buffers 687865856 bytes
Redo Buffers 7356416 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@khurram his]$ rman target /
Recovery Manager: Release 11.1.0.6.0 - Production on Fri Oct 2 11:29:30 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: HIS (DBID=3219691467, not open)
RMAN> restore database;
Starting restore at 02-OCT-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=154 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 /u01/app/oracle/oradata/his/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/his/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/his/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/his/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T112226_5dc712wg_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T112226_5dc712wg_.bkp tag=TAG20091002T112226
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 02-OCT-09
RMAN> recover database;
Starting recover at 02-OCT-09
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_2_5dc73qw2_.arc
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_3_5dc73vgm_.arc
archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_4_5dc740d7_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_2_5dc73qw2_.arc thread=1 sequence=2
media recovery complete, elapsed time: 00:00:01
Finished recover at 02-OCT-09
as you can see that 2,3,4 were required during recovery process.
Scenario 2
I lost all data file as well control file , i have backed up the data files, controlfile and archive logs.
Its like a disatsre you lost alls data file and as well controlfile , if you backed the controlfile then remember during controlfile backup it will have file type flag 4 that tells Oracle it is a backup control file.
The Stop SCN for alls data file marked to 0xffff.ffffffff (infinity).File type flag in the backup control file tells to oracle that it cannot rely on its redo thread,which means recovering will go on and on , controlfile will not aware how much should i go for redo it will never stop if you are able to supply redo.
It will always ask you more subsequent redo if you already supplied to it during process that's why it let you open the database in reset logs.
Lets see after restoring the controlfile and datafiles , you will see SQL tool recovery mechanism ask you recover database using backup controlfile which shows that controlfile does not know where to end the applying redo chain.
Here an excerpt which shows that restored controlfile does not know till how long the redo should be applied, its the RMAN robustness which does not ask you manually to supply redo, RMAN search the alls redo from archivelogs and if possible you have redo within redo logs.
RMAN> connect target sys/sys
connected to target database: HIS (DBID=3219691467)
RMAN> configure controlfile autobackup on;
using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
RMAN> list backup;
RMAN>
RMAN> backup database;
Starting backup at 02-OCT-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
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=/u01/app/oracle/oradata/his/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/his/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/his/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/his/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-OCT-09
channel ORA_DISK_1: finished piece 1 at 02-OCT-09
piece handle=/u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T092724_5dc09dlc_.bkp tag=TAG20091002T092724 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 02-OCT-09
Starting Control File and SPFILE Autobackup at 02-OCT-09
piece handle=/u01/app/oracle/flash_recovery_area/HIS/autobackup/2009_10_02/o1_mf_s_699182899_5dc0c49t_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 02-OCT-09
RMAN> sql 'alter system archive log current';
sql statement: alter system archive log current
RMAN> sql 'alter system archive log current';
sql statement: alter system archive log current
RMAN> sql 'alter system archive log current';
sql statement: alter system archive log current
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 981.55M DISK 00:00:52 02-OCT-09
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20091002T092724
Piece Name: /u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T092724_5dc09dlc_.bkp
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 894968 02-OCT-09 /u01/app/oracle/oradata/his/system01.dbf
2 Full 894968 02-OCT-09 /u01/app/oracle/oradata/his/sysaux01.dbf
3 Full 894968 02-OCT-09 /u01/app/oracle/oradata/his/undotbs01.dbf
4 Full 894968 02-OCT-09 /u01/app/oracle/oradata/his/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 9.36M DISK 00:00:01 02-OCT-09
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20091002T092819
Piece Name: /u01/app/oracle/flash_recovery_area/HIS/autobackup/2009_10_02/o1_mf_s_699182899_5dc0c49t_.bkp
SPFILE Included: Modification time: 02-OCT-09
SPFILE db_unique_name: HIS
Control File Included: Ckp SCN: 894991 Ckp time: 02-OCT-09
RMAN> shutdown abort
Oracle instance shut down
RMAN> exit
Recovery Manager complete.
[oracle@khurram ~]$ rm -rf /u01/app/oracle/oradata/his/*
[oracle@khurram ~]$ rman target /
Recovery Manager: Release 11.1.0.6.0 - Production on Fri Oct 2 09:32:37 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
Oracle instance started
Total System Global Area 1620115456 bytes
Fixed Size 2144864 bytes
Variable Size 922748320 bytes
Database Buffers 687865856 bytes
Redo Buffers 7356416 bytes
RMAN> restore controlfile from autobackup;
Starting restore at 02-OCT-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=153 device type=DISK
recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: HIS
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/flash_recovery_area/HIS/autobackup/2009_10_02/o1_mf_s_699182899_5dc0c49t_.bkp found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/flash_recovery_area/HIS/autobackup/2009_10_02/o1_mf_s_699182899_5dc0c49t_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/his/control01.ctl
output file name=/u01/app/oracle/oradata/his/control02.ctl
output file name=/u01/app/oracle/oradata/his/control03.ctl
Finished restore at 02-OCT-09
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> restore database;
Starting restore at 02-OCT-09
Starting implicit crosscheck backup at 02-OCT-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=153 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 02-OCT-09
Starting implicit crosscheck copy at 02-OCT-09
using channel ORA_DISK_1
Finished implicit crosscheck copy at 02-OCT-09
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/HIS/autobackup/2009_10_02/o1_mf_s_699182899_5dc0c49t_.bkp
File Name: /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_5_5dc0d1m8_.arc
File Name: /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_3_5dc0cx6p_.arc
File Name: /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_4_5dc0czx3_.arc
using channel ORA_DISK_1
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 /u01/app/oracle/oradata/his/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/his/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/his/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/his/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T092724_5dc09dlc_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HIS/backupset/2009_10_02/o1_mf_nnndf_TAG20091002T092724_5dc09dlc_.bkp tag=TAG20091002T092724
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 02-OCT-09
[oracle@khurram ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Oct 2 09:34:51 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> recover database
ORA-00283: recovery session canceled due to errors
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done
Here come to RMAN and see that even alls archived log are still there for applying but due to restored controlfile from backup flag type 4 will ask you more and more redo log.
[oracle@khurram ~]$ rman target /
Recovery Manager: Release 11.1.0.6.0 - Production on Fri Oct 2 09:35:19 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: HIS (DBID=3219691467, not open)
RMAN> recover database
2> ;
Starting recover at 02-OCT-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=151 device type=DISK
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_3_5dc0cx6p_.arc
archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_4_5dc0czx3_.arc
archived log for thread 1 with sequence 5 is already on disk as file /u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_5_5dc0d1m8_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_3_5dc0cx6p_.arc thread=1 sequence=3
archived log file name=/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_4_5dc0czx3_.arc thread=1 sequence=4
archived log file name=/u01/app/oracle/flash_recovery_area/HIS/archivelog/2009_10_02/o1_mf_1_5_5dc0d1m8_.arc thread=1 sequence=5
unable to find archived log
archived log thread=1 sequence=6
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/02/2009 09:35:26
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 6 and starting SCN of 895024
Ulimately you have to open the database with resetlog.