Sunteți pe pagina 1din 40

Backup and Recovery Using

Flashback / Snapshot
Sumit Sengupta
EDS, an HP Company

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>

Restrictions
AQ
Materialized Views
Dictionary Table (except DDL definition
like User_Constraints
Object/Nested/Remote Table
DDLs often invalidate Flashbacks
Not suited for packaged applications

Types of Flashback

Version query
Transaction query
Table drop ( Recyclebin >= 10G )
Database ( Flashback Mode >= 10G )
Transaction ( 11G )
Data Archive ( Total Recall, 11G )

Beyond Oracle Flashback


Snapshot Storage Backups
Vendor Specific
Storage Layer Instant Point of Time
Akin to Flashback Database

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.

Pseudo Columns ( >= 10G )

VERSIONS_STARTTIME
VERSIONS_STARTSCN
VERSIONS_ENDTIME
VERSIONS_ENDSCN
VERSIONS_XID
VERSIONS_OPERATION
ORA_ROWSCN

SCN And Timestamp..1


Easy Conversions using functions
SQL> select sysdate from dual ;
SYSDATE
-----------------27-nov-08 13:28:15
SQL> select current_scn from v$database;
CURRENT_SCN
----------573468

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

SQL Driven Flashback SQL


SQL> SELECT
first_name, salary, versions_starttime,
versions_startscn, versions_endtime,
versions_endscn, versions_xid,
versions_operation
FROM emp
VERSIONS BETWEEN SCN minvalue and
maxvalue
WHERE
employee_id = 107 ;

Results
FIRST
SALARY STARTTIME
STARTSCN 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 #
#

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

Session Driven Query


DBMS_FLASHBACK Package ( >= 9i )
Enable at Specific Time/SCN for Session
No DDL While in flashback mode
SQL > drop table emp ;
ORA-08182: operation not supported

while in Flashback mode

Other Sessions can issue DDL

Pseudo Column
ORA_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

Create Table With Row Dep.


SQL>CREATE TABLE emp ( column list ) ;
SQL>CREATE TABLE emp_dep ( column list )
ROWDEPENDENCIES;

SQL> select distinct


dbms_rowid.rowid_block_number (rowid)
"Block", count(1) from emp group by
dbms_rowid.rowid_block_number (rowid) ;
Block
COUNT(1)
---------- ---------388
98
389
9

Additional Space Needed


SQL> select from emp_dep group by ;
Block Dep
COUNT(1)
---------- ---------404
92
405
15
SQL> select table_name, dependencies, avg_row_len
from user_tables ;
TABLE_NAME
DEPENDEN
AVG_ROW_LEN
------------------------- -----------------EMP
DISABLED
71
EMP_DEP
ENABLED
77

Update Rows With Delay


begin
for empid in 189..197
loop
update emp set salary = salary +
1000 where id = empid ;
commit ;
dbms_lock.sleep (10) ;
end loop ;
end ;

Table Without Row


Dependency
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

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

Types of Flashback

Version query
Transaction query
Table drop ( Recyclebin >= 10G )
Database ( Flashback Mode >= 10G )
Transaction ( 11G )
Data Archive ( Total Recall, 11G )

Flashback Transaction Query


Quick Logminer in 10G
Needs Select Any Txn System Privilege
SQL> select commit_timestamp, undo_sql
from 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';

Types of Flashback

Version query
Transaction query
Table drop ( Recyclebin >= 10G )
Database ( Flashback Mode >= 10G )
Transaction ( >= 11G )
Data Archive ( Total Recall >= 11G )

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 !

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 to
timestamp ( systimestamp -1/24 ) ;
ERROR at line 1:
ORA-01466: unable to read data - table
definition has changed

Flashback Table Example


SQL> flashback table emp to before drop ;
SQL> select index_name from user_indexes
where table_name = 'EMP' ;
INDEX_NAME
-----------------------------BIN$XOC7UfSrQTLgQKjAbg8oPQ==$0
SQL> alter index
"BIN$XOC7UfSrQTLgQKjAbg8oPQ==$0" rename
to EMP_UK ;

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

Types of Flashback

Version query
Transaction query
Table drop ( Recyclebin >= 10G )
Database ( Flashback Mode >=
10G )
Transaction ( 11G )
Data Archive ( Total Recall, 11G )

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

When DB is not in Flashback


Mode
Restore Point Info Stored in UNDO TS
Cannot Restore Beyond UNDO
Retention for Normal Restore Points
db_flashback_retention_target
irrelevant
V$ Views on flashback Logs are empty
For Guaranteed RP, Flashback Logs are
generated. Guarantee for DB only.

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 mount
mode and needs a Resetlogs to open

Flashback DB Issues
Logs not always deleted. Bug#5106952
Not deleted during auto-backupbug#7390954
Guaranteed RP delete on Linux cleaned
up space as expected
Upon Flashback and resetlogs, all prior
logs and backups need to be deleted
manually from FRA

Types of Flashback

Version query
Transaction query
Table drop ( Recyclebin >= 10G )
Database ( Flashback Mode >= 10G )
Transaction ( 11G )
Data Archive ( Total Recall, 11G )

Flashback Transaction
DBMS_FLASHBACK.TRANSACTION_BACKOUT
procedure
NOCASCADE (def) Assumes no dependency
CASCADE Backs out dependent txns
NOCASCADE_FORCE Ignores dependencies
NONCONFLICT_ONLY Only non-conflicting
rows rolled back, txn atomicity is lost.

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_arc1
tablespace fl_arc1 quota 100G
retention 1 year;
SQL> create table emp (..) flashback
archive fl_arc1 ;
SQL> select * from emp as of SCN
7634512 ;

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 Raid
groups of 16 disks RAID-DP

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

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

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, Versioning
etc.

Lessons Learned
A lot of overhead storage in RAID,
Snapshot
Snap Manager not supported on all
OS/ASM
Easy integration with RMAN

Thank You !


40

Please Fill Out The Evaluation Form !

S-ar putea să vă placă și