Flashback Flashback Query Fb0.sql 9iR1 – primitive

Slides:



Advertisements
Similar presentations
Chris Ruel * Image used without permission.
Advertisements

SQL2-ch2 管理綱要物件.
17 Copyright © 2005, Oracle. All rights reserved. Performing Flashback.
Basic Storage Concepts and Settings
10 Copyright © 2009, Oracle. All rights reserved. Managing Undo Data.
Advanced Databases Basic Database Administration Guide to Oracle 10g 1.
5 Copyright © 2006, Oracle. All rights reserved. Database Recovery.
Backup and Recovery (2) Oracle 10g CAP364 1 Hebah ElGibreen.
Backup and Recovery Part 1.
Chapter 5 Configuring the RMAN Environment. Objectives Show command to see existing settings Configure command to change settings Backing up the controlfile.
Backup Concepts. Introduction Backup and recovery procedures protect your database against data loss and reconstruct the data, should loss occur. The.
Agenda  Overview  Configuring the database for basic Backup and Recovery  Backing up your database  Restore and Recovery Operations  Managing your.
Oracle Database Administration Database files Logical database structures.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
1. Automate a Secure Historical Data Store with Oracle Total Recall Venky RadhakrishnanKevin Jernigan Database DeveloperSenior Director Product Management.
5 Copyright © 2004, Oracle. All rights reserved. Using Recovery Manager.
Database Technical Session By: Prof. Adarsh Patel.
1 Oracle Database 11g – Flashback Data Archive. 2 Data History and Retention Data retention and change control requirements are growing Regulatory oversight.
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.
Extents, segments and blocks in detail. Database structure Database Table spaces Segment Extent Oracle block O/S block Data file logical physical.
Architecture Rajesh. Components of Database Engine.
1 Oracle Flashback Technologies COUG Presentation – Feb 2010 Feb 25, 2010 Ray Smith
9 Copyright © 2004, Oracle. All rights reserved. Flashback Database.
The protection of the DB against intentional or unintentional threats using computer-based or non- computer-based controls. Database Security – Part 2.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Chapter 14 DML Tuning. 2 DML Performance Fundamentals DML Performance is affected by: – Efficiency of WHERE clause – Amount of index maintenance – Referential.
Backup and Recovery Overview Supinfo Oracle Lab. 6.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Oracle Database 10 g Time Navigation: Human-Error Correction Magnus Lubeck DBA/Systems Analyst CERN, IT-DB Group Session id: Tammy Bednar Sr. Product.
AUSOUG National Conference Series 2009 Time Travel Back To The Future With Oracle 11g Total Recall Gavin Soorma Senior Oracle DBA, Bankwest.
6 Copyright © 2006, Oracle. All rights reserved. Flashback.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
7 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
IT Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.
Week 4 Lecture 2 Advanced Table Management. Learning Objectives  Create tables with large object (LOB) columns and tables that are index-organized 
10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
Oracle 10g Database Administrator: Implementation and Administration Chapter 5 Basic Storage Concepts and Settings.
3 Copyright © 2006, Oracle. All rights reserved. Using Recovery Manager.
Over view  Why Oracle Forensic  California Breach security Act  Oracle Logical Structure  Oracle System Change Number  Oracle Data Block Structure.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
© 2006 Northgate Information Solutions plc and its associated companies. All rights reserved. Slide 1.
18 Copyright © 2004, Oracle. All rights reserved. Backup and Recovery Concepts.
6 Copyright © 2007, Oracle. All rights reserved. Performing User-Managed Backup and Recovery.
18 Copyright © 2004, Oracle. All rights reserved. Recovery Concepts.
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
11 Copyright © 2007, Oracle. All rights reserved. Using Flashback Technology.
Chapter 3 Table Creation and Management Oracle 10g: SQL.
6 Copyright © Oracle Corporation, All rights reserved. Backup and Recovery Overview.
20 Copyright © 2006, Oracle. All rights reserved. Best Practices and Operational Considerations.
What is the Flashback Database? Improves a database’s availability Useful alternative to traditional restoration methods Contains Flashback logs Archived.
14 Copyright © 2007, Oracle. All rights reserved. Backup and Recovery Concepts.
What is Flashback? Technology that allows you to revert the database to a point in time in the past Several versions of flashback available Different types.
23 Copyright © 2004, Oracle. All rights reserved. Preferring the Past: Flashback.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
9 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
10 Copyright © 2007, Oracle. All rights reserved. Managing Undo Data.
Oracle Database High Availability
Backup and Recovery.
Database structure and space Management
Performing Flashback.
Oracle Database High Availability
Oracle 10g Database Administrator: Implementation and Administration
Using Flashback Technology II
Index Index.
Performing Database Recovery
Presentation transcript:

