30
Copyright © 2006, Oracle. All rights reserved. Database Recovery

les_05 os

  • Upload
    pnkj232

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 1/30

Copyright © 2006, Oracle. All rights reserved.

Database Recovery

Page 2: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 2/30

5-2 Copyright © 2006, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to:

• Perform complete or incomplete user-managed

recovery

Identify situations where incomplete recovery isnecessary

• 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

User man.

RMAN CLI

EM

Complete

Incomplete

Control file

RO TBS 

Page 3: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 3/30

5-3 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.

Page 4: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 4/30

5-4 Copyright © 2006, Oracle. All rights reserved.

User-Managed Recovery:RECOVER  Command

• Restore all database files from a backup and then

recover the database:

• Restore the damaged data files from a backup andthen recover the data files:

Or:

SQL> RECOVER DATABASE

SQL> RECOVER TABLESPACE index_tbs

SQL> RECOVER DATAFILE2> '/oradata/indx01.dbf'

Page 5: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 5/30

5-5 Copyright © 2006, Oracle. All rights reserved.

RMAN Recovery: RESTORE 

and RECOVER  Commands

run{

sql "ALTER TABLESPACE inv_tbs OFFLINE IMMEDIATE";RESTORE TABLESPACE inv_tbs;

RECOVER TABLESPACE inv_tbs DELETE ARCHIVELOG;

sql "ALTER TABLESPACE inv_tbs ONLINE";

}

User man.

> RMAN CLI

EM

Complete

Incomplete

Control fileRO TBS 

Page 6: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 6/30

5-6 Copyright © 2006, Oracle. All rights reserved.

Recovery Using

Enterprise Manager

With the Enterprise Manager Recovery Wizard, you can

create and run an RMAN script to perform the recovery.

RMAN> RECOVER DATABASE … 

User man.

RMAN CLI

> EM

Complete

Incomplete

Control file

RO TBS 

Page 7: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 7/305-7 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.

• Incomplete recovery brings the database up to a

specified point in time in the past, before the

recovery operation was requested.

Recovery

task started

at this time

Complete

recovery

Incomplete

recovery

Missing transactionsafter incomplete recoveryRestore fromthis backup

Page 8: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 8/305-8 Copyright © 2006, Oracle. All rights reserved.

Complete Recovery

Restoreddata files

Data files containingcommitted anduncommittedtransactions

Recovereddata files

Changes applied

Undo applied

6

5

3

2

1

Archivedlog Archived

log OnlineRedo log

User man.

RMAN CLI

EM

> Complete

Incomplete

Control fileRO TBS 

4

Databaseopened

Page 9: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 9/305-9 Copyright © 2006, Oracle. All rights reserved.

Incomplete Recovery

Data files containingcommitted anduncommitted

Transactions up to PIT

PIT-recovereddata files

Undo applied

6

5

3

2

1

Archivedlog Archived

log OnlineRedo log

4

Databaseopened

XX

Changes applied to point in time (PIT)

Restored datafiles from as far

back as necessary

User man.

RMAN CLI

EM

Complete

> Incomplete

Control fileRO TBS 

Page 10: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 10/305-11 Copyright © 2006, Oracle. All rights reserved.

Situations Requiring Incomplete Recovery

• 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.

Page 11: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 11/305-12 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

Page 12: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 12/305-14 Copyright © 2006, Oracle. All rights reserved.

Performing User-Managed

Incomplete Recovery

• Recover a database until time:

• Recover a database until cancel:

• Recover using the backup control file:

SQL> RECOVER DATABASE UNTIL CANCEL;

SQL> RECOVER DATABASE UNTIL

2 TIME '2005-12-14:12:10:03';

SQL> RECOVER DATABASE2 UNTIL TIME '2005-12-14:12:10:03'3 USING BACKUP CONTROLFILE;

Page 13: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 13/305-15 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.

Page 14: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 14/305-16 Copyright © 2006, Oracle. All rights reserved.

User-Managed Time-Based Recovery:

Example

