This tutorial shows you how to back out transactions in your database using Flashback Transaction.
Approximately 20 minutes
This tutorial covers the following topics:
Overview | |
Prerequisites | |
Creating a Test Environment | |
Backing Out transactions with a WAW Dependency | |
Cleanup | |
Summary |
Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.
What Is Flashback Transaction Back-Out?
Flashback Transaction Back-Out is a logical recovery option to roll back a target transaction and its dependent transactions while the database remains online. A dependent transaction is related by either a write-after-write (WAW) relationship, in which a transaction modifies the same data that was changed by the target transaction, or a primary key constraint relationship, in which a transaction re-inserts the same primary key value that was deleted by the target transaction. Flashback Transaction utilizes undo and the redo generated for undo blocks, to create and execute a compensating transaction for reverting the affected data back to its original state.
Before you perform this tutorial, you should:
1. | Install the database by completing the Installing Oracle Database 11g in Linux tutorial. |
|
2. | Download and unzip the flatxn.zip file into your working directory (i.e wkdir). |
To setup a test environment and create transactions for this OBE, perform the following steps:
A transaction can have a write-after-write (WAW) dependency, meaning that a transaction updates or deletes row data, that has been inserted or updated by a previous transaction. In this section, you want to backout a bad transaction, in addition to its WAW dependents which also caused incorrect changes. P erform the following steps:
1. | Enter the following URL to log in to Enterprise Manager Database Control (change the <hostname> to localhost or your specific hostname). https://<hostname>:1158/em
|
|
2. | To log in to Enterprise Manager, enter the following details, and click Login.
|
|
3. | You suspect that the HR.REGIONS table contains changes from the bad transaction, and want to view the complete table data. Click the Schema tabbed page. Then click Tables.
|
|
4. | To view all tables that belong to the HR schema user, enter HR into the Schema field and click the Go button.
|
|
5. | The HR tables are displayed. First, select the HR.REGIONS tables, then select View Data from the Actions drop-down list. Click the Go button behind the Actions drop-down, to view the data in the HR.REGIONS table.
|
|
6. | While viewing the content of the table, you realize that it should not contain the rows in the red box. Click OK.
|
|
7. | You return to the list of tables. Select the HR.REGIONS table, then select Flashback Transaction from the Actions drop-down list and click the Actions Go button.
|
|
8. | Review your query conditions. You can specify a time period in which you believe the erroneous changes were made. For this example, leave the default time period of the last hour. Then click Next. The Processing: Mining Transactions window appears, while redo logs are processed for the given time period.
|
|
9. | On the Flashback Transaction: Select Transaction page, select the Transaction ID link of the transaction which updates 2 regions.
|
|
10. | On the Select Transaction: Show Details page, review the erroneous UPDATE commands and click OK.
|
|
11. | Click Next to identify any dependent transactions and backout all needed changes. The Processing: Flashback Transaction window appears.
|
|
12. | On the Flashback Transaction: Show Dependencies page, click the first Transaction ID link.
|
|
13. | On the Show Dependencies: Details page, review the compensating transactions. Notice that none of the compensating transactions have been executed. Notice that the update of region #10 is marked "[exec=no]" meaning it will not be executed because it has dependent transactions. You will fix this in the next step by requesting all dependent transactions are also undone. Click OK.
|
|
14. | On the Flashback Transaction: Show Dependencies page, click Change Recovery Option.
|
|
15. | On the Show Dependencies: Change Recovery Option page, select Cascade, which will also backout the erroneous dependent transaction changes, and click OK. The Processing: Flashback Transaction window appears.
|
|
16. | From the Flashback Transaction: Show Dependencies window, click Next.
|
|
17. | Review the information and click Finish.
|
|
18. | The Flashback Transaction executed successfully. Click OK.
|
|
19. | You can view what is now contained in the HR.REGIONS table. Select the HR.REGIONS tables, then select View Data from the Actions drop-down list and click Go.
|
|
20. | Transactions 2, 3 were backed out but transaction 4 remains (region name is still set to "Still called Venus") since there was no WAW dependency between transaction 2 and 4.
|
You can cleanup your environment by performing the following steps:
1. | From a SQL*Plus session, execute the flatxn_cleanup1.sql script:
|
|
2. | Now you want to run flatxn_cleanup.sh to turn archivelog off. Execute the following command: ./flatxn_cleanup.sh
|
In this tutorial, you learned how to back out transactions with a WAW Dependency: