27
6 Copyright © 2006, Oracle. All rights reserved. Flashback

6 Copyright © 2006, Oracle. All rights reserved. Flashback

Embed Size (px)

Citation preview

Page 1: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

6Copyright © 2006, Oracle. All rights reserved.

Flashback

Page 2: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Objectives

After completing this lesson, you should be able to:

• Query the recycle bin

• Configure Flashback Database

• Perform Flashback Database to a point in time

• Monitor flashback log statistics

• Enable and disable the Flashback Database feature

• Use the Enterprise Manager Recovery Wizard to perform Flashback Database

• Use guaranteed restore points with Flashback Database

Recycle binFlashback DBConfig. FB DBMonitor FB DBGuar. Res. Pt.

Page 3: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Flashback Technology: Review

Object Level Scenario Examples

FlashbackTechnology Uses

AffectsData

Database Truncate table; Undesired multitable changes made

Database Flashback logs

TRUE

Table Drop table Drop Recycle bin TRUE

Update with the wrong WHERE clause

Table Undo data TRUE

Compare current data with data from the past

Query Undo data FALSE

Compare versions of a row

Version Undo data FALSE

Tx Investigate several historical states of data

Transaction Undo data FALSE

Page 4: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Flashback Drop and the Recycle Bin

DROP TABLE employees;

FLASHBACK TABLEemployeesTO BEFORE DROP; Mistake was

made.

RECYCLEBIN=ON

Page 5: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

3

21

Recycle Bin

DROP TABLE employees;

BIN$zbjra9wy==$0EMPLOYEES_PK

EMPLOYEES

Recyclebin

DBA_FREE_SPACE

BIN$zbjrBdpw==$0

USER_OBJECTS

BIN$zbjrBdpw==$0 EMPLOYEESBIN$zbjra9wy==$0 EMPLOYEES_PK

4

Objects are:

– Renamed

– Not moved

Page 6: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Restoring Tables from the Recycle Bin

• Restore dropped tables and dependent objects.

• If multiple recycle bin entries have the same original name:– Use unique, system-generated names to restore a

particular version– When using original names, the restored table is

last in, first out (LIFO)

• Rename the original name if that name is currently used.

FLASHBACK TABLE <table_name>TO BEFORE DROP [RENAME TO <new_name>];

Page 7: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Recycle Bin: Automatic Space Reclamation

BIN$zbjrBdpw==$0 BIN$zbjra9wy==$0

BIN$zbjra9wy==$0

BIN$zbjrBdpw==$0

1

2

3

Recycle bin

DBA_FREE_SPACE - RECYCLEBIN

Autoextend

Page 8: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Recycle Bin: Manual Space Reclamation

PURGE {TABLE <table_name>|INDEX <index_name>}

PURGE TABLESPACE <ts_name> [USER <user_name>]

PURGE [USER_|DBA_]RECYCLEBIN

Page 9: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Bypassing the Recycle Bin

DROP TABLESPACE <ts_name> [INCLUDING CONTENTS] ;

DROP USER <user_name> [CASCADE] ;

DROP TABLE <table_name> [PURGE] ;

Page 10: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Querying the Recycle Bin

SELECT owner, original_name, object_name, type, ts_name, droptime, related, spaceFROM dba_recyclebinWHERE can_undrop = 'YES';

SELECT original_name, object_name, type, ts_name, droptime, related, spaceFROM user_recyclebinWHERE can_undrop = 'YES';

SQL> SHOW RECYCLEBIN

Page 11: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Querying Data fromDropped Tables

SELECT ... FROM "BIN$zbjrBdpw==$0" [AS OF ...]WHERE ...

Recyclebin

USER_INDEXES

YES

INDEX_NAMEDROPPED

NO SALES_PK

USER_TABLESTABLE_NAMEDROPPED

YES

NO SALES

BIN$zbjrBdpw==$0 EMPLOYEES

BIN$zbjra9wy==$0 EMPLOYEES_PK

Page 12: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Flashback Database: Review

The Flashback Database operation:

• Works like a rewind button for the database

• Can be used in cases of logical data corruptions made by users

The database is corrupted.

The database is “rewound.”

You “press the rewind button.”

Users generate errors.

Recycle bin> Flashback DB

Config. FB DBMonitor FB DBGuar. Res. Pt.

Page 13: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Flashback Database Architecture

Flashbackbuffer

Redo logbuffer

SGA

LGWR