SQL> SHUTDOWN IMMEDIATE$ cp /BACKUP/* /u01/db01/ORADATASQL> STARTUP MOUNTSQL> RECOVER  DATABASE UNTIL TIME '2005-11-28:11:44:00';SQL> ALTER DATABASE OPEN RESETLOGS; 

This is the scenario:

• A job ran in error, and its effects have to be

undone.

This happened 15 minutes ago, and there hasbeen little database activity since then.

•  You decide to perform incomplete recovery to

restore the database back to its state as of 15

minutes ago.

Page 15: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 15/305-18 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.

Page 16: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 16/305-19 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 thedatabase.

4. Execute RECOVER  DATABASE UNTIL CANCEL.

5. Execute ALTER  DATABASE OPEN RESETLOGS to

open the database.

Page 17: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 17/305-20 Copyright © 2006, Oracle. All rights reserved.

Performing Incomplete Recovery

by Using RMAN

1. Mount the database.

2. Allocate multiple channels for parallelization.

3. Restore all data files.

4. Recover the database by using UNTIL TIME,UNTIL SEQUENCE, or UNTIL SCN.

5. Open the database by using RESETLOGS.

Page 18: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 18/305-21 Copyright © 2006, Oracle. All rights reserved.

Time-Based Recovery

Using RMAN: Example

RMAN> RUN {

2> SET UNTIL TIME = '2005-11-28:11:44:00';

3> RESTORE DATABASE;

4> RECOVER DATABASE;

5> ALTER DATABASE OPEN RESETLOGS; }

Page 19: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 19/305-23 Copyright © 2006, Oracle. All rights reserved.

Log Sequence Recovery

Using RMAN: Example

RMAN> RUN {2> SET UNTIL SEQUENCE 120 THREAD 1;3> ALTER DATABASE MOUNT;4> RESTORE DATABASE;

5> RECOVER DATABASE; # recovers through log 1196> ALTER DATABASE OPEN RESETLOGS;7> }

Page 20: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 20/305-24 Copyright © 2006, Oracle. All rights reserved.

Incomplete Recovery Using

Enterprise Manager

Page 21: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 21/305-25 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.

Page 22: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 22/305-26 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: 

 – RECOVER DATABASE 

 – FLASHBACK DATABASE

 – FLASHBACK TABLE

SQL> CREATE RESTORE POINT before_load;

 before_load

RMAN> RECOVER DATABASE UNTIL RESTORE POINT before_load;2

1

Page 23: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 23/305-27 Copyright © 2006, Oracle. All rights reserved.

Incomplete Recovery: Best Practices

• 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.

Page 24: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 24/305-29 Copyright © 2006, Oracle. All rights reserved.

Recovering a Control File

Autobackup

RecoveryManager

(RMAN) Flash recoveryarea

Database

Control

file

RECOVER DATABASE;

 ALTER DATABASE OPEN

RESETLOGS;

 ALTER TABLESPACE temp ADDTEMPFILE...;

RMAN> RESTORE CONTROLFILE TO2> '/oradata/ctlfile.bak' FROM AUTOBACKUP;

User man.

RMAN CLI

EM

Complete

Incomplete

> Control file

RO TBS

Page 25: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 25/30

Page 26: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 26/30

5-32 Copyright © 2006, Oracle. All rights reserved.

Creating a New Control File

Page 27: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 27/30

5-33 Copyright © 2006, Oracle. All rights reserved.

Recovering Read-Only

Tablespaces

Change

Tablespace

State

Crash

and perform

recovery

Case 1

Case 2

Case 3

Backup

Read-only

Read/write

Read-only

Read-only

Read/write

*

*

*

* Control file

backup to be

used for recovery

if current one lost

User man.

RMAN CLI

EM

Complete

Incomplete

Control file

> RO TBS

Page 28: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 28/30

5-35 Copyright © 2006, Oracle. All rights reserved.

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

Page 29: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 29/30

5-37 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 usingRMAN

• 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

Page 30: les_05 os

8/13/2019 les_05 os

http://slidepdf.com/reader/full/les05-os 30/30

Practice Overview: Performing

Incomplete Recovery

This practice covers the following topics:

• Point-in-time recovery using RMAN

• Recovery from the loss of control files