Recovery Through RESETLOGS

Download Report

Transcript Recovery Through RESETLOGS

Database Recovery
Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to:
• Recover the control file
• Explain reasons for incomplete recovery
• Describe incomplete recovery methodology
• Recover the database to a specific point in time
using:
– User-managed backups
– RMAN-managed backups
– Enterprise Manager Database Control Console
8-2
Copyright © 2004, Oracle. All rights reserved.
Recovery Steps
Archived
log Archived
log Online
Redo log
Changes applied
Undo applied
2
4
Restored data
files
1
8-3
Data files containing
committed and uncommitted
transactions
3
Copyright © 2004, Oracle. All rights reserved.
Recovered data
files
5
Server Managed Recovery:
RESTORE and RECOVER Commands
run{
sql "ALTER TABLESPACE indx_tbs OFFLINE IMMEDIATE";
RESTORE TABLESPACE indx_tbs;
RECOVER TABLESPACE indx_tbs DELETE ARCHIVELOG;
sql "ALTER TABLESPACE indx_tbs ONLINE";
}
8-4
Copyright © 2004, Oracle. All rights reserved.
User-Managed Recovery Procedures:
RECOVER Command
•
Restore all database files from backup and
recover the database:
SQL> RECOVER DATABASE
•
Restore the damaged data files from a backup and
recover the data files:
SQL> RECOVER TABLESPACE index_tbs
Or
SQL> RECOVER DATAFILE
2> '/oradata/indx01.dbf'
8-5
Copyright © 2004, Oracle. All rights reserved.
Recovering a Control File Autobackup
RMAN> RESTORE SPFILE TO
2> '/oradata/spfile.bak' FROM AUTOBACKUP;
Recovery
Manager
(RMAN)
Flash Recovery
Area
RECOVER DATABASE;
ALTER DATABASE OPEN
RESETLOGS;
Control
File
Database
8-6
ALTER TABLESPACE temp ADD
TEMPFILE...;
Copyright © 2004, 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;
8-8
Copyright © 2004, Oracle. All rights reserved.
Creating a New Control File
8-9
Copyright © 2004, Oracle. All rights reserved.
Incomplete Recovery Overview
Instance
User
process
User
process
Server
process
PGA
Server
process
PGA
SGA
8-10
Large Pool
Data
buffer
Redo log
buffer
SMON
Parameter
file
Password
file
Locks
DBWn PMON CKPT
1
Data file 1
1
Control
files
1
Data file 2
1
Data file 3
Database
Copyright © 2004, Oracle. All rights reserved.
Shared pool
Shared SQL
and PL/SQL
Data dict.
cache
LGWR ARCn
1
Redo log
file 1
0
Redo log
file 2
Archived
log files
Situations Requiring Incomplete Recovery
•
•
•
8-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 © 2004, 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
8-12
Copyright © 2004, Oracle. All rights reserved.
Incomplete Recovery Best Practices
•
•
•
•
8-14
Follow all steps carefully.
Take whole database backups before and after
recovery.
Always verify that the recovery was successful.
Back up and remove archived logs.
Copyright © 2004, Oracle. All rights reserved.
Using RECOVER for Incomplete Recovery
•
Recover a database until time:
SQL> RECOVER DATABASE UNTIL
2 TIME '2003-12-14:12:10:03';
•
Recover a database until cancel:
SQL> RECOVER DATABASE UNTIL CANCEL;
•
Recover using backup control file:
SQL> RECOVER DATABASE
2 UNTIL TIME '2003-12-14:12:10:03'
3 USING BACKUP CONTROLFILE;
8-16
Copyright © 2004, Oracle. All rights reserved.
UNTIL TIME Recovery Example
146
Data file 1
146
Control
files
146
Data file 2
146
Data file 3
1
Data file 1
1
Data file 2
146
Redo log
file 1
145
Redo log
file 2
OE.ORDERS
Database
1
Control
files
1
Redo log
file 1
0
Redo log
file 2
1
OE.ORDERS
Data file 3
Recovered Database
8-17
1
2
Shut down and back up
3
Mount the database
Restore all data files
144
Data file 1
146
Control
files
144
Data file 2
146
Redo log
file 1
145
Redo log
file 2
OE.ORDERS
144
Data file 3
Restored Database
5
Open with Resetlogs
6
Back up the database
Copyright © 2004, Oracle. All rights reserved.
4
144
Archived
log file
UNTIL TIME Recovery Steps
1.
2.
3.
4.
5.
Shutdown database
Restore data files
Mount the database
Recover the database
Open database with RESETLOGS option
6. Backup the database
SQL>
$ cp
SQL>
SQL>
SQL>
SQL>
$ cp
8-18
shutdown immediate
/BACKUP/* /u01/db01/ORADATA
startup mount
recover database until time '2004-05-28:11:44:00';
alter database open resetlogs;
shutdown;
/u01/db01/ORADATA/* /BACKUP
Copyright © 2004, Oracle. All rights reserved.
Cancel-Based Recovery: Example
Scenario:
• The current time is 12:00 p.m. on May 28, 2004.
• The ORDERS table was dropped while someone
was trying to fix corrupted data blocks.
• Log files exist on the same disk as the data files.
• The table was dropped at approximately 11:45 a.m.
• Staff are currently in a meeting.
8-20
Copyright © 2004, Oracle. All rights reserved.
Cancel-Based Recovery: Example
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 will be lost.
• Users can recover their data.
8-21
Copyright © 2004, Oracle. All rights reserved.
Incomplete Recovery and the Alert Log
•
•
•
8-22
Check the alert log before and after recovery
Look for error information, hints, and SCNs
Confirm steps in the recovery process were
successful
Copyright © 2004, Oracle. All rights reserved.
Incomplete Recovery of a Database
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.
6. Perform a whole database backup.
8-23
Copyright © 2004, Oracle. All rights reserved.
RMAN Incomplete Recovery
UNTIL TIME: Example
RMAN>
2>
3>
4>
5>
8-24
RUN {
SET UNTIL TIME = '2004-05-28:11:44:00';
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS; }
Copyright © 2004, Oracle. All rights reserved.
RMAN Incomplete Recovery
UNTIL SEQUENCE: Example
RMAN>
2>
3>
4>
5>
6>
7>
8-26
RUN {
SET UNTIL SEQUENCE 120 THREAD 1;
ALTER DATABASE MOUNT;
RESTORE DATABASE;
RECOVER DATABASE; # recovers through log 119
ALTER DATABASE OPEN RESESTLOGS;
}
Copyright © 2004, Oracle. All rights reserved.
Recovery Using Enterprise Manager
Log in as a user with the SYSDBA privilege.
8-27
Copyright © 2004, Oracle. All rights reserved.
Recovery Using Enterprise Manager
Click on the Maintenance tab.
8-28
Copyright © 2004, Oracle. All rights reserved.
Recovery Using Enterprise Manager
Select Perform Recovery.
8-29
Copyright © 2004, Oracle. All rights reserved.
Recovery Using Enterprise Manager
Select Whole Database
and enter OS login
credentials.
8-30
Copyright © 2004, Oracle. All rights reserved.
Recovery Using Enterprise Manager
Select data files.
8-31
Copyright © 2004, Oracle. All rights reserved.
Recovery Using Enterprise Manager
Final review
8-32
Copyright © 2004, Oracle. All rights reserved.
Simplified Recovery Through RESETLOGS
•
The database can be opened immediately after
RESETLOGS. (No longer need to take a full backup)
•
•
No changes are required to existing scripts.
Recovery through RESETLOGS can be used for:
– Incomplete recovery
– Recovery using a backup control file
t1
Backup
taken
8-33
t2
t3
Incomplete
recovery
performed
Open with
RESETLOGS
t4
Full backup
Copyright © 2004, Oracle. All rights reserved.
t5
Recovery
needed
Recovery Through RESETLOGS: Changes
LOG_ARCHIVE_FORMAT="LOG%t_%s_%r.arc"
SQL> SELECT recid, thread#, sequence#,
2
resetlogs_change#, resetlogs_time
3 FROM
v$log_history;
SQL> SELECT recid, file#,
2
resetlogs_change#, resetlogs_time
3 FROM
v$offline_range;
SQL> SELECT incarnation#, resetlogs_id,
2
prior_incarnation#, status
3 FROM
v$database_incarnation;
8-34
Copyright © 2004, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Recognize a situation that requires incomplete
recovery
• Describe the incomplete recovery methodology
• Recover the database to a specific point in time
using:
– User-managed backups
– RMAN-managed backups
– Enterprise Manager Database Control Console
8-36
Copyright © 2004, Oracle. All rights reserved.
Practice 8 Overview: Incomplete Recovery
This practice covers the following topics:
• Point-in-time recovery using RMAN
• Database recovery using the EM Database Control
Console
8-37
Copyright © 2004, Oracle. All rights reserved.