Thomas Kyte http://asktom.oracle.com/

Flashback Flashback Query Fb0.sql 9iR1 – primitive Had to open flashback cursors before doing any DML It worked, but was not “easy” Fb0.sql

Flashback Flashback Query Fb1.sql 9iR2 – sophisticated No need to open cursors before doing modifications Can flashback in SQL, no packages needed Can flashback in modifications It worked and was much easier Could join the table with itself as of N minutes ago Put update a set of rows, put them back as they were N minutes ago In SQL Fb1.sql

Flashback In 10g In 11g Flashback Query Flashback Table Flashback Row History Flashback Drop Flashback Database In 11g Flashback Data Archive

Flashback – Flashback Table

Flashback – Flashback Table SQL Undo based – automates the compensating SQL that can get quite tricky to write Fb2.sql In a nutshell Deletes all rows inserted/modified since that SCN/Time Inserts all rows modified/deleted since that SCN/Time Rowids therefore will change (must enable row movement on the table) Let’s see what is under the covers here Fb3.sql What about RI? Fb4.sql

Flashback – Flashback Table Rowids Change All Tables locked A single Transaction (it is DDL, either all works or none works) Flashback 50 tables or 1 table – one big “refresh” RI Constraints verified in a deferred fashion (apparently) Statistics do not “flashback” Indexes Are neither “dropped” nor “created” If they did not exist at the flashback PIT, they will now If they were dropped after the flashback PIT, they will still be dropped Fb5.sql

Flashback – Flashback Table No Clusters MV’s AQ Dictionary tables (duh) Remote Tables Object Types Nested Tables Partitions/Sub-partitions (entire table) Fb_part.sql

Flashback – Flashback Table Various DDL may prevent flashbacks, such as Moving (no undo generated) Truncating (no undo generated) Constraints (fb6.sql – since only modified rows would be validated) Add/Drop column Partition operations (except adding a range partition) Triggers are disabled by default And I cannot imagine the use case where they would be enabled (well, maybe auditing)

Flashback – Flashback Row History Instead of “show me the data as of”, you can say “show me all versions of the data between” Select ename, sal from emp versions between timestamp a and b where ename = ‘SCOTT’ ENAME SAL ---------- ---------- SCOTT 3000 SCOTT 3300 SCOTT 3630 …

Flashback – Flashback Row History See related information about each row SCN range the row was “valid for” Time range (approx) the row was valid for The transaction id (XID) that modified the row The operation (I/U/D) that was performed on the row select ename, sal, versions_operation, versions_starttime, versions_endtime, versions_startscn, versions_endscn, versions_xid from emp versions between timestamp &A and &B where empno = 7788 order by versions_startscn nulls first Fb7.sql

Flashback – Flashback Row History Related psuedo column ORA_ROWSCN Approximate by default Rowdependencies makes it exact Scn_to_timestamp Approximate mapping to time 3 second interval sys@ORA10G> desc smon_scn_time Name Null? Type ----------------- -------- ------------ THREAD NUMBER TIME_MP NUMBER TIME_DP DATE SCN_WRP NUMBER SCN_BAS NUMBER NUM_MAPPINGS NUMBER TIM_SCN_MAP RAW(1200) SCN NUMBER ORIG_THREAD NUMBER sys@ORA9IR2> desc smon_scn_time Name Null? Type ----------------- -------- ------------ THREAD NUMBER TIME_MP NUMBER TIME_DP DATE SCN_WRP NUMBER SCN_BAS NUMBER Fb9.sql

Flashback – Flashback Table Undrop a table!

Flashback – Flashback Table Uses a recycle bin metaphor Table/indexes/triggers/constraints are renamed Extents are not deallocated immediately Whether you can undrop something depends entirely on how “full” your tablespace was! This is useful for “whoops” recovery right after the fact You may be able to undrop a table months after the fact You may not be able to undrop a table seconds after the fact! Fb10.sql

Flashback – Flashback Table Multiple table T’s may exist in the recycle bin HTML/DB demo story You should rename indexes et.al. after the fact RI (foreign keys from child tables) are not “undropped” You had to specify “cascade constraints” The fkeys are not really part of “this table” anyway Fb11.sql

