Legal | Privacy

Recovering from Human Error using Flashback

This lesson describes the Oracle Database 10g Flashback features that support self-service error correction.

This lesson discusses the following:

Overview

Prerequisites

Filling the Recycle Bin

Querying Tables in the Recycle Bin

Recovering Tables from the Recycle Bin

Emptying Tables from the Recycle Bin

Using Flashback Table to Recover a Table

Move your mouse over this icon to show all screenshots. You can also move your mouse over each individual icon to see only the screenshot associated with it.

In Oracle Database 10g, flashback functionality has been extended. It is now possible to flash back an entire table and quickly recover a table that has been inadvertently dropped.

What is the Recycle Bin?

In previous releases of the Oracle server, the DROP command permanently removed objects from the database. Now when you drop a table and its dependent objects it is placed in the recycle bin. It is not removed from the database until you empty the recycle bin. The extents allocated to the segment are not deallocated until you purge the object. You can restore these dropped objects from the recycle bin at any time.

Before starting this module, you should have performed the following:

1.

Completed the Configuring Linux for the Installation of Oracle Database 10g lesson

2.

Completed the Installing the Oracle Database 10g on Linux lesson

3.

Download the flashback.zip into your working directory.

First, you will need to add an object to the Recycle Bin. Perform the following steps:

1.

Open SQL*Plus and enter the following commands to create a new table:

connect system/<password>
@create_job_hist

Move your mouse over this icon to see the image

 

2.

Now enter the following SQL statement to drop the table you just created.

drop table hr.jobs_hist;

Move your mouse over this icon to see the image

The table has been dropped. You have just added this table to the recycle bin.

 

You can still query tables after you have dropped them. You can issue a SELECT statement against the objects in the recycle bin using the name of the object in the recycle bin. You can also issue a Flashback Query against objects in the recycle bin to query past data, as long as the undo information required to satisfy the query is available. You can only issue these queries if you are the original owner of the object. Perform the following

1.

At this point, you can query the recycle bin for the table you just dropped. Open another browser window and enter the following URL:

http://<hostname>:5500/em

Enter sys/<password> as SYSDBA and click Login.

Move your mouse over this icon to see the image

 

2.

Click the Administration tab.

Move your mouse over this icon to see the image

 

3.

Click Tables.

Move your mouse over this icon to see the image

 

4.

Enter HR for the Schema and click GO.

Move your mouse over this icon to see the image

 

5.

Click the Recycle Bin link.

Move your mouse over this icon to see the image

 

6.

Enter the HR schema and click GO.

Move your mouse over this icon to see the image

 

7.

You notice that the table you dropped is listed. Click View Content.

Move your mouse over this icon to see the image

 

8.

You see the contents of the table you dropped. Click OK.

Move your mouse over this icon to see the image

 

You can recover the table from the recycle bin by performing the following:

1.

In the recycle bin, select the checkbox next to the JOBS_HIST object and click Flashback Drop.

Move your mouse over this icon to see the image

 

2.

Click Next.

Move your mouse over this icon to see the image

 

3.

Before you submit the job to recover the table, click Show SQL to see what will be executed.

Move your mouse over this icon to see the image

 

4.

Review the SQL statement that will run. When done, click OK.

Move your mouse over this icon to see the image

 

5.

Click Submit.

Move your mouse over this icon to see the image

 

6.

You receive a message saying the flashback drop was successful. Click OK.

Move your mouse over this icon to see the image

 

7.

The JOBS_HIST table no longer appears in the Recycle Bin. You want to make sure that the table now appears in the list. Click the Tables breadcrumb.

Move your mouse over this icon to see the image

 

8.

You now see the JOBS_HIST back in the list.

Move your mouse over this icon to see the image

 

Back to List of Topics

At some point, you may want to permanently remove the object from the database and release the space allocated to it after you have dropped the object. To remove an object from the recycle bin, perform the following:

1.

Select the radio button in front of the JOBS_HIST table and click Delete.

Move your mouse over this icon to see the image

 

2.

Click Yes to confirm deletion.

Move your mouse over this icon to see the image

 

3.

Click the Recycle Bin link.

Move your mouse over this icon to see the image

 

4.

