Rman Case Studies
Rman Case Studies
Rman Case Studies
REVISION HISTORY
TABLE OF CONTENTS
ABSTRACT
AUDIENCE
INFORMATION
INPUT
____________________________________________________________________
_ RMAN Recovery case studies Page 1 of 34
Ver 1.0
______________________________________________________________________________
PREREQUISITE
CASE DESCRIPTION
1. ABSTRACT................................................................................................................................2
2. AUDIENCE ................................................................................................................................2
3. INFORMATION...........................................................................................................................2
3.1 INPUT.......................................................................................................................3
3.2 PREREQUISTES......................................................................................................3
3.3 CASE DESCRIPTIONS...........................................................................................3
1. ABSTRACT
The backups for all the databases are very important are for DBAs and
for the organization as well. DBAs can recover the whole database
back to point of failure to allow normal activity after any database
disaster. But sometimes we can not perform the recovery although we
have the backups available because we are not sure which recovery
process to follow i.e. tablespace level, datafile level or database level
and that to complete or incomplete recovery. So we should be very
sure as to which process of recovery to follow and the recovery should
be very quick.
This document will give you some case studies for RMAN recovery.
2. AUDIENCE
Oracle DBA’s.
3. INFORMATION
____________________________________________________________________
_ RMAN Recovery case studies Page 2 of 34
Ver 1.0
______________________________________________________________________________
3.1INPUT
3.2PREREQUISTES
You should have a database used as a catalog for RMAN. RMAN user
must be created before taking any backups.
Creating catalog
Default Configuration
NOTE:
____________________________________________________________________
_ RMAN Recovery case studies Page 3 of 34
Ver 1.0
______________________________________________________________________________
CASE1
Scenario
• Tablespace Level
• Datafile Level
RMAN> RUN {
2> ALLOCATE CHANNEL ch1 TYPE DISK
3> FORMAT='D:\RMAN_BKP\DF_%t_%s_%D';
4> BACKUP DATABASE PLUS ARCHIVELOG;
5> RELEASE CHANNEL ch1;
6> }
Now the file system or disk drive where System datafile was there crashed.
So we don’t have the system datafile to start the database. We can not make
the System tablespace offline unlike others tablespace, so that we can
recover them from open mode.
SQL> startup
ORACLE instance started.
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> restore datafile 1;
4> recover datafile 1;
5> sql 'alter database open';
6> }
OPEN_MODE
----------
READ WRITE
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> restore tablespace system;
4> recover tablespace system;
5> sql 'alter database open';
6> }
OPEN_MODE
----------
READ WRITE
____________________________________________________________________
_ RMAN Recovery case studies Page 5 of 34
Ver 1.0
______________________________________________________________________________
CASE2
How to recover Non-System Tablespace
Scenario
Proceedings:
1. Create a table before full backup.
2. Take the full backup (level 0)
3. Create another table
4. Take the level 1 backup
5. Create another table
6. Shutdown the database
7. Remove the datafile of Users tablespace at the OS level
8. Recover the datafile using RMAN
We can restore the datafile from level 0, add the changes from level 1, then
recover by applying online redo logs and archived redo logs.
select * from t2
t2
---
1
1
1
Commit;
RMAN> RUN {
2> ALLOCATE CHANNEL ch1 TYPE DISK
3> format='D:\RMAN_BKP\full_DF_%t_%s_%D';
4> BACKUP
5> incremental level 0 database;
6> RELEASE CHANNEL ch1;
7> }
____________________________________________________________________
_ RMAN Recovery case studies Page 6 of 34
Ver 1.0
______________________________________________________________________________
t2
--
2
2
2
2
Commit;
select * from t3 ;
t3
--
3
3
3
3
3
Commit;
Error
SQL> startup
ORACLE instance started.
____________________________________________________________________
_ RMAN Recovery case studies Page 7 of 34
Ver 1.0
______________________________________________________________________________
Recovery
Step 1: Connect to RMAN
Step 2: Run the following script
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> restore datafile 9;
4> recover datafile 9;
5> sql 'alter database open';
6> sql 'alter tablespace users online';
7> }
t1 t2 t3
--- -- --
1 2 3
1 2 3
1 2 3
2 3
3
Case 3 (Part I)
Scenario
We normally take a full backup with controlfile everyday. Now after taking the
full backup we create a tablespace. Then we lost all online control files. The
recovery possibly will be an incomplete one.
Priority:
We should always try to do recovery with the current control if possible; the
second best option would be to create a new control file. Using the backup
controlfile should be the last option to use as the database needs to be
started up with the RESETLOGS option.
____________________________________________________________________
_ RMAN Recovery case studies Page 8 of 34
Ver 1.0
______________________________________________________________________________
Recovery:
We will restore all the control files.
Then we will do a recover database.
Then we will make the datafile of the new tablespace “DROP OFFLINE”
Then open the database with OPEN RESETLOGS.
Reset the incarnation.
Take the Full Backup, as the incarnation will differ.
SQL> startup
ORACLE instance started.
RMAN> run {
2> allocate channel c1 type disk;
3> restore controlfile to 'D:\Oracle\oradata\test\CONTROL01.CTL';
4> restore controlfile to 'D:\Oracle\oradata\test\CONTROL02.CTL';
____________________________________________________________________
_ RMAN Recovery case studies Page 9 of 34
Ver 1.0
______________________________________________________________________________
Database altered.
As the recovery is using the backup control file where the entry for
tablespace “data” was not there, so is the following warning.
____________________________________________________________________
_ RMAN Recovery case studies Page 10 of 34
Ver 1.0
______________________________________________________________________________
Database altered.
Database altered.
FILE_NAME
-----------------------------------------------
D:\ORACLE\ORADATA\TEST\SYSTEM01.DBF
D:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF
D:\ORACLE\ORADATA\TEST\CWMLITE01.DBF
D:\ORACLE\ORADATA\TEST\DRSYS01.DBF
D:\ORACLE\ORADATA\TEST\EXAMPLE01.DBF
D:\ORACLE\ORADATA\TEST\INDX01.DBF
D:\ORACLE\ORADATA\TEST\ODM01.DBF
D:\ORACLE\ORADATA\TEST\TOOLS01.DBF
D:\ORACLE\ORADATA\TEST\USERS01.DBF
D:\ORACLE\ORADATA\TEST\XDB01.DBF
D:\ORACLE\ORADATA\TEST\DATA01.DBF
11 rows selected.
____________________________________________________________________
_ RMAN Recovery case studies Page 11 of 34
Ver 1.0
______________________________________________________________________________
3:55:54
1 row selected
____________________________________________________________________
_ RMAN Recovery case studies Page 12 of 34
Ver 1.0
______________________________________________________________________________
Now the Inc Key 3016 will be used for future recovery as shown by
“CUR” Column. “CUR” column shows NO for Inc key 2, which was
created before the ALTER DATABASE OPEN.
3.3.1
3.3.2 Fix
- When we run a “begin backup” command every file (part of tablespace) has
to be ONLINE.
- There is no direct way to remove the datafile, once you have added any
datafile
to the tablespace it will be there unless you drop the tablespace.
- In other words, 'OFFLINE DROP' does no more good than 'OFFLINE'.
- The ALTER DATABASE DATAFILE OFFLINE DROP command is not meant to
allow you to remove a datafile. This is the only alternative in case of database
in noarchivelog mode.
- Once the datafile is offline, Oracle no longer attempts to access it, but it is
still considered part of that tablespace. This datafile is marked only as offline
in the controlfile and there is no SCN comparison done between the controlfile
and the datafile during startup (This also allows you to startup a database
with a non-critical datafile missing). The entry for that datafile is not deleted
from the controlfile to give us the opportunity to recover that datafile.
Case 3 (Part-II)
Scenario
____________________________________________________________________
_ RMAN Recovery case studies Page 13 of 34
Ver 1.0
______________________________________________________________________________
We normally take a full backup with controlfile everyday. Now after taking the
full backup we create a tablespace. Then we lost all online control files. The
recovery possible will be an incomplete one.
Priority:
We should always try to do recovery with the current control if possible; the
second best option would be to create a new control file. Using the backup
controlfile should be the last option to use as the database needs to be
started up with the RESETLOGS option.
Recovery:
We will generate the SQL for creating the controlfile and edit.
We will create a controlfile from the above command.
Then we will do a recover database. If complete recovery not possible then
we will do an incomplete recovery.
Then open the database with OPEN RESETLOGS.
Reset the incarnation.
Take the Full Backup, as the incarnation will differ.
When the database is up and running, we will take a backup of control file to
trace, so that we can recreate the controlfile when necessary. Either we can
create the controlfile manually or from the trace file. It’s not a good practice
to manually create a controlfile because we have to know each and every
location of datafile, logfile etc. To create Control File following is the
command.
Following is the command to generate the SQL for creating the controlfile.
Go to the “UDUMP” location, copy and paste the SQL to create a .sql file for
creating the Control File . The contents in TRACE file will be like following
# The following commands will create a new control file and use it
____________________________________________________________________
_ RMAN Recovery case studies Page 14 of 34
Ver 1.0
______________________________________________________________________________
____________________________________________________________________
_ RMAN Recovery case studies Page 15 of 34
Ver 1.0
______________________________________________________________________________
Remove the unnecessary comments. The files should look like the following.
Make sure that no syntax error is there. Let’s take the following file as
“ctl.sql” file
CTL.SQL
Now after taking the backup of Controlfile to trace. Suppose we lost all our
controlfiles. Recovery should be as following.
Create the controlfile by executing the .sql file (manual or from trace)
____________________________________________________________________
_ RMAN Recovery case studies Page 16 of 34
Ver 1.0
______________________________________________________________________________
SQL> @D:\ctl.sql
Control file created.
Now try to do an incomplete recovery of the database
List of incarnation
____________________________________________________________________
_ RMAN Recovery case studies Page 17 of 34
Ver 1.0
______________________________________________________________________________
RUN {
ALLOCATE CHANNEL ch1 TYPE DISK
FORMAT='D:\RMAN_BKP\DF_%t_%s_%D';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
Case 4
Incomplete Recovery (Using RESETLOGS)
We take cold backup everyday using RMAN by shutting down the database.
So now if we take a cold backup at point A and at point B, there is a media
failure and we lost all our online logfiles. Since we have lost all our log files,
we have to do an incomplete recovery. We have used recover database until
cancel and we can recover database until the last archived log file. And then
we opened the database USING OPEN RESETLOGS option. Here the log
sequence will be reset to 1 at point B. Now after few days at point C, another
media failure occurred and we lost a datafile. Now all the online log files and
the control files are intact. Now there are two possible cases.
Scenario
A B C
We have a cold backup we had a incomplete recovery
We faced
till this point. Here. We forgot to take a
another
complete backup here. We used
situation,
RESETLOGS option. Where
we
had to
do an
incomplete
recovery.
Important point before and after using “OPEN RESETLOGS” option
Proceedings
____________________________________________________________________
_ RMAN Recovery case studies Page 19 of 34
Ver 1.0
______________________________________________________________________________
Full backup
RMAN> RUN {
2> ALLOCATE CHANNEL ch1 TYPE DISK
3> format='D:\RMAN_BKP\full_DF_%t_%s_%D';
4> BACKUP
5> incremental level 0 database;
6> RELEASE CHANNEL ch1;
7> }
Create table “Ranjan1”, so that this table DDL will be in log seq 1
ARCHIVELOG_CHANGE#-1
--------------------
18256317
SCN for each datafile at the datafile header, which must be same for
all datafiles before doing incomplete recovery or resetlogs.
FILE# CHECKPOINT_CHANGE#
---------- ------------------
____________________________________________________________________
_ RMAN Recovery case studies Page 21 of 34
Ver 1.0
______________________________________________________________________________
1 18256339
2 18256339
3 18256339
4 18256339
5 18256339
6 18256339
7 18256339
8 18256339
9 18256339
10 18256339
10 rows selected.
Insert a row into ranjan1 table after the resetlogs, so that this DML
will be stored in log seq 1 i.e. after resetlogs.
____________________________________________________________________
_ RMAN Recovery case studies Page 22 of 34
Ver 1.0
______________________________________________________________________________
SCN for each datafile at the datafile header, which must be same for
all datafiles after doing incomplete recovery or resetlogs.
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 18256586
2 18256586
3 18256586
4 18256586
5 18256586
6 18256586
7 18256586
8 18256586
9 18256586
10 18256586
10 rows selected.
Recovery
SQL> startup mount;
ORACLE instance started.
____________________________________________________________________
_ RMAN Recovery case studies Page 23 of 34
Ver 1.0
______________________________________________________________________________
Database mounted.
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> recover database;
4> }
RMAN-00571:
================================================
===========
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
================================================
===========
RMAN-03002: failure of recover command at 07/03/2007 11:25:59
RMAN-06004: ORACLE error from recovery catalog database: RMAN-
20003: target data
base incarnation not found in recovery catalog
____________________________________________________________________
_ RMAN Recovery case studies Page 24 of 34
Ver 1.0
______________________________________________________________________________
Reset database
RMAN> reset database;
For restoring and recovering the data from old incarnation (Till point
A), we have to use the older incarnation i.e. 3986
____________________________________________________________________
_ RMAN Recovery case studies Page 25 of 34
Ver 1.0
______________________________________________________________________________
4> }
RMAN-00571:
================================================
===========
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
================================================
===========
RMAN-03002: failure of recover command at 07/03/2007 11:31:31
RMAN-06004: ORACLE error from recovery catalog database: RMAN-
20011: target data
base incarnation is not current in recovery catalog
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> restore database;
4> recover database;
5>
6> }
RMAN-00571:
================================================
===========
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
================================================
===========
RMAN-03002: failure of restore command at 07/03/2007 11:33:43
RMAN-06004: ORACLE error from recovery catalog database: RMAN-
20011: target data
base incarnation is not current in recovery catalog
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> recover database until sequence 3 thread 1;
4> }
RMAN-00571:
================================================
===========
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
================================================
===========
RMAN-03002: failure of recover command at 07/03/2007 11:34:36
____________________________________________________________________
_ RMAN Recovery case studies Page 26 of 34
Ver 1.0
______________________________________________________________________________
RMAN> run {
2> allocate channel c1 type disk;
3> restore controlfile to 'D:\Oracle\oradata\test\CONTROL01.CTL';
4> restore controlfile to 'D:\Oracle\oradata\test\CONTROL02.CTL';
5> restore controlfile to 'D:\Oracle\oradata\test\CONTROL03.CTL';
6> release channel c1;
7> }
____________________________________________________________________
_ RMAN Recovery case studies Page 27 of 34
Ver 1.0
______________________________________________________________________________
Tried recovering the database. Got the following error “for restoring
the file 9”.
RMAN> run{
2> allocate channel ch1 type disk;
3> recover database until sequence 5 thread 1;
4>
5> }
RMAN-00571:
================================================
===========
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
================================================
===========
RMAN-03002: failure of recover command at 07/03/2007 11:51:10
RMAN-06094: datafile 9 must be restored
RMAN-06166: datafile 8 cannot be recovered …….
Restore datafile 9
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> restore datafile 9;
4> recover database until sequence 5 thread 1;
5> }
RMAN-00571:
================================================
===========
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
================================================
===========
RMAN-03002: failure of recover command at 07/03/2007 11:55:14
RMAN-06163: some datafiles cannot be recovered, aborting the
RECOVER command
RMAN-06166: datafile 10 cannot be recovered
RMAN-06166: datafile 8 cannot be recovered …..
We have to restore all the datafile from the backup and then do an
incomplete recovery of the database. During recovery Oracle asking
for a log. Its not an error, its just a warning. So after this if we do a
“OPEN RESETLOGS” till the last available log.
RMAN> run {
____________________________________________________________________
_ RMAN Recovery case studies Page 28 of 34
Ver 1.0
______________________________________________________________________________
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 18257590
2 18257590
3 18257590
4 18257590
5 18257590
6 18257590
7 18257590
8 18257590
9 18255586
10 18257590
10 rows selected.
Do an “OPEN RESETLOGS”
____________________________________________________________________
_ RMAN Recovery case studies Page 29 of 34
Ver 1.0
______________________________________________________________________________
List of incarnation
RMAN> list incarnation;
CASE 5
Situation:
We took backup everyday at night. One day we found there is some space
issue with a tablespace USERS. So we add a new datafile to this tablespace.
We thought we will take full backup in the night so didn’t back up the new
datafile. Now a media failure occurred and we lost the new datafile. Since we
don’t have the new datafile in the yesterday’s backup, following is the way to
recover.
Assumptions:
We have all the archived logs and online redo logs intact.
Recovery
• Open the database in mount state.
• Create the same datafile which is lost.
• For recovery we can use current control file or backup control
file having the entry for the new datafile.
• Recover the datafile so that the online redo logs and archived
logs will be applied.
• Open the database
RMAN> RUN {
2> ALLOCATE CHANNEL ch1 TYPE DISK
3> format='D:\RMAN_BKP\full_DF_%t_%s_%D';
4> BACKUP
5> incremental level 0 database;
6> RELEASE CHANNEL ch1;
7> }
Tablespace altered.
NO
----------
4
____________________________________________________________________
_ RMAN Recovery case studies Page 32 of 34
Ver 1.0
______________________________________________________________________________
Recovery
SQL> startup
ORACLE instance started.
Recreate the datafile which is lost. The file name should be same as
the lost file.
Recover the datafile, so that the archive logs and the online redo logs
will be applied.
RMAN> run {
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> recover datafile 'D:\ORACLE\ORADATA\TEST\USERS02.DBF';
4> release channel ch1;
5> }
Database altered.
NO
----------
4
____________________________________________________________________
_ RMAN Recovery case studies Page 33 of 34
Ver 1.0
______________________________________________________________________________
____________________________________________________________________
_ RMAN Recovery case studies Page 34 of 34
Ver 1.0