2009 Sengupta Flashback Snapshot

40
1 Backup and Recovery Using Flashback / Snapshot Sumit Sengupta EDS, an HP Company

Transcript of 2009 Sengupta Flashback Snapshot

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 1/40

1

Backup and Recovery UsingFlashback / Snapshot

Sumit Sengupta

EDS, an HP Company

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 2/40

Basic Properties

• Follows Read Consistency/Snapshot• Re-plays data from Undo Segments

• Only SQL interface changed in 9i

• Init.ora Parameters UNDO_RETENTION = <N> Secs

UNDO_MANAGEMENT = AUTO UNDO_TABLESPACE = <TS_NAME>

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 3/40

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 4/40

Types of Flashback

• Version query • Transaction query

Table drop ( Recyclebin >= 10G )• Database ( Flashback Mode >= 10G )

• Transaction ( 11G )

• Data Archive ( Total Recall, 11G )

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 5/40

Beyond Oracle FlashbackSnapshot Storage Backups

•  Vendor Specific• Storage Layer – Instant Point of Time

 Akin to Flashback Database

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 6/40

Flashback Version Query

• Relies on Undo ( >= 9i )• SQL driven – Past Data for a single query

Session – Past data for the session• More Pseudo Columns in 10G.

•  “Past” – based on SCN or Time

• SCN to Time conversion functions in 10G.

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 7/40

Pseudo Columns ( >= 10G )

•  VERSIONS_STARTTIME•  VERSIONS_STARTSCN

•  VERSIONS_ENDTIME

•  VERSIONS_ENDSCN

•  VERSIONS_XID

•  VERSIONS_OPERATION• ORA_ROWSCN

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 8/40

SCN And Timestamp..1

Easy Conversions using functionsSQL> select sysdate from dual ;

SYSDATE

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

27-nov-08 13:28:15

SQL> select current_scn from v$database;

CURRENT_SCN

-----------

573468

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 9/40

SCN And Timestamp..2

•SQL> select scn_to_timestamp ( 573468 )from dual

SCN_TO_TIMESTAMP(573468)

-----------------------------------27-NOV-08 01.28.15.000000000 PM 

• For 9i, Look at SYS.SMON_SCN_TIME

• Updated Every 5 Mts

• See Note# 365536.1

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 10/40

SQL Driven Flashback SQL

SQL> SELECTfirst_name, salary, versions_starttime,

versions_startscn, versions_endtime,versions_endscn, versions_xid,

versions_operationFROM emp

VERSIONS BETWEEN SCN minvalue and

 maxvalue

 WHERE

employee_id = 107 ;

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 11/40

Results

FIRST SALARY STARTTIMESTARTSCN ENDTIME ENDSCN VERSIONS_XID DML

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

Diana 4500 06-JAN-09 12.44.26 AM 1192643 # #0200250051020000 U

Diana 4200 # #06-JAN-09 12.44.26 AM  1192643 ##

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 12/40

SQL Driven 9i Query

SQL> SELECT ...FROM emp

 AS OF SCN 564398

 WHERE

employee_id = 107 ;

SCN or Timestamp – Approx.conversions in SYS.SMON_SCN_TIME

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 13/40

Session Driven Query

• DBMS_FLASHBACK Package ( >= 9i )• Enable at Specific Time/SCN for Session

No DDL While in flashback modeSQL > drop table emp ;

ORA-08182: operation not supported 

while in Flashback mode• Other Sessions can issue DDL

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 14/40

Pseudo ColumnORA_ROWSCN

• Last DML Time ( at the block level )• Unless table has “Row Dependency” 

Needs to be created with that option• CTAS does not get it

• Cannot use it in Versions Query

• Helps Replication Parallel Propagation

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 15/40

Create Table With Row Dep.

SQL>CREATE TABLE emp ( column list )… ;

SQL>CREATE TABLE emp_dep ( column list )…

ROWDEPENDENCIES;

SQL> select distinctdbms_rowid.rowid_block_number (rowid)"Block", count(1) from emp group bydbms_rowid.rowid_block_number (rowid) ;

Block COUNT(1)

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

388 98

389 9

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 16/40

 Additional Space NeededSQL> select …from emp_dep group by … ;

Block Dep COUNT(1)

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

404 92

405 15

SQL> select table_name, dependencies, avg_row_lenfrom user_tables ;

TABLE_NAME DEPENDEN AVG_ROW_LEN

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

EMP DISABLED 71EMP_DEP ENABLED 77

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 17/40

Update Rows With Delay

 beginfor empid in 189..197

loop

update emp set salary = salary +1000 where id = empid ;

commit ;

dbms_lock.sleep (10) ;

end loop ;

end ;

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 18/40

Table Without RowDependency

SQL> select id, scn_to_timestamp

(ora_rowscn) DML_TIME from emp where

id between 189 and 190 ;

ID DML_TIME

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

189 28-NOV-08 02.46.31.000000000 PM

190 28-NOV-08 02.46.31.000000000 PM 

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 19/40

Table With Row Dependency

SQL> select id, scn_to_timestamp

(ora_rowscn) DML_TIME from emp_dep

where id between 189 and 190 ;

ID DML_TIME

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

189 28-NOV-08 02.51.18.000000000 PM

190 28-NOV-08 02.51.28.000000000 PM 

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 20/40

Types of Flashback

•  Version query• Transaction query

Table drop ( Recyclebin >= 10G )• Database ( Flashback Mode >= 10G )

• Transaction ( 11G )

• Data Archive ( Total Recall, 11G )

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 21/40

Flashback Transaction Query

Quick “Logminer” in 10G• Needs “Select Any Txn” System PrivilegeSQL> select commit_timestamp, undo_sqlfrom flashback_transaction_query where

