I am an IT professional with 10 years of professional experience,I have good proficiency on Oracle technologies, and at last 2 years of my career to study Real Application Clusters,data guard and participate actively on Oracle community ,If you want to hire me on Contract or to quote on project basis contact me at khurrampc@hotmail.com.

Monday, October 12, 2009

Recovery Window

Setting RMAN recovery window to 2 days make any backup older than 2 days become obsolete is a myth. See below the scenario which make you understand what need to consider when you are setting RMAN recovery window.
For Non Incremental Level backup
================================

Assume no backup exist before 13th of Oct
Assume recovery window is 2
POR = Point of recoverability

-----------------------------------------------------------------------------------------------------------
date           backup type        status               POR (Current date-recovery window)
-----------------------------------------------------------------------------------------------------------
13-OCT-2009    Full backup        No obsolete found    13-OCT-2009-2 = 11-OCT-2009
15-OCT-2009    Full backup        No obsolete found    15-OCT-2009-2 = 13-OCT-2009
16-OCT-2009    Full backup        No obsolete found    16-OCT-2009-2 = 14-OCT-2009
See above table data on 16-OCT-2009 , POR is 14-OCT-2009 and you dont have any backup on 14th of oct within yours backup schedule, in this case 13th Oct backup will enable you POR of 14th Oct , 13th Oct backup will not be marked obsoleted What would be happen on 17th of october lets see
-----------------------------------------------------------------------------------------------------------
date           backup type        status               POR (Current date-recovery window=POR)
-----------------------------------------------------------------------------------------------------------
13-OCT-2009    Full backup        No obsolete found    13-OCT-2009-2 = 11-OCT-2009
15-OCT-2009    Full backup        No obsolete found    15-OCT-2009-2 = 13-OCT-2009
16-OCT-2009    Full backup        No obsolete found    16-OCT-2009-2 = 14-OCT-2009
17-OCT-2009    No   backup        13th Oct Full backup 17-OCT-2009-2 = 15-OCT-2009
                                  will be marked 
                                  obsoleted
See above table data on 17-OCT-2009 , POR is 15-OCT-2009 you have backup on 15th of oct within yours backup schedule, in this case 13th Oct backup will not be needed for the point of recoverability for 15th of Oct ,15th Oct backup already exist for the POR,15th Oct backup will provide you POR and hence 13th Oct backup will be marked obsoleted.
For Incremental Level backup
================================

Assume no backup exist before 13th of Oct
Assume recovery window is 2
POR = Point of recoverability

-----------------------------------------------------------------------------------------------------------
date           backup type   status               POR (Current date-recovery window)
-----------------------------------------------------------------------------------------------------------
13-OCT-2009    L0            No obsolete found    13-OCT-2009-2 = 11-OCT-2009
14-OCT-2009    L1            No obsolete found    14-OCT-2009-2 = 12-OCT-2009
15-OCT-2009    L1            No obsolete found    15-OCT-2009-2 = 13-OCT-2009
16-OCT-2009    L1            No obsolete found    16-OCT-2009-2 = 14-OCT-2009
See above table data on 16-OCT-2009 , POR is 14-OCT-2009 you have backup on 14th of oct within yours backup schedule but this backup is L1 not L0 , in this case 13th Oct backup will be needed for the point of recoverability for 14th of Oct ,13th Oct backup will not be marked obsoleted.
-----------------------------------------------------------------------------------------------------------
date           backup type   status               POR (Current date-recovery window)
-----------------------------------------------------------------------------------------------------------
13-OCT-2009    L0            No obsolete found    13-OCT-2009-2 = 11-OCT-2009
14-OCT-2009    L1            No obsolete found    14-OCT-2009-2 = 12-OCT-2009
15-OCT-2009    L1            No obsolete found    15-OCT-2009-2 = 13-OCT-2009
16-OCT-2009    L1            No obsolete found    16-OCT-2009-2 = 14-OCT-2009
17-OCT-2009    L1            No obsolete found    17-OCT-2009-2 = 15-OCT-2009
See above table data on 17-OCT-2009 , POR is 15-OCT-2009 you have backup on 15th of oct within yours backup schedule but this backup is L1 not L0 , in this case 13th Oct backup will be needed for the point of recoverability for 15th of Oct ,13th Oct backup will not be marked obsoleted yet.
-----------------------------------------------------------------------------------------------------------
date           backup type   status               POR (Current date-recovery window)
-----------------------------------------------------------------------------------------------------------
13-OCT-2009    L0            No obsolete found    13-OCT-2009-2 = 11-OCT-2009
14-OCT-2009    L1            No obsolete found    14-OCT-2009-2 = 12-OCT-2009
15-OCT-2009    L1            No obsolete found    15-OCT-2009-2 = 13-OCT-2009
16-OCT-2009    L1            No obsolete found    16-OCT-2009-2 = 14-OCT-2009
17-OCT-2009    L1            No obsolete found    17-OCT-2009-2 = 15-OCT-2009
18-OCT-2009    L1            No obsolete found    18-OCT-2009-2 = 16-OCT-2009
19-OCT-2009    L1            No obsolete found    19-OCT-2009-2 = 17-OCT-2009
20-OCT-2009    L0            No obsolete found    20-OCT-2009-2 = 18-OCT-2009
21-OCT-2009    No backup     No obsolete found    21-OCT-2009-2 = 19-OCT-2009
22-OCT-2009    No backup     obsolete found       22-OCT-2009-2 = 20-OCT-2009
                             13th L0 and its 
                             alls L1 
