2009 Collaborate IOUG Presentation

48
Biju Thomas OneNeck IT Services Corporation http://www.oneneck.com (Booth 4364) Session #330 Are You Using Flashback Yet?

description

Are You Using Flashback Yet?

Transcript of 2009 Collaborate IOUG Presentation

Page 1: 2009 Collaborate IOUG Presentation

Biju Thomas

OneNeck IT Services Corporation

http://www.oneneck.com (Booth 4364)

Session #330

Are You Using Flashback Yet?

Page 2: 2009 Collaborate IOUG Presentation

About the Speaker

• Senior Database Administrator at OneNeck

IT Services Corporation (www.oneneck.com)

• More than 15 years of Oracle experience

• Author of OCA Oracle Database 11g Administrator

Certified Associate Study Guide published by Sybex

• Co-author of Oracle10g, Oracle9i & Oracle8i

Certification books published by Sybex

• Published articles in Oracle Magazine, Oracle

Internals and Select Journal

• Oracle 11g, 10g, 9i, 8i & 7.3

OCP Administrator

Page 3: 2009 Collaborate IOUG Presentation

Introducing OneNeck

The ERP Outsourcing Experts

Provide a comprehensive, flexible suite of outsourcing solutions designed specifically to help mid-market and public sector organizations

• Supporting over 22,000 users at over 850 sites worldwide

• Primary data center/support center operations in Phoenix

and Houston

• Hosting and managing over 2000 databases

• 98% Contract Renewal Rate over 10 years

• 100% US based operations and staff

• 24x7x365 support center handling over 50,000 tickets

annually

• Oracle certified hosting partner

• Ranked #1 ERP Outsourcing Vendor by the Black Book of

Outsourcing three years in a row

• http://www.OneNeck.com

• Stop by booth 4364

Page 4: 2009 Collaborate IOUG Presentation

Please remember to complete the session evaluation form

Biju Thomas

Are you using Flashback yet? Session # 330

Page 5: 2009 Collaborate IOUG Presentation

Objectives

• Flashback Operations in Oracle Database

• What is Flash Recovery Area (FRA)?

• Configuring FRA

• Flashback Database

• Using & Maintaining FRA

• V$ Views for FRA and Flashback logs

Page 6: 2009 Collaborate IOUG Presentation

Flashback Operations in Oracle

Page 7: 2009 Collaborate IOUG Presentation

Flashback Query

• Introduced in Oracle 9i R1

• Use DBMS_FLASHBACK package to enable

and disable flashback

• Must use Automatic Undo Management

• Only DML operations

• PL/SQL recognizes flashback

EXECUTE DBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER (n);

EXECUTE DBMS_FLASHBACK.ENABLE_AT_TIME (‘date_time‘);

EXECUTE DBMS_FLASHBACK.DISABLE;

Page 8: 2009 Collaborate IOUG Presentation

Flashback Query #2

• Improvement in 9i R2

• AS OF TIMESTAMP and AS OF SCN clauses in query

• SYS user can use this clause

Examples:

INSERT INTO employees

SELECT * FROM employees as of timestamp

TO_TIMESTAMP('22-MAR-09 21:50', 'DD-MON-YY HH24:MI')

WHERE employee_id = 106;

EXP Parameter:

FLASHBACK_SCN=nnn

FLASHBACK_TIME="YYYY-MM-DD HH24:MI:SS" [9i fixed format]

FLASHBACK_TIME="TO_TIMESTAMP('31-MAR-09 12:00', 'DD-MON-YY

HH24:MI')" [specify format 10g onwards]

Page 9: 2009 Collaborate IOUG Presentation

Flashback Query #3

• Example: Rows updated in EMPLOYEES table.

SELECT employee_id, first_name, last_name, salary

FROM employees AS OF TIMESTAMP

TO_TIMESTAMP('22-MAR-09 21:50', 'DD-MON-YY HH24:MI')

MINUS

SELECT employee_id, first_name, last_name, salary

FROM employees;

EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY

----------- ------------- ---------------- ----------

103 Alexander Hunold 9000

106 Valli Pataballa 4800

Page 10: 2009 Collaborate IOUG Presentation

Flashback Versions Query

• Introduced in Oracle 10g R1

• Shows all changes between a timeframe

VERSIONS BETWEEN [TIMESTAMP/SCN] .. AND ..