RVWRFlashbacklogs

Redologs

… …

Buffer cache

1

Log blockbeforeimages

periodically.

Back out changesto database using

before images.

Do forward media recovery.

Everychange

Not everychange!

2

Page 14: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Configuring FlashbackDatabase

1. Configure the flash recovery area.

3. Enable Flashback Database.

2. Set the retentiontarget.

SQL> SHUTDOWN IMMEDIATE;SQL> STARTUP MOUNT EXCLUSIVE;SQL> ALTER SYSTEM SET

2 DB_FLASHBACK_RETENTION_TARGET=2880 SCOPE=BOTH;

SQL> ALTER DATABASE FLASHBACK ON;SQL> ALTER DATABASE OPEN;

Recycle binFlashback DB

> Config. FB DBMonitor FB DBGuar. Res. Pt.

Page 15: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Configuring Flashback Database Using EM

Make sure that the database is in ARCHIVELOG mode.

Page 16: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Configuring Flashback Database Using EM

Enable flashback logging and specify the flash recovery area.

Page 17: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Flashback Database: Examples

RMAN> FLASHBACK DATABASE TO TIME = 2> "TO_DATE('2004-05-27 16:00:00', 3> 'YYYY-MM-DD HH24:MI:SS')";

RMAN> FLASHBACK DATABASE TO SCN=23565;

RMAN> FLASHBACK DATABASE 2> TO SEQUENCE=223 THREAD=1;

SQL> FLASHBACK DATABASE 2 TO TIMESTAMP(SYSDATE-1/24);

SQL> FLASHBACK DATABASE TO SCN 53943;

SQL> FLASHBACK DATABASE TO RESTORE POINT b4_load;

Page 18: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Performing Flashback Database Using EM

Select object and

operation type.

Page 19: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Performing Flashback Database Using EM

Launching the Recovery Wizard:

Page 20: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Performing Flashback Database Using EM

Page 21: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Excluding Tablespaces from Flashback Database

• Take the tablespace offline before you perform the Flashback Database recovery.

• Drop the tablespace or recover the offline files with traditional point-in-time recovery.

ALTER TABLESPACE <ts_name> FLASHBACK {ON|OFF}

SQL> SELECT name, flashback_on 2 FROM v$tablespace;

Page 22: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Flashback Database Considerations

• When the Flashback Database operation completes, open the database:– In read-only mode to verify that the correct target

time or SCN was used– With a RESETLOGS operation to allow for DML

• The opposite of “flash back” is “recover.”

• You cannot use Flashback Database in the following situations:– The control file has been restored or re-created.– A tablespace has been dropped.– A data file has been shrunk.

• Use the TO BEFORE RESETLOGS to flash back to before the last RESETLOGS operation.

Page 23: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Monitoring FlashbackDatabase

To monitor the ability to meet your retention target:

• View the flash recovery area disk quota:

• Determine the current flashback window:

• Monitor logging in the Flashback Database logs:

SQL> SELECT estimated_flashback_size, 2 flashback_size 3 FROM V$FLASHBACK_DATABASE_LOG;

SQL> SELECT * 2 FROM V$FLASHBACK_DATABASE_STAT;

SQL> SELECT oldest_flashback_scn, 2 oldest_flashback_time 3 FROM V$FLASHBACK_DATABASE_LOG;

Recycle binFlashback DBConfig. FB DB

> Monitor FB DBGuar. Res. Pt.

Page 24: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Monitoring Flashback Database with EM

Page 25: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Guaranteed Restore Points

A guaranteed restore point ensures that you can perform a FLASHBACK DATABASE command to that SCN at any time.

SQL> CREATE RESTORE POINT before_load

2 GUARANTEE FLASHBACK DATABASE;

Recycle binFlashback DBConfig. FB DBMonitor FB DB

> Guar. Res. Pt.

Page 26: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Summary

In this lesson, you should have learned how to:

• Query the recycle bin

• Configure Flashback Database

• Perform Flashback Database to a point in time using Enterprise Manager or RMAN

• Monitor flashback log statistics

• Enable and disable the Flashback Database feature

• Use guaranteed restore points with Flashback Database

Page 27: 6 Copyright © 2006, Oracle. All rights reserved. Flashback

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

Practice Overview: Performing Flashback Database

This practice covers the following topics:

• Performing Flashback Database to undo unwanted transactions

• Monitoring the Flashback Database retention

• Determine the size of the flashback logs