See above table data on 22-OCT-2009 , POR is 20-OCT-2009 you have L0 backup on 20th of oct within yours backup schedule and this backup is L0 not L1 , in this case 20th Oct backup will be needed for the point of recoverability for 20th of Oct ,before 20th L0 backup 13th L0 backup will marked obsoleted and hence alls its incremental level backup will be marked obsoleted.

Thursday, October 1, 2009

How much recovery required

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.

Tuesday, September 29, 2009

Backup Plus Archivleog

Question :

RMAN will do backup of current redolog by moving the log to archivelog if we did 'backup database plus archivelog'. Do RMAN will backup the redolog if the backup command is without archivelog?

Answer :

Whenever you backup archivelog log ,log switch occur for the current log.
SQL> select group#,status
  2    from v$log
  3  /

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT

RMAN> backup archivelog all;

Starting backup at 29-SEP-09
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=366 RECID=396 STAMP=698845462
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_annnn_TAG20090929T114422_5d3c69j7_.bkp tag=TAG20090929T114422 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-SEP-09

SQL> select group#,status
  2    from v$log
  3  /


    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 INACTIVE
         3 ACTIVE
You can see above that during archivelog backup process log switch occur.
SQL> select group#,status
  2    from v$log
  3  /

    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 INACTIVE
         3 ACTIVE

RMAN> backup database plus archivelog;


Starting backup at 29-SEP-09
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=367 RECID=398 STAMP=698845610
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_annnn_TAG20090929T114650_5d3cbxg3_.bkp tag=TAG20090929T114650 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-SEP-09

Starting backup at 29-SEP-09
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=/u01/app/oracle/oradata/mmi/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/mmi/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/mmi/undotbs03.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/mmi/users01.dbf
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_nnndf_TAG20090929T114654_5d3cc1yz_.bkp tag=TAG20090929T114654 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_ncsnf_TAG20090929T114654_5d3cdm4z_.bkp tag=TAG20090929T114654 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-SEP-09

Starting backup at 29-SEP-09
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=368 RECID=400 STAMP=698845668
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_annnn_TAG20090929T114748_5d3cdqpv_.bkp tag=TAG20090929T114748 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-SEP-09

SQL> select group#,status
  2    from v$log
  3  /


    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 ACTIVE
         3 CURRENT
As you can see "backup database plus archivelog" comes up with archivelog backup which inherit the log switch occurrence of archivelog backup.
SQL> select group#,status
  2    from v$log
  3  /

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 ACTIVE
         3 CURRENT


RMAN> backup database;

Starting backup at 29-SEP-09
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=/u01/app/oracle/oradata/mmi/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/mmi/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/mmi/undotbs03.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/mmi/users01.dbf
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_nnndf_TAG20090929T115013_5d3ck8jy_.bkp tag=TAG20090929T115013 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 29-SEP-09
channel ORA_DISK_1: finished piece 1 at 29-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_29/o1_mf_ncsnf_TAG20090929T115013_5d3clstc_.bkp tag=TAG20090929T115013 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-SEP-09


SQL> select group#,status
  2    from v$log
  3  /

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT
As you can only just backup database will not trigger a log switch. But keep in mind during online backup there may be some background process or some online users production activity cause massive redo which filled the redo within the span of backup process time and then trigger a log switch does not mean that "backup database" cause a log switch.

Wednesday, September 16, 2009

Recovered SCN

Question :
after performing recovery, how can we know till what time the target database is being recovered.