Flashback – Flashback Table Only works for non-system, LMT’s You can query dropped objects (but no modifications/DDL) You can even flashback query them (but that’s getting a a little carried away… VPD tables not recycled MV logs do not come back MV’s are not recycled

Flashback – Flashback Table You can PURGE objects, once purged – they are gone A single table or index The current users recyclebin set of objects The entire systems set of objects All objects in tablespace ‘X’ All objects for the given user

Flashback – Flashback Table Drop table also has a PURGE option Don’t get in the habit of using it. Keep it a two step “drop”/”purge” operation if you want to reclaim space Why? Makes it almost impossible to “accidentally” drop a table, you really really want to get rid of that thing since it takes two command. Cannot “untruncate” a table

Flashback Database Fbdb.sql Data Files Flashback Log A new strategy for point in time recovery Flashback Log captures old versions of changed blocks Think of it as a continuous backup Replay log to restore DB to time Restores just changed blocks It’s fast - recover in minutes, not hours It’s easy - single command restore SQL> Flashback Database to ‘2:05 PM’ Disk Write New Block Version Old Block Version Data Files Flashback Log “Rewind” button for the Database Holds old block contents Fbdb.sql

Flashback Database Cannot recover from media failure, that’s still the job of conventional backup and recovery You can mix restore and flashback (dropped datafiles) Flashback retention is a target, not a directive Must be in archive log mode (but you already must be anyway) Must use flash recovery area (anyone remember version 5)

Flashback Database Yes, it will increase write IO (flashback recovery area) But – so does Archive log mode The way we do undo and redo Everything pretty much – we can design (eg: plan) for it

Flashback Data Archive

Historical Data Storage Flashback Data Archive A new database object, flashback data archive, is a logical container for storing historical information Consists of one or more tablespaces ‘QUOTA’ determines max amount of space a flashback data archive can use in each tablespace (default is Unlimited) Specify duration for retaining historical changes using ‘RETENTION’ parameter Tracks history for one or more tables Tables should share the archiving characterstics Automatically purges aged-out historical data based on retention policy Create as many flashback data archives as needed Group related tables by desired retention period - HIPAA requires all health transactions be maintained for 6 years Tablespaces In a tablespace, a flashback data archive can co-exist with other objects. It is recommended to create dedicated tablespaces for flashback data archives and leave the quota at the default value of ‘unlimited’. Tracked tables in all tablespaces inherit RETENTION and Purge policies

How Does Flashback Data Archive Work? Primary source for history is the undo data History is stored in automatically created history tables inside the archive Transactions and its undo records on tracked tables marked for archival Undo records not recycled until history is archived History is captured asynchronously by new background process (fbda) Default capture interval is 5 minutes Capture interval is self-tuned based on system activities Process tries to maximize undo data reads from buffer cache for better performance INSERTs do not generate history records

Flashback Data Archive And DDLs Possible to add columns to tracked tables Automatically disallows any other DDL that invalidates history Dropping and truncating a tables Dropping or modifying a column Flashback Data Archive guarantees historical data capture and maintenance Any operations that invalidates history or prevents historical capture will be disallowed On a table with flashback data archiving enabled, if records are inserted and never updated, there will be no history generated! Disabling archiving will drop the internal history tables. Re-enabling archiving will create a new set of history tables. It will not pick up from where it left off. Comprehensive DDL support on FDA-enabled tables in a future release (TBD)

Creating Flashback Data Archive & Enable History Tracking Create tablespace (ASSM is required) Create a flashback data archive Set the retention period CREATE FLASHBACK ARCHIVE fda1 TABLESPACE tbs1 RETENTION 5 YEAR; Enable archiving on desired tables ALTER TABLE EMPLOYEES FLASHBACK ARCHIVE fda1; 1 2 3 Requires new system privilege FLASHBACK ARCHIVE ADMINISTER Flashback Data Archive Flashback Data Archive Add a desc sys_fba_hist_xxxxx to demo steps.. Requires new object privilege FLASHBACK ARCHIVE

Managing Flashback Data Archive Static data dictionary views *_FLASHBACK_ARCHIVE - Displays information about Flashback Data Archives. *_FLASHBACK_ARCHIVE_TS - Displays tablespaces of Flashback Data Archives. *_FLASHBACK_ARCHIVE_TABLES - Displays information about tables that are enabled for flashback archiving. Alerts generated when flashback data archive is 90% full Automatically purges historical data after expiration of specified retention period Supports ad-hoc purge by administrators (privileged operation) ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE TIMESTAMP (SYSTIMESTAMP - INTERVAL '1' DAY);

Managing Flashback Data Archive SYS_FBA_HIST_* - Internal History Table Replica of tracked table with additional timestamp columns Partitioned for faster performance Tune performance using indexes Compression reduces disk space required No modifications allowed to internal partitions Applications don’t need to access internal tables directly Use ‘AS OF’ to seamlessly query history -> no copying primary key indexes in R1…DBA’s can add indexes for better performance

Questions