Upload
printesh-patel
View
216
Download
4
Embed Size (px)
DESCRIPTION
recovering a database if system datafile is lost or damages
Citation preview
RECOVERING THE DATABASE IF SYSTEM
DATAFILE IS LOST OR CORRUPTED
Posted by Narashim Reddy .R on August 16, 2009
Rate This
[oracle@reddy ~]$ export ORACLE_SID=rub
[oracle@reddy ~]$ sqlplus sys as sysdba
SQL*Plus: Release 10.2.0.1.0 Production on Fri Oct 31 16:26:10 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to an idle instance.
SQL> startup;
ORACLE instance started.
Total System Global Area 348127232 bytes
Fixed Size 1219328 bytes
Variable Size 289408256 bytes
Database Buffers 50331648 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/rub/archive
Oldest online log sequence 0
Next log sequence to archive 1
Current log sequence 1
SQL> select name from v$datafile;
NAME
/home/oracle/rub/datafiles/system01.dbf
/home/oracle/rub/datafiles/undotbs1.dbf
/home/oracle/rub/datafiles/sysaux01.dbf
/home/oracle/rub/datafiles/users01.dbf
SQL> select name from v$controlfile;
NAME
/home/oracle/rub/control/c1.ctl
SQL> alter tablespace system begin backup;
Tablespace altered.
SQL> alter tablespace undotbs1 begin backup;
Tablespace altered.
SQL> alter tablespace sysaux begin backup;
Tablespace altered.
SQL> alter tablespace users begin backup;
Tablespace altered.
SQL> !
[oracle@reddy ~]$ mkdir backup
[oracle@reddy ~]$ cd rub/
[oracle@reddy rub]$ cd control/
[oracle@reddy control]$ ls
c1.ctl
[oracle@reddy control]$ cp c1.ctl /home/oracle/backup/
[oracle@reddy control]$ cd ..
[oracle@reddy rub]$ cd datafiles/
[oracle@reddy datafiles]$ ls
redo01.log redo02.log sysaux01.dbf system01.dbf temp01.dbf undotbs1.dbf
users01.dbf
[oracle@reddy datafiles]$ cp *.dbf /home/oracle/backup/
[oracle@reddy datafiles]$ cd ..
[oracle@reddy rub]$ cd archive/
[oracle@reddy archive]$ ls
[oracle@reddy archive]$ cd $ORACLE_HOME/dbs
[oracle@reddy dbs]$ ls
initrub.ora spfilerub.ora
[oracle@reddy dbs]$ cp initrub.ora /home/oracle/backup/
[oracle@reddy dbs]$ cp spfilerub.ora /home/oracle/backup/
[oracle@reddy dbs]$ cd /home/oracle/backup/
[oracle@reddy backup]$ ls
c1.ctl initrub.ora sysaux01.dbf system01.dbf temp01.dbf undotbs1.dbf
users01.dbf spfilerub.ora
[oracle@reddy backup]$ exit
exit
SQL> alter tablespace system end backup;
Tablespace altered.
SQL> alter tablespace undotbs1 end backup;
Tablespace altered.
SQL> alter tablespace sysaux end backup;
Tablespace altered.
SQL> alter tablespace users end backup;
Tablespace altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !
[oracle@reddy ~]$ cd rub/
[oracle@reddy rub]$ cd datafiles/
[oracle@reddy datafiles]$ ls
redo01.log redo02.log sysaux01.dbf system01.dbf temp01.dbf undotbs1.dbf
users01.dbf
[oracle@reddy datafiles]$ rm -rf system01.dbf
[oracle@reddy datafiles]$ cd
[oracle@reddy ~]$ exit
exit
SQL> startup;
ORACLE instance started.
Total System Global Area 348127232 bytes
Fixed Size 1219328 bytes
Variable Size 289408256 bytes
Database Buffers 50331648 bytes
Redo Buffers 7168000 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 see DBWR trace file
ORA-01110: data file 1: /home/oracle/rub/datafiles/system01.dbf
SQL> !
[oracle@reddy ~]$ cd backup/
[oracle@reddy backup]$ ls
c1.ctl initrub.ora sysaux01.dbf system01.dbf temp01.dbf undotbs1.dbf
users01.dbf
[oracle@reddy backup]$ cp system01.dbf /home/oracle/rub/datafiles/
[oracle@reddy backup]$ cd
[oracle@reddy ~]$ exit
exit
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 348127232 bytes
Fixed Size 1219328 bytes
Variable Size 289408256 bytes
Database Buffers 50331648 bytes
Redo Buffers 7168000 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: /home/oracle/rub/datafiles/system01.dbf
SQL> recover datafile 1;
ORA-00279: change 373322 generated at 10/31/2008 16:30:29 needed for
thread 1
ORA-00289: suggestion : /home/oracle/rub/archive/arch_1_669569864_1.arc
ORA-00280: change 373322 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
Log applied.
Media recovery complete.
SQL> alter database open;
Database altered. . . . . . . .