Академический Документы
Профессиональный Документы
Культура Документы
NAME
5. Restore and Recovery of a Datafile to a different location.(Disk corrupted having recent backup
and recover the datafile in new Disk location).
User managed recovery scenarios do require that the database is in archive log mode, and that
backups of all datafiles and control files are made with the tablespaces set to begin backup, if the
database is open while the copy is made. At the end of the copy of each tablespace it is necessaire to
take it out of backup mode. Alternatively complete backups can be made with the database shutdown.
Online redologs can be optionally backed up.
Files to be copied:
select name from v$datafile;
select member from v$logfile; # optional
select name from v$controlfile;
1.Complete Closed Database Recovery. System tablespace is missing
If the system tablespace is missing or corrupted the database cannot be started up
so a complete closed database recovery must be performed.
Pre requisites: A closed or open database backup and archived logs.
1. Use OS commands to restore the missing or corrupted system datafile to its original location
from recent backup, ie:
cp -p /user/backup/uman/system01.dbf /user/oradata/u01/dbtst/system01.dbf
2. startup mount;
3. recover datafile 1;
4. alter database open;
workshop1: system datafile recovery with recent backup
view plainprint?
SQL> create user rajesh identified by rajesh;
User created.
SQL> grant dba to rajesh;
Grant succeeded.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
1219904 bytes
138412736 bytes
Database Buffers
301989888 bytes
Redo Buffers
2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/testdb/system01.dbf'
Database dismounted.
ORACLE instance shut down.
SQL> host cp /u01/app/oracle/oradata/backup/system01.dbf
/u01/app/oracle/oradata/testdb/system01.dbf
system datafile restored from recent backup
1219904 bytes
138412736 bytes
Database Buffers
301989888 bytes
Redo Buffers
2973696 bytes
Database mounted.
SQL> recover datafile 1;
ORA-00279: change 454383 generated at 05/07/2010 01:40:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_%u_.arc
ORA-00280: change 454383 for thread 1 is in sequence #7
.
ORA-00279: change 456039 generated at 05/07/2010 12:46:22 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_11_%u_.arc
ORA-00280: change 456039 for thread 1 is in sequence #11
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_10_5y7hl7dr_.arc'
no longer needed for this recovery
Log applied.
Media recovery complete.
SQL> alter database open;
Database altered.
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
12
14
14
USERNAME
-----------------------------RAJESH
recovery can be
workshop2: Non-system datafile recovery from recent backup when database is open
view plainprint?
SQL> ALTER USER rajesh DEFAULT TABLESPACE users;
User altered.
Table created.
1 row created.
SQL> commit;
Commit complete.
ID
---------123
System altered.
SQL> /
System altered.
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
14
16
16
Connected.
SQL> alter system flush buffer_cache;
System altered.
Tablespace altered.
Log applied.
Media recovery complete.
SQL> alter tablespace users online;
Tablespace altered.
Connected.
SQL> select * from demo;
ID
---------123
3.Complete Open Database Recovery (when the database is initially closed).Non system datafile is
missing
If a non system tablespace is missing or corrupted and the database crashed, recovery can be
performed after the database is open.
Pre requisites: A closed or open database backup and archived logs.
1. startup; (you will get ora-1157 ora-1110 and the name of the missing datafile, the database will
remain mounted)
2.
alter database datafile3 offline; (tablespace cannot be used because the database is not open)
3.
4.
Use OS commands to restore the missing or corrupted datafile to its original location, ie:
cp -p /user/backup/uman/user01.dbf /user/oradata/u01/dbtst/user01.dbf
5.
recover datafile 3;
6.
view plainprint?
SQL> conn sys/oracle as sysdba;
Connected.
SQL> alter system switch logfile;
System altered.
2 where username='RAJESH';
USERNAME
DEFAULT_TABLESPACE
------------------------------ -----------------------------RAJESH
USERS
Table created.
1 row created.
SQL> commit;
Commit complete.
ID
---------786
SQL> startup
ORACLE instance started.
1219904 bytes
142607040 bytes
Database Buffers
297795584 bytes
Redo Buffers
2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/testdb/users01.dbf'
Database altered.
Database altered.
Log applied.
Media recovery complete.
SQL> alter database datafile 4 online;
Database altered.
ID
---------786
4.Recovery of a Missing Datafile that has no backups (database is open).
If a non system datafile that was not backed up since the last backup is missing,
If the create datafile command needs to be executed to place the datafile on a location different than
the original use:
alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf' as
'/user/oradata/u02/dbtst/newdata01.dbf'
restriction: datafile should be created after controlfile creation.(i.e,controlfile creation time is prior
than datafile creation time).
workshop 4: Missing Non-system Datafile having no backups
view plainprint?
SQL> alter session set nls_date_format='DD-MON-YYYY hh24:mi:ss';
Session altered.
CONTROLFILE_CREATED
-------------------07-MAY-2010 16:27:22
CREATION_TIME
NAME
Tablespace created.
CREATION_TIME
NAME
CONTROLFILE_CREATED
-------------------07-MAY-2010 16:27:22
User created.
Grant succeeded.
USERNAME
DEFAULT_TABLESPACE
------------------------------ -----------------------------JAY
TESTING
Table created.
1 row created.
SQL> commit;
Commit complete.
ID
---------321
ID
---------321
System altered.
Database altered.
----TO CREATE A NEW RECOVERED DATAFILE IN SAME LOCATION.
SQL> alter database create datafile '/u01/app/oracle/oradata/testdb/test01.dbf';
Database altered.
----TO CREATE A NEW RECOVERED DATAFILE IN DIFFERENT LOCATION.
SQL> alter database create datafile '/u01/app/oracle/oradata/testdb/test01.dbf' as
'/u03/oradata/test01.dbf';
Database altered.
Log applied.
Media recovery complete.
SQL> alter database datafile 5 online;
Database altered.
ID
---------321
SQL>
1. Use OS commands to restore the missing or corrupted datafile to the new location, ie:
cp -p /user/backup/uman/user01.dbf /user/oradata/u02/dbtst/user01.dbf
2. alter tablespace offline immediate;
3. alter tablespace rename datafile
'/user/oradata/u01/dbtst/user01.dbf' to '/user/oradata/u02/dbtst/user01.dbf';
4. recover tablespace ;
5. alter tablespace online;
workshop 5:
view plainprint?
SQL> create user lachu identified by lachu
2 default tablespace users;
User created.
Grant succeeded.
Table created.
1 row created.
SQL> commit;
Commit complete.
TNAME
TABTYPE CLUSTERID
TABLE
Database altered.
Log applied.
Media recovery complete.
SQL> alter database datafile 4 online;
Database altered.
NAME
--------------------------------------------/u01/app/oracle/oradata/testdb/system01.dbf
/u01/app/oracle/oradata/testdb/undotbs01.dbf
/u01/app/oracle/oradata/testdb/sysaux01.dbf
/u03/oradata/users01.dbf ----------restored in new location (disk)
TNAME
TABTYPE CLUSTERID
TABLE
ID
---------123