Database Recovery
Copyright © 2006, Oracle. All rights reserved.
Objectives
User man.
RMAN CLI
EM
Complete
Incomplete
Control file
RO TBS
After completing this lesson, you should be able to:
• Perform complete or incomplete user-managed
recovery
• Identify situations where incomplete recovery is
necessary
• Perform complete or incomplete recovery by using
RMAN
• Perform incomplete recovery based on time, SCN,
log sequence, restore points, or the cancel method
• Recover an automatically backed up control file
• Use Enterprise Manage to perform recovery
• Recover read-only tablespaces
5-2
Copyright © 2006, Oracle. All rights reserved.
Recovery Methods
There are two methods for performing recovery:
• User-managed recovery
– Files must be maintained and moved into place
manually.
– Use SQL*Plus commands.
•
RMAN recovery
– Files are managed automatically.
– Use RMAN functionality including all repository
maintenance and reporting capabilities.
– This can be done by using Enterprise Manager.
– Oracle Corporation recommends using this method.
5-3
Copyright © 2006, Oracle. All rights reserved.
User-Managed Recovery:
RECOVER Command
•
Restore all database files from a backup and then
recover the database:
SQL> RECOVER DATABASE
•
Restore the damaged data files from a backup and
then recover the data files:
SQL> RECOVER TABLESPACE index_tbs
Or:
SQL> RECOVER DATAFILE
2> '/oradata/indx01.dbf'
5-4
Copyright © 2006, Oracle. All rights reserved.
RMAN Recovery: RESTORE
and RECOVER Commands
User man.
> RMAN CLI
EM
Complete
Incomplete
Control file
RO TBS
run{
sql "ALTER TABLESPACE inv_tbs OFFLINE IMMEDIATE";
RESTORE TABLESPACE inv_tbs;
RECOVER TABLESPACE inv_tbs DELETE ARCHIVELOG;
sql "ALTER TABLESPACE inv_tbs ONLINE";
}
5-5
Copyright © 2006, Oracle. All rights reserved.
Recovery Using
Enterprise Manager
User man.
RMAN CLI
> EM
Complete
Incomplete
Control file
RO TBS
With the Enterprise Manager Recovery Wizard, you can
create and run an RMAN script to perform the recovery.
RMAN> RECOVER DATABASE …
5-6
Copyright © 2006, Oracle. All rights reserved.
Complete Versus Incomplete Recovery
There are two types of recovery:
• Complete recovery brings the database up to the
present, including all data changes made to the
point in time when the recovery was requested.
Complete
recovery
Incomplete
recovery
Restore from
this backup
•
5-7
Missing transactions
after incomplete recovery
Recovery
task started
at this time
Incomplete recovery brings the database up to a
specified point in time in the past, before the
recovery operation was requested.
Copyright © 2006, Oracle. All rights reserved.
User man.
RMAN CLI
EM
> Complete
Incomplete
Control file
RO TBS
Complete Recovery
Archived
log Archived
log
Online
Redo log
Changes applied
2
1
Restored
data files
5-8
Database
opened
Undo applied
4
5
3
Data files containing
committed and
uncommitted
transactions
Copyright © 2006, Oracle. All rights reserved.
6
Recovered
data files
User man.
RMAN CLI
EM
Complete
> Incomplete
Control file
RO TBS
Incomplete Recovery
Archived
log Archived
log
Online
Redo log
X
X
Changes applied to point in time (PIT)
2
Database
opened
4
1
Restored data
files from as far
back as necessary
5-9
3
Data files containing
committed and
uncommitted
Transactions up to PIT
Copyright © 2006, Oracle. All rights reserved.
Undo applied
5
6
PIT-recovered
data files
Situations Requiring Incomplete Recovery
•
•
•
5-11
Complete recovery fails because of a missing
archived log file.
One or more unarchived redo log files and a data
file are lost.
A backup of the control file is used to open or
recover the database.
Copyright © 2006, Oracle. All rights reserved.
Types of Incomplete Recovery
There are four types of incomplete recovery:
• Time-based recovery
• Cancel-based recovery
• Change-based recovery
• Log sequence recovery
5-12
Copyright © 2006, Oracle. All rights reserved.
Performing User-Managed
Incomplete Recovery
•
Recover a database until time:
SQL> RECOVER DATABASE UNTIL
2 TIME '2005-12-14:12:10:03';
•
Recover a database until cancel:
SQL> RECOVER DATABASE UNTIL CANCEL;
•
Recover using the backup control file:
SQL> RECOVER DATABASE
2 UNTIL TIME '2005-12-14:12:10:03'
3 USING BACKUP CONTROLFILE;
5-14
Copyright © 2006, Oracle. All rights reserved.
Performing User-Managed
Incomplete Recovery
To perform user-managed incomplete recovery, follow
these steps:
1. Shut down the database.
2. Restore data files.
3. Mount the database.
4. Recover the database.
5. Open the database with the RESETLOGS option.
5-15
Copyright © 2006, Oracle. All rights reserved.
User-Managed Time-Based Recovery:
Example
This is the scenario:
• A job ran in error, and its effects have to be
undone.
• This happened 15 minutes ago, and there has
been little database activity since then.
• You decide to perform incomplete recovery to
restore the database back to its state as of 15
minutes ago.
SQL>
$ cp
SQL>
SQL>
SQL>
5-16
SHUTDOWN IMMEDIATE
/BACKUP/* /u01/db01/ORADATA
STARTUP MOUNT
RECOVER DATABASE UNTIL TIME '2005-11-28:11:44:00';
ALTER DATABASE OPEN RESETLOGS;
Copyright © 2006, Oracle. All rights reserved.
User-Managed Cancel-Based Recovery:
Example
The scenario is the same as the one for the time-based
example, except for these findings:
• Redo logs are not multiplexed.
• One of the online redo logs is missing.
• The missing redo log is not archived.
• The redo log contained information from
11:34 a.m.
• Twenty-six minutes of data are lost.
• Users can reenter their data manually.
5-18
Copyright © 2006, Oracle. All rights reserved.
User-Managed Cancel-Based Recovery:
Example
Recover the database as follows:
1. Shut down the database.
2. Restore all data files from the most recent backup.
3. You already have a valid backup, so mount the
database.
4. Execute RECOVER DATABASE UNTIL CANCEL.
5. Execute ALTER DATABASE OPEN RESETLOGS to
open the database.
5-19
Copyright © 2006, Oracle. All rights reserved.
Performing Incomplete Recovery
by Using RMAN
1.
2.
3.
4.
Mount the database.
Allocate multiple channels for parallelization.
Restore all data files.
Recover the database by using UNTIL TIME,
UNTIL SEQUENCE, or UNTIL SCN.
5. Open the database by using RESETLOGS.
5-20
Copyright © 2006, Oracle. All rights reserved.
Time-Based Recovery
Using RMAN: Example
RMAN>
2>
3>
4>
5>
5-21
RUN {
SET UNTIL TIME = '2005-11-28:11:44:00';
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS; }
Copyright © 2006, Oracle. All rights reserved.
Log Sequence Recovery
Using RMAN: Example
RMAN>
2>
3>
4>
5>
6>
7>
5-23
RUN {
SET UNTIL SEQUENCE 120 THREAD 1;
ALTER DATABASE MOUNT;
RESTORE DATABASE;
RECOVER DATABASE; # recovers through log 119
ALTER DATABASE OPEN RESETLOGS;
}
Copyright © 2006, Oracle. All rights reserved.
Incomplete Recovery Using
Enterprise Manager
5-24
Copyright © 2006, Oracle. All rights reserved.
Incomplete Recovery and the Alert Log
The following are some best practices regarding the
alert log in incomplete recovery scenarios:
• Check the alert log before and after recovery.
• Look for error information, hints, and SCNs.
• Confirm that steps in the recovery process were
successful.
5-25
Copyright © 2006, Oracle. All rights reserved.
Restore Points
A restore point:
• Serves as an alias for an
SCN or a specific point in time
• Is stored in the control file
• Can be used with:
before_load
– RECOVER DATABASE
– FLASHBACK DATABASE
– FLASHBACK TABLE
1
2
5-26
SQL> CREATE RESTORE POINT before_load;
RMAN> RECOVER DATABASE UNTIL RESTORE POINT before_load;
Copyright © 2006, Oracle. All rights reserved.
Incomplete Recovery: Best Practices
•
•
•
•
•
•
5-27
Plan for and practice scenarios ahead of time.
Investigate and verify that incomplete recovery is
necessary.
Follow all steps carefully.
Take whole database backups before and after
recovery.
Always verify that the recovery was successful.
Take advantage of restore points.
Copyright © 2006, Oracle. All rights reserved.
Recovering a Control File
Autobackup
RMAN> RESTORE CONTROLFILE TO
2> '/oradata/ctlfile.bak' FROM AUTOBACKUP;
Recovery
Manager
(RMAN)
User man.
RMAN CLI
EM
Complete
Incomplete
> Control file
RO TBS
Flash recovery
area
RECOVER DATABASE;
ALTER DATABASE OPEN
RESETLOGS;
Control
file
Database
5-29
ALTER TABLESPACE temp ADD
TEMPFILE...;
Copyright © 2006, Oracle. All rights reserved.
Creating a New Control File
SYSTEM
USERS
Redo log
file 1A
SYSAUX
INDEX
Redo log Redo log
file 2A
file 2B
UNDO
TEMP
Control
files
Parameter
file
Password
file
Redo log
file 1B
SQL> ALTER DATABASE BACKUP CONTROLFILE
TO TRACE;
5-31
Copyright © 2006, Oracle. All rights reserved.
Creating a New Control File
5-32
Copyright © 2006, Oracle. All rights reserved.
*
Case 1
Recovering Read-Only
Tablespaces
User man.
RMAN CLI
EM
Complete
Incomplete
Control file
> RO TBS
Read-only
*
Case 2
Read/write
Read-only
*
Read/write
Case 3
Read-only
Control file
* backup
to be
Backup
5-33
Change
Tablespace
State
Crash
and perform
recovery
Copyright © 2006, Oracle. All rights reserved.
used for recovery
if current one lost
Read-Only Tablespace Recovery Issues
Special considerations must be taken for read-only
tablespaces when:
• Re-creating a control file
• Renaming data files
• Using a backup control file
5-35
Copyright © 2006, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Perform complete or incomplete user-managed
recovery
• Perform complete or incomplete recovery by using
RMAN
• Identify situations where incomplete recovery is
necessary
• Perform incomplete recovery based on time, SCN,
log sequence, restore points, or the cancel method
• Recover a control file autobackup
• Use Enterprise Manage to perform recovery
• Recover read-only tablespaces
5-37
Copyright © 2006, Oracle. All rights reserved.
Practice Overview: Performing
Incomplete Recovery
This practice covers the following topics:
• Point-in-time recovery using RMAN
• Recovery from the loss of control files
5-38
Copyright © 2006, Oracle. All rights reserved.