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.

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.

Followers

About Me

My photo
Melbourne, Victoria, Australia