RMAN> backup database;

Starting backup at 16-SEP-09
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=/u01/app/oracle/oradata/mmi/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/mmi/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/mmi/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/mmi/mydatafile.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/mmi/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-SEP-09
channel ORA_DISK_1: finished piece 1 at 16-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_16/o1_mf_nnndf_TAG20090916T134511_5c19dv9q_.bkp tag=TAG20090916T134511 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 16-SEP-09

Starting Control File and SPFILE Autobackup at 16-SEP-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/autobackup/2009_09_16/o1_mf_s_697729560_5c19gcmc_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 16-SEP-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> shutdown abort
 
Oracle instance shut down

RMAN> exit

Recovery Manager complete.

[oracle@khurram ~]$ rm -rf /u01/app/oracle/oradata/mmi/*
[oracle@khurram ~]$ rman target /

Recovery Manager: Release 11.1.0.6.0 - Production on Wed Sep 16 13:47:35 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                721421728 bytes
Database Buffers             889192448 bytes
Redo Buffers                   7356416 bytes

RMAN> restore controlfile from autobackup;

Starting restore at 16-SEP-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: MMI
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/flash_recovery_area/MMI/autobackup/2009_09_16/o1_mf_s_697729560_5c19gcmc_.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/MMI/autobackup/2009_09_16/o1_mf_s_697729560_5c19gcmc_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/mmi/control01.ctl
output file name=/u01/app/oracle/oradata/mmi/control02.ctl
output file name=/u01/app/oracle/oradata/mmi/control03.ctl
Finished restore at 16-SEP-09

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1
From another terminal come at SQL
[oracle@khurram ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Wed Sep 16 13:49:14 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> set linesize 1000
SQL> select substr(name,1,50) fname,checkpoint_change#,last_change#,status
  2    from v$datafile;

FNAME                                              CHECKPOINT_CHANGE# LAST_CHANGE# STATUS
-------------------------------------------------- ------------------ ------------ -------
/u01/app/oracle/oradata/mmi/system01.dbf                      1350307              SYSTEM
/u01/app/oracle/oradata/mmi/sysaux01.dbf                      1350307              ONLINE
/u01/app/oracle/oradata/mmi/undotbs01.dbf                     1350307              ONLINE
/u01/app/oracle/oradata/mmi/users01.dbf                       1350307              ONLINE
/u01/app/oracle/oradata/mmi/mydatafile.dbf                    1350307              ONLINE
here you can see that within control file repository the data files START SCN (CHECKPOINT_SCHANGE#) is 1350307,whenever checkpoints occur, Oracle writes a START SCN to the data file headers as well it writes the START SCN within controlfile for each datafile.The control file also maintains another SCN value for each data file with START SCN is the STOP SCN, this STOP SCN is usually null (infinity) when yours database status is open and datafile status is online , the null status shows that recovery will start from START SCN and will goes to the end of redo thread.The STO SCN here is LAST_CHANGE#
RMAN> restore database;

Starting restore at 16-SEP-09
Starting implicit crosscheck backup at 16-SEP-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=152 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 16-SEP-09

Starting implicit crosscheck copy at 16-SEP-09
using channel ORA_DISK_1
Finished implicit crosscheck copy at 16-SEP-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/MMI/autobackup/2009_09_16/o1_mf_s_697729560_5c19gcmc_.bkp
File Name: /u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_1_5c19gzs5_.arc
File Name: /u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_2_5c19h2m0_.arc
File Name: /u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_3_5c19h4tk_.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/mmi/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/mmi/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/mmi/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/mmi/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/mmi/mydatafile.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_16/o1_mf_nnndf_TAG20090916T134511_5c19dv9q_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_16/o1_mf_nnndf_TAG20090916T134511_5c19dv9q_.bkp tag=TAG20090916T134511
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 16-SEP-09

SQL> select substr(name,1,50) fname,checkpoint_change#,last_change#,status
  2    from v$datafile;

FNAME                                              CHECKPOINT_CHANGE# LAST_CHANGE# STATUS
-------------------------------------------------- ------------------ ------------ -------
/u01/app/oracle/oradata/mmi/system01.dbf                      1350307              SYSTEM
/u01/app/oracle/oradata/mmi/sysaux01.dbf                      1350307              ONLINE
/u01/app/oracle/oradata/mmi/undotbs01.dbf                     1350307              ONLINE
/u01/app/oracle/oradata/mmi/users01.dbf                       1350307              ONLINE
/u01/app/oracle/oradata/mmi/mydatafile.dbf                    1350307              ONLINE
Now do recovery
RMAN> recover database;

Starting recover at 16-SEP-09
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_1_5c19gzs5_.arc
archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_2_5c19h2m0_.arc
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_3_5c19h4tk_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_1_5c19gzs5_.arc thread=1 sequence=1
archived log file name=/u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_2_5c19h2m0_.arc thread=1 sequence=2
archived log file name=/u01/app/oracle/flash_recovery_area/MMI/archivelog/2009_09_16/o1_mf_1_3_5c19h4tk_.arc thread=1 sequence=3
unable to find archived log
archived log thread=1 sequence=4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/16/2009 13:51:44
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 4 and starting SCN of 1350423

SQL> select substr(name,1,50) fname,checkpoint_change#,last_change#,status
  2    from v$datafile;

FNAME                                              CHECKPOINT_CHANGE# LAST_CHANGE# STATUS
-------------------------------------------------- ------------------ ------------ -------
/u01/app/oracle/oradata/mmi/system01.dbf                      1350423              SYSTEM
/u01/app/oracle/oradata/mmi/sysaux01.dbf                      1350423              ONLINE
/u01/app/oracle/oradata/mmi/undotbs01.dbf                     1350423              ONLINE
/u01/app/oracle/oradata/mmi/users01.dbf                       1350423              ONLINE
/u01/app/oracle/oradata/mmi/mydatafile.dbf                    1350423              ONLINE
Here you can see that within controlfile repositry there is datafile header START SCN which was 1350307 after restore,when you started recovery now its SCN is 1350423 which shows that yours recovery process start from SCN 1350307 and ends at 1350423.

Tuesday, September 15, 2009

coreletion between report need backup and retention policy

Question :

Daily i used take full backup using rman,after that when query report need backup it showing all datafile list, i don't understand how come it showing all the datafile list thought i take full backup please help me in this issues.

Answer :

It relates to yours retention policy if you would have retention policy to 2 and you have one backupsets of USERS tablespace then it will require one more for tablespace users to mature yours retention policy.

RMAN> list backup
2> ;


List of Backup Sets
===================


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
5       595.00K    DISK        00:00:03     15-SEP-09      
        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: TAG20090915T110249
        Piece Name: /u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_15/o1_mf_annnn_TAG20090915T110249_5bycjdm6_.bkp

  List of Archived Logs in backup set 5
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    17      1320409    15-SEP-09 1320963    15-SEP-09

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    1005.51M   DISK        00:01:14     15-SEP-09      
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20090915T110253
        Piece Name: /u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_15/o1_mf_nnndf_TAG20090915T110253_5bycjk2h_.bkp
  List of Datafiles in backup set 6
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1320969    15-SEP-09 /u01/app/oracle/oradata/mmi/system01.dbf
  2       Full 1320969    15-SEP-09 /u01/app/oracle/oradata/mmi/sysaux01.dbf
  3       Full 1320969    15-SEP-09 /u01/app/oracle/oradata/mmi/undotbs01.dbf
  4       Full 1320969    15-SEP-09 /u01/app/oracle/oradata/mmi/users01.dbf
  5       Full 1320969    15-SEP-09 /u01/app/oracle/oradata/mmi/mydatafile.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
7       10.00K     DISK        00:00:03     15-SEP-09      
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20090915T110412
        Piece Name: /u01/app/oracle/flash_recovery_area/MMI/backupset/2009_09_15/o1_mf_annnn_TAG20090915T110412_5byclzbb_.bkp

  List of Archived Logs in backup set 7
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    18      1320963    15-SEP-09 1321005    15-SEP-09

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    9.39M      DISK        00:00:00     15-SEP-09      
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20090915T110416
        Piece Name: /u01/app/oracle/flash_recovery_area/MMI/autobackup/2009_09_15/o1_mf_s_697633458_5bycm3q8_.bkp
  SPFILE Included: Modification time: 15-SEP-09
  SPFILE db_unique_name: MMI
  Control File Included: Ckp SCN: 1321012      Ckp time: 15-SEP-09


RMAN> show retention policy;

RMAN configuration parameters for database with db_unique_name MMI are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default


RMAN> report need backup;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------



RMAN> configure retention policy to redundancy 2
2> ;

new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored

RMAN> report need backup
2> ;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of files with less than 2 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
1    1     /u01/app/oracle/oradata/mmi/system01.dbf
2    1     /u01/app/oracle/oradata/mmi/sysaux01.dbf
3    1     /u01/app/oracle/oradata/mmi/undotbs01.dbf
4    1     /u01/app/oracle/oradata/mmi/users01.dbf
5    1     /u01/app/oracle/oradata/mmi/mydatafile.dbf

RMAN> configure retention policy to redundancy 1
2> ;

old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
new RMAN configuration parameters are successfully stored

RMAN> report need backup
2> ;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------

RMAN> 

Wednesday, August 12, 2009

ORA-01157: cannot identify/lock data file - see DBWR trace file

This demonstration relate to RMAN role connection with control file, whenever you add any datafile within tablespace or add any new tablespace within database , this added datafile or table space information goes to within controlfile.Later on if you will restore whole database and yours backup piece does not contain this newly added datafile , controlfile will give an hint to RMAN for adding this newly datafile during restoring the whole database.

i.e

1)Take a full backup;
2)create tablespace;
3)shutdown immediate;
4)delete alls datafile
5)restore database

at step 5 restore will recreate the datafile in conjunction with RMAN and controlfile.Lets see
RMAN> backup database;

Starting backup at 12-AUG-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=140 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/mmi/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/mmi/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/mmi/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/mmi/users01.dbf
channel ORA_DISK_1: starting piece 1 at 12-AUG-09
channel ORA_DISK_1: finished piece 1 at 12-AUG-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_08_12/o1_mf_nnndf_TAG20090812T145015_58542s82_.bkp tag=TAG20090812T145015 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 12-AUG-09
channel ORA_DISK_1: finished piece 1 at 12-AUG-09
piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_08_12/o1_mf_ncsnf_TAG20090812T145015_585446c6_.bkp tag=TAG20090812T145015 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-AUG-09


SQL> create tablespace mytablespace datafile '/u01/app/oracle/oradata/mmi/mydatafile.dbf' size 10M
  2  /

Tablespace created.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
Delete alls datafile using OS
RMAN> connect target sys/sys

connected to target database (not started)

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area    1620115456 bytes

Fixed Size                     2144864 bytes
Variable Size                922748320 bytes
Database Buffers             687865856 bytes
Redo Buffers                   7356416 bytes


RMAN> restore database;

Starting restore at 12-AUG-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=154 device type=DISK

creating datafile file number=5 name=/u01/app/oracle/oradata/mmi/mydatafile.dbf
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/mmi/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/mmi/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/mmi/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/mmi/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/MMI/backupset/2009_08_12/o1_mf_nnndf_TAG20090812T145015_58542s82_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/MMI/backupset/2009_08_12/o1_mf_nnndf_TAG20090812T145015_58542s82_.bkp tag=TAG20090812T145015
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 12-AUG-09

Stop here dont make recovery here go to /u01/app/oracle/oradata/mmi you will see there is datafile named mydatafile.dbf will be created.The control file knows about the datafile even though datafile is not backed up, if controlfile knows about datafile then restore creates the datafile in the original location with RMAN tool. During user managed restore , controlfile will not play this role with yours OS copying command and you will encounter following error during recovery like.. ORA-01157: cannot identify/lock data file 6 - see DBWR trace file ORA-01110: data file 6: '/u01/app/oracle/oradata/mmi/mydatafile.dbf' the reason for above error is that you are doing restore and recovery by using user managed backup and recovery,control file knows about the data file even though data file is not backed up, if control file knows about data file then restore creates the data file in the original location in corrdination with RMAN but with user manged restore and recovery controlfile not able to coordinate with OS utility copy and paste. In short during user managed restore , control file will not play this role with yours OS copying command .It is RMAN which coordinate with control file.

Friday, April 10, 2009

Media recovery start point

Media Recovery will always start from the most earliest restored datafile header CKPT SCN.
SQL> select controlfile_change#,checkpoint_change#
  2    from v$database
  3  /

CONTROLFILE_CHANGE# CHECKPOINT_CHANGE#
------------------- ------------------
             675815             675666

SQL> select substr(name,1,51) fname,checkpoint_change#
  2    from v$datafile_header
  3  /

FNAME                                               CHECKPOINT_CHANGE#
--------------------------------------------------- ------------------
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSTEM01.DBF              675666
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\UNDOTBS01.DBF             675666
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSAUX01.DBF              675666
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS01.DBF               675666
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS02.DBF               675666
Shutdown immediate the database and then make a cold copy of user01.dbf datafiles to folder A
F:\oracle\product\10.1.0\oradata>cd prod

F:\oracle\product\10.1.0\oradata\prod>mkdir A

F:\oracle\product\10.1.0\oradata\prod>copy users01.dbf A
        1 file(s) copied.
Start the database
SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                   787988 bytes
Variable Size             145750508 bytes
Database Buffers           25165824 bytes
Redo Buffers                 262144 bytes
Database mounted.
Database opened.

SQL> select controlfile_change#,checkpoint_change#
  2    from v$database
  3  /

CONTROLFILE_CHANGE# CHECKPOINT_CHANGE#
------------------- ------------------
             676283             676131

SQL> select substr(name,1,51) fname,checkpoint_change#
  2    from v$datafile_header
  3  /

FNAME                                               CHECKPOINT_CHANGE#
--------------------------------------------------- ------------------
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSTEM01.DBF              676131
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\UNDOTBS01.DBF             676131
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSAUX01.DBF              676131
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS01.DBF               676131
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS02.DBF               676131
shutdown immediate again the database and make copy of system01.dbf datafiles to folder B,every shutdown immediate itself make a checkpoint and increment the CKPT SCN at datafile header with controlfile.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.


F:\oracle\product\10.1.0\oradata\prod>mkdir B

F:\oracle\product\10.1.0\oradata\prod>copy system01.dbf B
        1 file(s) copied.
Start the database
SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                   787988 bytes
Variable Size             145750508 bytes
Database Buffers           25165824 bytes
Redo Buffers                 262144 bytes
Database mounted.
Database opened.
SQL> select controlfile_change#,checkpoint_change#
  2    from v$database
  3  /

CONTROLFILE_CHANGE# CHECKPOINT_CHANGE#
------------------- ------------------
             676623             676473

SQL> select substr(name,1,51) fname,checkpoint_change#
  2    from v$datafile_header
  3  /

FNAME                                               CHECKPOINT_CHANGE#
--------------------------------------------------- ------------------
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSTEM01.DBF              676473
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\UNDOTBS01.DBF             676473
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSAUX01.DBF              676473
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS01.DBF               676473
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS02.DBF               676473

Shutdown immediate the database again and then make a cold copy of user02.dbf datafiles to folder C.
F:\oracle\product\10.1.0\oradata\prod>mkdir C

F:\oracle\product\10.1.0\oradata\prod>copy users02.dbf C
        1 file(s) copied.

F:\oracle\product\10.1.0\oradata\prod>
Dont startup the database let it be remain shutdown,copy users01.dbf from folder A,system01 from folder B and users02 from folder C to the folder F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD respectivley. After copying those file to prod folder from A,B and C startup the database
==========================================================================
Copy user01.dbf from folder A (F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\A) 
to folder PROD (F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD)
==========================================================================

F:\oracle\product\10.1.0\oradata\prod>copy F:\oracle\product\10.1.0\oradata\prod\A\users01.dbf  
                                      F:\oracle\product\10.1.0\oradata\prod\
Overwrite F:\oracle\product\10.1.0\oradata\prod\USERS01.DBF? (Yes/No/All): yes
        1 file(s) copied.

===========================================================================
Copy system01.dbf from folder B (F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\B) 
to folder PROD (F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD)
===========================================================================

F:\oracle\product\10.1.0\oradata\prod>copy F:\oracle\product\10.1.0\oradata\prod
\B\system01.dbf  F:\oracle\product\10.1.0\oradata\prod\
Overwrite F:\oracle\product\10.1.0\oradata\prod\SYSTEM01.DBF? (Yes/No/All): yes
        1 file(s) copied.

===========================================================================
Copy users02.dbf from folder C (F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\C) 
to folder PROD (F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD)
===========================================================================

F:\oracle\product\10.1.0\oradata\prod>copy F:\oracle\product\10.1.0\oradata\prod
\C\users02.dbf  F:\oracle\product\10.1.0\oradata\prod\
Overwrite F:\oracle\product\10.1.0\oradata\prod\USERS02.DBF? (Yes/No/All): yes
        1 file(s) copied.
SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                   787988 bytes
Variable Size             145750508 bytes
Database Buffers           25165824 bytes
Redo Buffers                 262144 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: 'F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSTEM01.DBF'


SQL> select controlfile_change#,checkpoint_change#
  2    from v$database
  3  /

CONTROLFILE_CHANGE# CHECKPOINT_CHANGE#
------------------- ------------------
             678259             678859

SQL> select substr(name,1,51) fname,checkpoint_change#
  2    from v$datafile_header
  3  /

FNAME                                               CHECKPOINT_CHANGE#
--------------------------------------------------- ------------------
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSTEM01.DBF              676472
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\UNDOTBS01.DBF             678859
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\SYSAUX01.DBF              678859
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS01.DBF               676130
F:\ORACLE\PRODUCT\10.1.0\ORADATA\PROD\USERS02.DBF               678859
See above you will find that 676130 of users01.dbf is the earliest/oldest CKPT SCN with others datafile system01.dbf 676472 and users02.dbf 678859 recovery will start from that point 676130 which is earliest and oldest within restored datafiles.
SQL> recover database until cancel
ORA-00279: change 676130 generated at 04/11/2009 04:02:23 needed for thread 1
ORA-00289: suggestion :
F:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\PROD\ARCHIVELOG\2009_04_11\O1_MF_1_
1_%U_.ARC
ORA-00280: change 676130 for thread 1 is in sequence #1


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

Friday, March 6, 2009

Oracle Locks

User must request a resource (i.e row,table,index etc) before using it and must release that resource after using it.
Without following above approach there would be collision among user requests which result data to be in inconsistent.To avoid data inconsistency a lock mechanisim adopted within different database,Every database has its own locking mechanism.
Oracle uses two modes in a multiuser database either its on table or row

Exclusive lock mode
Exclusive lock mode never allowed the associates resource from being shared.This lock mode is obtained to modify data.Only one exclusive lock can be placed on a resource (such as a row or a table).

i.e

From one session i acquire the exclusive lock on resource (emp table)
Session a
SQL> lock table emp in exclusive mode nowait 2 / Table(s) Locked.
Note : The optional keyword NOWAIT tells Oracle not to wait for a table if it has been locked by another user.

From another session i try to acquire the exclusive lock on same resource (emp table) as "session a" above already acquired.
Session b
SQL> lock table emp in exclusive mode nowait 2 / lock table emp in exclusive mode nowait * ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified
Even you cannot get shared lock over that table which has already exclusive mode lock
SQL> lock table emp in row share mode nowait
  2  /
lock table emp in row share mode nowait
           *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified
Exclusive lock can be acquired at table level as well at row level.But oralce automatically acquire exclusive lock at row level which is the beauty of oracle to create data consistent as well maintain concurrency.

Share lock mode
Share lock mode allows the associated resource to be shared subject to cirumstances.

i.e

From one session i acquire the share lock on resource (emp table)
Session c
SQL> lock table emp in row share mode nowait 2 / Table(s) Locked.
From another session i try to acquire the same resource exclusive lock on same resoruces (emp table) which has already above taken by "session c".
Session d
SQL> lock table emp in row share mode nowait 2 / Table(s) Locked.
Share locks dont allow to acquire exclusive lock over the associates resource.

i.e

From one session i acquire the share lock on resource (emp table)
Session e 
SQL> lock table emp in row share mode nowait 2 / Table(s) Locked.
From another session i try to acquire the same exclusive lock on same resoruces (emp table) which has already taken by above "session e".
Session f 
SQL> lock table emp in exclusive mode nowait 2 / lock table emp in exclusive mode nowait * ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified
Now you are aware about locking mode.

Locks Types

DML locks
DML locks are locks which are acquired automatically by Oracle to protect data in tables and indexes Whenever you issue a DML statement to modify data i.e SELECT..FOR UPDATE,INSERT, UPDATE, MERGE, and DELETE statments.DML locks prevent destructive interference of simultaneous conflicting DML or DDL operations.

DML statments automatically acquire lock on two levels

i) Row-Level Locks (TX)
ii)Table Level Locks(TM)

These DML locks are always and only (exclusive) at row level but it can be shared as well as exclusive at table level.

Here TX specify lock at row level while TM is at table level.
i) Row Level Locks (TX)
Row-level locks are primarily used to prevent two transactions from modifying the same row. When a transaction needs to modify a row, a row lock is acquired.Any INSERT, DELETE, UPDATE, or SELECT FOR UPDATE statements will automatically issue an exclusive lock on the rows affected by the transaction. This exclusive lock at row means that other transactions can’t modify the affected rows until the original transaction commits or rolls back, thereby releasing the exclusive locks.
ii) Table Level Lock (TM)
Whenever you acquire any row level lock there is ultimately a table level is also acquired to prvent others session to alter, drop this table whose rows are being modified.TM Per table locks are acquired during the execution of a transaction when referencing a table with a DML statement so that the object is not dropped or altered during the execution of the transaction.

Here is an exceprt from SQL to verify that DML acquires lock at both row and table level
Session 1

SQL> update emp
  2     set sal=sal+1
  3   where empno=7566
  4  /

1 row updated.

Session 2

SQL> update emp
  2     set sal=sal+1
  3   where empno=7566
  4  /
     .
     .

hanged

Session 3

SQL> drop table emp
  2  /
drop table emp
           *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified
Above excerpt from SQL gives now a little fog but uptil now you might be clear that DML acquires lock at both row and table level ,to be more clear about this statment that "DML acquires lock at both row and table level" we need to explore oracle dynamic view v$lock.
SQL> conn sys/sys@prod as sysdba
Connected.
SQL> desc v$lock
 Name       Null?    Type
 ---------- -------- ----------------------------
 ADDR                RAW(4)
 KADDR               RAW(4)
 SID                 NUMBER
 TYPE                VARCHAR2(2)
 ID1                 NUMBER
 ID2                 NUMBER
 LMODE               NUMBER
 REQUEST             NUMBER
 CTIME               NUMBER
 BLOCK               NUMBER
From this view you just need to understand the columns TYPE (Lock type),LMODE (Lock mode) and REQUEST

As we have already seen that there are two types of DML locks

Row Level (TX)
Table Level (TM)
Type will show you the locks type either its (TX or TM)

Lock Mode (LMODE)

Lock mode tell you strength of lock ,oracle placed numbered for each lock mode (0 to 6) according to its strength.The higher the number the more its stronger.Remember follows lock mode can be at row as well table level.
6 - Exclusive (X)
5 - Shared Row Exclusive (SRX)
4 - Share (S)
3 - Row Exclusive (RX)
2 - Row Share (RS)
1 - null (NULL)
0 - none
Lets explore only 6 and 3 right now for eliminating little fog that "DML acquires lock at both row and table level",After that we will explore others in next blog.
6 - Exclusive (X) The most restrictive locking mode; permits queries on the locked table but prohibits any DML by any other users. Above statment says that you cannot acquire that lock on that same resource (Table,Rows) which is already acquired by another session. Like if you have table level exclusive lock then no other session can get any lock on that table,same if you have exclusive lock on rows then no other session can acquire lock on that rows ,yes you can get any other lock other then that rows which have already exclusive lock. This mode is automatically obtained when using the DROP TABLE statement.
3 - Row Exclusive (RX) A row exclusive table lock generally indicates that the transaction holding the lock has made one or more updates to rows in the table. A row exclusive table lock is acquired automatically for a table modified by the following types of statements.

INSERT INTO table ... ;

UPDATE table ... ;

DELETE FROM table ... ;

LOCK TABLE table IN ROW EXCLUSIVE MODE;

Permitted Operations : A row exclusive table lock held by a transaction allows other transactions to query, insert, update,delete, or lock rows concurrently in the same table. Therefore, row exclusive table locks allow multiple transactions to obtain simultaneous row exclusive and row share table locks for the same table. Prohibited Operations : A row exclusive table lock held by a transaction prevents other transactions from manually locking the table for exclusive reading or writing. Therefore, other transactions cannot concurrently lock the table using the following statements:

LOCK TABLE table IN SHARE MODE;

LOCK TABLE table IN SHARE EXCLUSIVE MODE;

LOCK TABLE table IN EXCLUSIVE MODE;

Here is an excerpt from SQL to see both lock mode
SQL> update emp    
  2     set sal=sal+1    
  3   where empno=7566    
  4  /            
            
            
1 row updated.

SQL> show user
USER is "SYS"

SQL> select username
  2        ,v$lock.sid
  3        ,v$lock.type "lock type"
  4        ,lmode       "lock mode"
  5    from v$lock,v$session
  6   where v$lock.sid = v$session.sid
  7     and v$session.username='SCOTT'
  8   order by v$lock.sid
  9  /

USERNAME                              SID lo  lock mode
------------------------------ ---------- -- ----------
SCOTT                                 161 TX          6
SCOTT                                 161 TM          3
As you can see DML locks within session for an update statment acquired TX (Row Level) lock with lock mode 6 which is an exclusive (the most restrictive/aggresive lock).You are also seeing that this DML lock also acquire TM (Table Level) with lock mode 3 which is row exclusive this lock will prevent other session to drop that table.

I will post with others mode in next blog

Followers

About Me

My photo
Melbourne, Victoria, Australia