table_name = 'EMP' and table_owner ='HR' ;

COMMIT_TIMESTAMP UNDO_SQL

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

06-jan-09 00:54:50 update "HR"."EMP"set "SALARY" = '4500' where ROWID ='AAANJjAAEAAAAHFAAg';

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 22/40

Types of Flashback

•  Version query

• Transaction query

• Table drop ( Recyclebin >= 10G )• Database ( Flashback Mode >= 10G )

Transaction ( >= 11G )• Data Archive ( Total Recall >= 11G )

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 23/40

Flashback Table/Recycle Bin

• Does not rely on UNDO Segments• Table Drop Keeps TS Space and Quota

• No limit on retention !

• RI/FK not restored

• Indexes need to be renamed after

flashback • No flashback from truncate table !

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 24/40

Flashback Table - Restrictions

SQL> flashback table emp to timestamp( systimestamp -3/24 ) ;

ERROR at line 1:

ORA-08189: cannot flashback the table

 because row movement is not enabled • SQL> flashback table emp_modified totimestamp ( systimestamp -1/24 ) ;

ERROR at line 1:

ORA-01466: unable to read data - tabledefinition has changed 

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 25/40

Flashback Table – Example

SQL> flashback table emp to before drop ;• SQL> select index_name from user_indexeswhere table_name = 'EMP' ;

INDEX_NAME

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

BIN$XOC7UfSrQTLgQKjAbg8oPQ==$0

• SQL> alter index

"BIN$XOC7UfSrQTLgQKjAbg8oPQ==$0" renameto EMP_UK ;

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 26/40

More on Recyclebin

• Sessions have it enabled by default• Purge Recyclebin removes it

permanently

• Dropping user purges all its objects.

• Indexes cannot be flashed back

independently

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 27/40

Types of Flashback

•  Version query• Transaction query

Table drop ( Recyclebin >= 10G )• Database ( Flashback Mode >=

10G )

• Transaction ( 11G )• Data Archive ( Total Recall, 11G )

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 28/40

Flashback Database

• Restore Point SCN/Timestamp• Can be Normal or Guaranteed

Flashback Log Stored in FRA • Database Must be in Archive Mode

• DB needs to be in Mount State to

Convert to Flashback Mode• Flashback Mode is not necessary

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 29/40

When DB is not in FlashbackMode

Restore Point Info Stored in UNDO TS• Cannot Restore Beyond UNDO

Retention for Normal Restore Points

• db_flashback_retention_targetirrelevant

•  V$ Views on flashback Logs are empty

• For Guaranteed RP, Flashback Logs aregenerated. Guarantee for DB only.

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 30/40

Database in Flashback Mode

Retention_Target ( defaults 1 day )• Still needs UNDO for normal RP.

• Guaranteed RPs – Guarantee for entire

DB• Restoring a Table to a guaranteed RP

depends on UNDO Space

• Flashback DB requires DB in mountmode and needs a Resetlogs to open

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 31/40

Flashback DB – Issues

Logs not always deleted. Bug#5106952• Not deleted during auto-backup-

bug#7390954

• Guaranteed RP delete on Linux cleanedup space as expected

• Upon Flashback and resetlogs, all priorlogs and backups need to be deletedmanually from FRA 

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 32/40

Types of Flashback

•  Version query• Transaction query

• Table drop ( Recyclebin >= 10G )

• Database ( Flashback Mode >= 10G )

• Transaction ( 11G )

• Data Archive ( Total Recall, 11G )

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 33/40

Flashback Transaction

DBMS_FLASHBACK.TRANSACTION_BACKOUTprocedure

NOCASCADE (def) – Assumes no dependency

CASCADE – Backs out dependent txnsNOCASCADE_FORCE – Ignores dependencies

NONCONFLICT_ONLY – Only non-conflictingrows rolled back, txn atomicity is lost.

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 34/40

Oracle Total Recall/Flashback Archive

Retention Based Archive of tables• Tablespace Quota can be limited

SQL> create tablespace fl_arc1 ;

SQL> create flashback archive fl_arc1tablespace fl_arc1 quota 100Gretention 1 year;

SQL> create table emp (..) flashback

archive fl_arc1 ;SQL> select * from emp as of SCN7634512 ;

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 35/40

Non-Oracle Solutions -Snapshot Backup

Storage Vendor Specific• Network Appliance – Snapshot

• NAS – SAN Merge ?

• Netapp – Raid-DP/ RAID-16

• Create an aggregate

• Within an Aggregrate, Create Raidgroups of 16 disks RAID-DP

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 36/40

RAID-DP

Double Protection-Extension of RAID 4• Can protect data against 2 disk failures

• Default “Fragment” size – 4 KB

• Recommended Raid size 16 disks

•  “WAFL” Disk Volumes

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 37/40

Storage Hierarchy

 Aggregate -> Volume -> Qtree -> Lun•  A lun is typically one physical disk 

•  ASM best practice – One Volume/DB

• Two Qtrees ( Data and Flash )/ Volume

• Data and Flash Luns are same size

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 38/40

Snapshot

Freezes blocks for write.• Extremely fast – regardless of size

• Minimum space reserved in Volume

• Database needs to be in backup mode

•  “Snap Manager” helps automate that

• Other “Snap” tools for DR, Versioningetc.

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 39/40

Lessons Learned

 A lot of overhead storage in RAID,Snapshot

• Snap Manager not supported on all

OS/ASM

• Easy integration with RMAN

8/17/2019 2009 Sengupta Flashback Snapshot

http://slidepdf.com/reader/full/2009-sengupta-flashback-snapshot 40/40

40

Thank You !

Please Fill Out The Evaluation Form !