• Upper/Lower bound may be replaced with

MINVALUE and MAXVALUE to retrieve all

available data

• VERSIONS_ pseudo columns available –

STARTTIME, STARTSCN, ENDTIME,

ENDSCN, XID, OPERATION

Page 11: 2009 Collaborate IOUG Presentation

Flashback Versions Query #2

• Example:

SELECT last_name, versions_starttime,

versions_endtime, versions_operation

FROM employees VERSIONS BETWEEN TIMESTAMP minvalue AND maxvalue

WHERE employee_id = 106

ORDER BY versions_starttime NULLS FIRST;

LAST_NAME VERSIONS_STARTTIME VERSIONS_ENDTIME V

------------- ---------------------- ---------------------- -

Pataballa 22-MAR-09 09.54.57 PM

Rojashin 22-MAR-09 09.54.57 PM 22-MAR-09 10.07.06 PM U

Hussaina 22-MAR-09 10.07.06 PM 22-MAR-09 10.14.04 PM U

Hussaina 22-MAR-09 10.14.04 PM D

Pataballa 22-MAR-09 10.17.21 PM I

Page 12: 2009 Collaborate IOUG Presentation

Flashback Transaction Query

• Introduced in Oracle 10g R1

• Enterprise Edition only

• Changes made to data at a

transaction level

• No need to use LogMiner

• Reconstruct SQL to undo

changes

• Need FLASHBACK ANY

TRANSACTON system privilege

to query view

FLASHBACK_TRANSACTION_

QUERY

FLASHBACK_TRANSACTION_QUERY

XID

START_SCN

START_TIMESTAMP

COMMIT_SCN

COMMIT_TIMESTAMP

LOGON_USER

UNDO_CHANGE#

OPERATION

TABLE_NAME

TABLE_OWNER

ROW_ID

UNDO_SQL

Page 13: 2009 Collaborate IOUG Presentation

Flashback Transaction Query #2

SELECT operation, start_timestamp, undo_sql

FROM flashback_transaction_query

WHERE table_name = 'EMPLOYEES'

AND table_owner = 'HR';

OPERATION START_TIMESTAMP

UNDO_SQL

------------------------------------------------------

UPDATE 22-MAR-09 21:53:21

update "HR"."EMPLOYEES" set "FIRST_NAME" = 'Alexander', "SALARY" = '9000'

where ROWID = 'AAARAIAAFAAAABXAAD';

DELETE 22-MAR-09 22:14:04

insert into "HR"."EMPLOYEES“ ("EMPLOYEE_ID", "FIRST_NAME", "LAST_NAME“

,"EMAIL", "PHONE_NUMBER", "HIRE_DATE", "JOB_ID", "SALARY",