Enter the HR schema and click GO.

Move your mouse over this icon to see the image

 

5.

In the recycle bin, select the checkbox next to the JOBS_HIST object and click Purge.

Move your mouse over this icon to see the image

 

6.

Click Yes to confirm deletion.

Move your mouse over this icon to see the image

 

7.

The table has been purged from the recycle bin. Click your Tables breadcrumb. .

Move your mouse over this icon to see the image

 

In Oracle9i, Flashback Query was introduced. This feature provides a way for you to view and repair historical data. You can perform queries on the database as of a certain wall clock time or user-specified system change number (SCN).

In Oracle Database 10G, Flashback functionality has been expanded. You can use the VERSIONS BETWEEN clause to retrieve all of the versions of the rows that exist or ever existed between the time the query was issued and a point back in time. This type of query is referred to as a Flashback Versions Query.

The rows returned by the Flashback Versions Query are a history of changes of the rows across transactions.

The Flashback Versions Query retrieves all committed occurrences of the rows. Changes made by the current active transaction are not returned. In other words, uncommitted row versions within a transaction will not be shown.

You can use Flashback Versions Query to retrieve row history. It provides you with a way to audit the rows of a table and retrieve information about the transactions that changed the rows. You can use the transaction ID obtained from Flashback Versions Query to perform transaction mining using LogMiner or Flashback Transaction Query to obtain additional information about the transaction.

You will perform the following tasks:

Update the JOBS Table
Enable Row Movement on the JOBS Table

Recover the JOBS Table to a Particular Point in Time

Update the JOBS Table

Back to List

To show how flashback works, you need to make a change to a table. Perform the following:

1.

From your SQL*Plus session, execute the following script logged on as system.

updatejobs.sql

The updatejobs.sql contains the following:

UPDATE hr.jobs
SET max_salary = max_salary + 2000
WHERE job_id = 'IT_PROG'
/
COMMIT
/

Move your mouse over this icon to see the image

 

2.

To see the current value, enter the following SQL statements:

connect hr/hr
select * from jobs where job_id='IT_PROG';

Move your mouse over this icon to see the image

You see the current value after your update is 12000.

 

Enable Row Movement on the JOBS Table

Back to List

You must first enable row movement on the table you want to perform flashback table on.Enabling row movement lets you specify whether Oracle can move a table row. It is possible for a row to move, for example, during table compression or an update operation on partitioned data. Perform the following:

1.

Switch to your Enterprise Manager browser session, click on the JOBS table.

Move your mouse over this icon to see the image

 

2.

Select the Options tab.

Move your mouse over this icon to see the image

 

3.

Select Yes for Enable Row Movement and click Apply.

Move your mouse over this icon to see the image

 

4.

Now you can perform a flashback table. Click the Tables breadcrumb.

Move your mouse over this icon to see the image

 

Recover the JOBS Table to a Particular Point in Time

Now you are ready to recover the JOBS table to a particular point in time. Perform the following:

1.

Select the radio button in front of the JOBS table and select Flashback by Row Versions from the Actions list box and click GO.

Move your mouse over this icon to see the image

 

2.

Select JOB_ID and MAX_SALARY and click Move. Then enter WHERE job_id = 'IT_PROG' in the Bind the Row Value field and click Next.

Move your mouse over this icon to see the image

 

3.

The update you made previously is in the list. Click Next.

Move your mouse over this icon to see the image

 

4.

Click Next.

Move your mouse over this icon to see the image

 

5.

You may want to see what will change. Click Show Row Changes.

Move your mouse over this icon to see the image

 

6.

You will see the objects that will change as a result of the flashback operation. Click OK.

Move your mouse over this icon to see the image

 

7.

You are now ready to perform the flashback operation. Click Submit.

Move your mouse over this icon to see the image

 

8.

The flashback operation has completed successfully. Click OK.

Move your mouse over this icon to see the image

 

9.

Switch to your SQL*Plus session again and perform the following SQL Statement to check to see that the salary value has changed back.

select * from jobs where job_id='IT_PROG';

Move your mouse over this icon to see the image

You see that the value has been changed back to 10000.

 

Move your mouse over this icon to hide all screenshots.

 

 

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy