Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 

 

 

Oracle dbms_flashback

Oracle Database Tips by Donald Burleson


Inside O
racle dbms_flashback


The System Change Number is captured from the packaged function dbms_flashback.get_system_change_number.

Get the current SCN at the source database. Next, use the Oracle dbms_flashback package to get the current SCN. This value will be used during instantiation at the destination site, as well as by rman when duplicating the database.

SET SERVEROUTPUT ON
DECLARE
until_scn NUMBER;
BEGIN
until_scn:=
DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER;

Before Oracle dbms_flashback Query functionality can be used by ordinary users, some actions are required from the database administrators:

Alter system set UNDO_MANAGEMENT=AUTO;

Alter system set UNDO_RETENTION=86400;

Grant execute on DBMS_FLASHBACK to username;


Oracle dbms_flashback Query is enabled and disabled using the DBMS_FLASHBACK package. The point in time of the flashback can be specified using the SCN or the actual time.

EXECUTE dbms_Flashback.Enable_At_Time('28-AUG-02 11:00:00');
 

a DBA might need the ability to restore collections of tables to some pristine state on a regular interval. In the prior section, creating restructures were illustrated where a backup or before image might be handy in case of problems during mid-restructuring. The truth is that there are many cases where the DBA would like the ability to restore a logical portion of the database back in time or to a prior SCN. But the problem is that physical backups and restores are very complex and operate more at the physical database level. Few applications are generally worthy of their own backup and recovery strategy using the physical tools to build logical or application based restore points.

However, a long time ago Oracle introduced a great concept in the SQL and PL/SQL languages called the SAVEPOINT. This was the ability to issue a database state bookmark within the application code such that one could rollback to an application based logical point in time. This was a useful technique but never really saw extensive usage. Nevertheless, it was a good concept if only it would have extended to database objects and/or even the database level itself. Well, now it does and it is Oracle's flashback technology.

 Oracle flashback technology essentially lets the DBA create SAVEPOINT like bookmarks to restore to either objects or the entire database. In some respects, it is a great short term point-in-time recover technique, rather than going to a full blown backup and restore. Plus, its usage has been made so integrated, seamless and easy that it is sure to see heavy usage as time goes on. It is truly a definite must-have tool for the DBA's tool belt.

 There are six flashback technologies, in chronological order of their appearance, whose topics will be examined in more detail:

  • Flashback Queries (9i)

  • Flashback Drop (10g)

  • Flashback Tables

  • Flashback Database

  • Flashback Transaction (11g)

  • Flashback Archives (Oracle Total Recall)

Furthermore, unlike other features covered in this chapter, it will be beneficial to learn how to utilize these various flashback technology capabilities via OEM, SQL commands and the PL/SQL API.

 

Note:  Part of the reason for covering all the flashback technologies here, including a recap of older ones, is to hopefully lead the reader along the historical path of flashback technology development and, therefore, to perceive that each step was built on the foundations of those prior.

Flashback Queries

Oracle 9i introduced the concept of the flashback query. This can be called the "Back to the Future" or time machine type query  where Oracle lets DBAs make some queries in the present as if from a database state in the not too distant past.

 The black magic that makes this possible are UNDO tablespaces and automatic UNDO management and Oracle now treats those UNDO blocks as first-rate data based upon the undo_retention parameter. Using these, Oracle does its best to retain UNDO data. One can even force that availability via the UNDO tablespace RETENTION GUARANTEE option.

In its simplest form, merely add an AS OF clause to the SELECT statement to request the current execution be performed as if it were run at some prior specified time or system change number like looking backwards in time.

 

SQL> select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER from dual;
 
GET_SYSTEM_CHANGE_NUMBER
------------------------
                  353026
 
SQL> update movies.customer set zip='99999';
 
62 rows updated.
 
SQL> commit;
 
Commit complete.
 
SQL> select firstname, lastname, zip from movies.customer as of scn 353026 where rownum < 5;
 
FIRSTNAME            LASTNAME                       ZIP
-------------------- ------------------------------ -----
Flozell              Adams                          75063
Troy                 Aikman                         75063
Larry                Allen                          75063
Eric                 Bjornson                       75063

 

The entire Oracle session can also be enabled to enter a "time tunnel" or "time warp" so that nothing has to be added to the SELECT command to see such historical data. In that case, simply enable and disable the flashback effect as shown here via the PL/SQL packages found in dbms_flashback.

 

SQL> select firstname, lastname, zip from movies.customer where rownum < 5;
 
FIRSTNAME            LASTNAME                       ZIP
-------------------- ------------------------------ -----
Flozell              Adams                          99999
Troy                 Aikman                         99999
Larry                Allen                          99999
Eric                 Bjornson                       99999
 
SQL>
SQL> execute DBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER(353026)
 
PL/SQL procedure successfully completed.
 
SQL>
SQL> select firstname, lastname, zip from movies.customer where rownum < 5;
 
FIRSTNAME            LASTNAME                       ZIP
-------------------- ------------------------------ -----
Flozell              Adams                          75063
Troy                 Aikman                         75063
Larry                Allen                          75063
Eric                 Bjornson                       75063
 
SQL> execute DBMS_FLASHBACK.DISABLE
 
PL/SQL procedure successfully completed.
For more dbms_flashback tips see:

Advanced Oracle Utilities: The Definitive Reference by Rampant TechPress is written by top Oracle database experts (Bert Scalzo,  Donald Burleson, and Steve Callan). 

Buy direct from the publisher and save 30%!

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.