"COMMISSION_PCT", "MANAGER_ID", "DEPARTMENT_ID") values ('106', 'Valli',

'Hussaina', 'VPATABAL', '590.423.4560',TO_DATE('05-FEB-98 00:00:00', 'DD-

MON-YY HH24:MI:SS'),'IT_PROG','4800',NULL,'103','60');

INSERT 22-MAR-09 22:17:13

delete from "HR"."EMPLOYEES" where ROWID = 'AAARAIAAFAAAABYAAJ';

Page 14: 2009 Collaborate IOUG Presentation

Flashback Table (Drop)

• Introduced in Oracle 10g R1 (EE)

• Recover a dropped table (does not use UNDO) DROP TABLE job_history;

Table dropped.

SHOW RECYCLEBIN

ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME

-------------- ------------------------------ ------------ -------------------

JOB_HISTORY BIN$ZcGwtQ/sKCbgQAB/AQBl2g==$0 TABLE 2009-03-22:23:27:54

FLASHBACK TABLE job_history TO BEFORE DROP;

Flashback complete.

• Option to rename table FLASHBACK TABLE jobs TO BEFORE DROP RENAME TO jobs_march;

Page 15: 2009 Collaborate IOUG Presentation

Flashback Drop #2

• Recycle bin automatically cleared when

tablespace is under “space pressure”

• Options for manually clearing space:

• To disable recyclebin:

– 10gR1: _recyclebin parameter

– 10gR2+: recyclebin parameter

PURGE TABLE <name> PURGE RECYCLEBIN

PURGE INDEX <name> PURGE DBA_RECYCLEBIN

PURGE TABLESPACE <name> DROP TABLE <name> PURGE

PURGE TABLESPACE <name>

USER <name>

Page 16: 2009 Collaborate IOUG Presentation

Flashback Table #3

• Reinstate table to a previous state using

TIMESTAMP or SCN (uses UNDO)

• ROW MOVEMENT should be enabled.

ALTER TABLE employees ENABLE ROW MOVEMENT;

Table altered.

FLASHBACK TABLE employees TO TIMESTAMP

TO_TIMESTAMP('22-MAR-09 21:50', 'DD-MON-YY HH24:MI');

Flashback complete.

Page 17: 2009 Collaborate IOUG Presentation

Flashback Database

• Introduced in Oracle 10g R1 (EE)

• Quickly rewind a database to fix any issues

• Similar to point-in-time recovery, but much

faster

• Uses flashback logs, a before image of

changed blocks

• Flashback logs saved in Flash Recovery Area

(FRA)

• 10g R2 introduced restore points and the

ability to flashback through RESETLOGS

Page 18: 2009 Collaborate IOUG Presentation

Flashback Transaction

• Introduced in Oracle 11g R1 (EE)

• Use to undo changes made by transaction

• Uses UNDO and redo logs (archive logs too)

• Requires supplemental logging of primary key ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;

• Enterprise Manager or PL/SQL interface – Under “Availability” tab, click “View and Manage

Transactions”

– DBMS_FLASHBACK.TRANSACTION_BACKOUT

procedure

Page 19: 2009 Collaborate IOUG Presentation
Page 20: 2009 Collaborate IOUG Presentation

Flashback Data Archive

• Introduced in Oracle 11g R1 (EE)

• Total Recall Option – separate license.

• Automatically track and maintain changes to data in

an application transparent and secure manner.

• Uses AS OF construct in SQL.

• Historical data can be kept for any specified duration

– not dependent on undo or flashback log data.

• RETENTION specified in the data archive.

• New background process “fbda” captures historic

information in a non-intrusive manner.

• New record added to history table only for update &

delete statements.

Page 21: 2009 Collaborate IOUG Presentation

Settings for Undo Flashback

• Enabling automatic Undo

– UNDO_MANAGEMENT = AUTO

• Parameters controlling amount of undo retained:

– UNDO_RETENTION

• Guaranteed retention option available

– ALTER TABLESPACE <undots> RETENTION

GUARANTEE

• Flashback Operations using Undo

– FB Query, FB Versions Query, FB Transaction, FB

Transaction Query, FB Table

Page 22: 2009 Collaborate IOUG Presentation

Flash Recovery Area (FRA)

Page 23: 2009 Collaborate IOUG Presentation

Flash Recovery Area

• Area of disk location where recovery related

files are stored

• Managed via Oracle Managed Files

• Free space automatically managed by

Oracle, obsolete files under current retention

policies are deleted when space needed.

• Can act as a disk cache for backup files

before writing to tape

• Flashback logs required to use the Flashback

database feature are created only in FRA

Page 24: 2009 Collaborate IOUG Presentation

Flash Recovery Area #2

• Need to specify the disk quota.

• Preferable to be on a different disk where

database files are not stored.

• Permanent and transient files can be stored –

permanent files are copies of redo logs and

control file.

• FRA can be on ASM disk

• Oracle server alerts monitors the reclaimable

space in FRA

Page 25: 2009 Collaborate IOUG Presentation

Configuring FRA

• DB_RECOVERY_FILE_DEST_SIZE

– Specify the maximum space allocated for FRA

• DB_RECOVERY_FILE_DEST

– Location of the FRA

• For RAC databases, all instances must have

same values

• DB_FLASHBACK_RETENTION_TARGET

– Specify in minutes how much flashback log

information should be retained – Default 1440.

Page 26: 2009 Collaborate IOUG Presentation

FRA Contents

• Permanent Files

– Copy of control file

– Copy of redo log files

• Transient Files

– Archive log files

– Flashback logs

– RMAN control file and spfile autobackup

– RMAN image copies & backup sets

Example File Name: /u05/flash_recovery_area/11GR11/backupset/2009_03_26/o1_mf_

annnn_TAG20090326T004654_4wp5rntg_.bkp

Page 27: 2009 Collaborate IOUG Presentation

Sizing FRA

• Bigger the FRA, more useful it becomes

• Recommendation: DB Size + Incr backups +

archive logs + flashback logs

• Flashback logs generated are approximately

similar in size to redo logs generated.

• If there is not enough free space in FRA,

flashback logs are deleted to make room.

Page 28: 2009 Collaborate IOUG Presentation

Using Database Flashback

Page 29: 2009 Collaborate IOUG Presentation

Configuring Flashback

• Enable flashback on the database in mount

state. SHUTDOWN IMMEDIATE;

STARTUP MOUNT;

ALTER DATABASE FLASHBACK ON;

ALTER DATABASE OPEN;

• Flashback logs will be written to FRA, and

oldest logs deleted when FRA becomes full.

• Database must be in ARCHIVELOG mode.

Page 30: 2009 Collaborate IOUG Presentation

Flashback a Database

• To flashback a database is similar to

performing a point-in-time recovery

• RESETLOGS required to open database. SHUTDOWN IMMEDIATE;

STARTUP MOUNT;

FLASHBACK DATABASE TO [BEFORE] [SCN | TIME |

SEQUENCE ] = value;

ALTER DATABASE OPEN RESETLOGS;

• Archive logs may be used to fill-in the gaps

Page 31: 2009 Collaborate IOUG Presentation

Using Restorepoints

• Introduced in Oracle 10g R2

• Very useful when performing planned

maintenance

• Option to guarantee flashback CREATE RESTORE POINT before_patch;

CREATE RESTORE POINT before_patch GUARANTEE

FLASHBACK DATABASE;

FLASHBACK DATABASE TO RESTORE POINT before_patch;

DROP RESTORE POINT before_patch;

Page 32: 2009 Collaborate IOUG Presentation

Using Flashback for DR Testing

• Setup FRA and enable flashback logs in the standby

database

• Create a restore point to go back to

• Disable log transport to standby database from primary

• Activate the standby database and open database.

• When testing is completed, revert back to the restore

point using FLASHBACK DATABASE.

• Convert the database to physical standby again

• Catch up the standby database to primary database

• Enable log transport from primary

Page 33: 2009 Collaborate IOUG Presentation

Standby Redo-apply Delay`

• Oracle provides time delay in applying the

archivelogs to the standby database to delay the

propagation of errors and corruption to standby

database.

• By having flashback logging on the standby

database, you can always flashback the standby

database, thus eliminate using time-delay.

• You can flashback and open the standby database,

get the rows/tables that were messed up and put the

standby database back in recovery mode.

• This helps to avoid outage to primary database for

non-critical data recovery.

Page 34: 2009 Collaborate IOUG Presentation

Using and Maintaining FRA

Page 35: 2009 Collaborate IOUG Presentation

Automated RMAN Backups

• When no FORMAT clause is specified for

RMAN backups, they go into FRA.

• Automatic controlfile and spfile backups may

be configured to go to FRA.

• Consider keeping image copies in FRA, with

incrementally updated backups (and with

optional rolling window) RUN

{ RECOVER COPY OF DATABASE WITH TAG 'daily_incr'

UNTIL TIME 'SYSDATE - 3';

BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG

'daily_incr' DATABASE;

}

Page 36: 2009 Collaborate IOUG Presentation

RMAN FORMAT Clause

• If you perform RMAN disk backups with the

FORMAT clause specifying the FRA location,

they are not managed by Oracle and not

considered for FRA cleanup and FRA space

management algorithm.

• So, to backup to FRA, do not specify the

FORMAT clause, the default location is the

FRA for RMAN backups when FRA is

configured. RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK CLEAR;

Page 37: 2009 Collaborate IOUG Presentation

Backing up FRA

• FRA can be backed up only using RMAN RUN {

ALLOCATE CHANNEL CH01T TYPE sbt_tape;

BACKUP RECOVERY AREA;

}

• Flashback logs, the current control file, and

online redo logs are not backed up.

• This statement can only back up to a tape

device, disk is not supported.

Page 38: 2009 Collaborate IOUG Presentation

Using LOG_ARCHIVE_DEST_n

• If you explicitly specify the FRA location in the

LOG_ARCHIVE_DEST_n parameter, the

archive logs are not considered in the FRA

space management algorithm and they are

not backed up when you specify the BACKUP

RECOVERY AREA command.

• The correct specification is

log_archive_dest_n=

'LOCATION= USE_DB_RECOVERY_FILE_DEST'

Page 39: 2009 Collaborate IOUG Presentation

FRA Full Errors

• Once the Flash Recovery Area is full, Oracle

automatically deletes eligible files to reclaim space in

the Flash Recovery Area as needed.

• Oracle may delete flashback logs from the earliest

SCNs to make room for other files.

• Alert log errors:

ORA-19809: limit exceeded for recovery files

ORA-19804: cannot reclaim <nnnnn> bytes disk

space from <mmmmm> limit

ORA-19815: WARNING: db_recovery_file_dest_size of

<size of FRA configured> bytes is 100.00% used,

and has 0 remaining bytes available.

Page 40: 2009 Collaborate IOUG Presentation

Resolving Full FRA

• Make more space available by adjusting

DB_RECOVERY_FILE_DEST_SIZE.

• Backup the contents of the Flash Recovery

Area to a tertiary device such as tape.

• Change backup retention policy. CONFIGURE RETENTION POLICY TO RECOVERY WINDOW

OF 7 DAYS;

• Change archive log deletion policy. CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED

UP 1 TIMES TO SBT;

Page 41: 2009 Collaborate IOUG Presentation

V$ Views

Page 42: 2009 Collaborate IOUG Presentation

Backups/Logs Using FRA

• Find out if backups and archive logs are part

of the FRA algorithm

– IS_RECOVERY_DEST_FILE column in

V$BACKUP_PIECE

– IS_RECOVERY_DEST_FILE column in

V$ARCHIVED_LOG

Page 43: 2009 Collaborate IOUG Presentation

V$RECOVERY_FILE_DEST

• Find out the current location, disk quota, space in

use, space reclaimable by deleting files, and total

number of files in the Flash Recovery Area.

SQL> select * from v$recovery_file_dest;

NAME

SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES

------------ ------------ ----------------- --------------

/u01/app/oracle/flash_recovery_area

15728640000 9448377344 10272768 213

Page 44: 2009 Collaborate IOUG Presentation

V$FLASH_RECOVERY_AREA_USAGE

• Find out the percentage of the total disk quota used by different

types of files. Determine how much space for each type of file can

be reclaimed by deleting files that are obsolete, redundant, or

already backed up to tape. SQL> SELECT FILE_TYPE, PERCENT_SPACE_USED USED, PERCENT_SPACE_RECLAIMABLE RECLAIM,

NUMBER_OF_FILES FILES FROM V$FLASH_RECOVERY_AREA_USAGE;

FILE_TYPE USED RECLAIM FILES

-------------------- ---------- ---------- ----------

CONTROL FILE 0 0 0

REDO LOG 0 0 0

ARCHIVED LOG 61.66 51.2 216

BACKUP PIECE 19.07 9.7 31

IMAGE COPY 4.93 .4 8

FLASHBACK LOG 1.24 0 9

FOREIGN ARCHIVED LOG 0 0 0

Page 45: 2009 Collaborate IOUG Presentation

V$FLASHBACK_DATABASE_LOG

• Estimate how far back you can rollback the

database using flashback logs, and estimated

size based on retention target.

SQL> select * from v$flashback_database_log;

OLDEST_FLASHBACK_SCN OLDEST_FL RETENTION_TARGET FLASHBACK_SIZE

-------------------- --------- ---------------- --------------

ESTIMATED_FLASHBACK_SIZE

------------------------

8257936 25-MAR-09 1440 194478080

4303306752

Page 46: 2009 Collaborate IOUG Presentation

Items Learned in this Session

• Flashback Operations

– Think of flashback before saying “no” or getting

ready to recover

• Flash Recovery Area

– It’s worth even if you use it just for flashback logs

– Do not specify FORMAT clause for RMAN or

directory name for archive log destination

• Flashback Database

– Good for critical patching activities, migrations

– Use restorepoints

Page 47: 2009 Collaborate IOUG Presentation

Questions…?

Page 48: 2009 Collaborate IOUG Presentation

Thank You…

• Please complete the session evaluation form

– Biju Thomas

– Are you using Flashback yet?

– Session # 330

• Further questions, comments…

– Stop by Booth # 4364

– WWW.ONENECK.COM