`

Oracle 11g Flashback Transaction Backout(原创)

阅读更多

Flashback Transaction Backout
Oracle Database 11g introduces the flashback transaction backout feature, which lets you perform logical recovery by undoing changes made by a transaction as well as its dependent transactions. It is easy to maintain data consistency because you can back out transactions that include a sequence of insert, update, and delete statements with a single execution of the TRANSACTION_BACKOUT procedure belonging to the DBMS_FLASHBACK package. You can do the same thing through the Enterprise Manager, which uses the TRANSACTION_BACKOUT procedure as well, to back out the changes made by a transaction or set of transactions with just a single click on your part.
A dependent transaction can have either a write-after-write or a primary key constraint relationship with the parent transaction:

  • In a write-after-write relationship, the dependent transaction modifies the data that was previously modified by the parent transaction.
  • Under a primary key constraint relationship, the dependent transaction reinserts the primary key deleted by the parent transaction.

In order to undo the changes brought about by a transaction, the database executes appropriate compensating transactions to return the data to its original state. Because the flashback transaction backout feature needs both the undo as well as the redo data generated for the undo blocks to execute the compensating transactions, you’ll need the necessary undo data and the archived redo logs to undo a transaction.

Prerequisites for Flashback Transaction Backout
You must enable supplemental logging in the database to enable the flashback transaction backout feature. So, first issue the following statements to turn supplemental logging on in the database:

SQL> alter database add supplemental log data;
SQL> alter database add supplemental log data (primary key) columns;
You must also grant the following privileges to any user that wants to use the flashback transaction backout feature. The following statements grant the necessary privileges to the user HR:
SQL> grant execute on dbms_flashback to hr;
SQL> grant select any transaction to hr;

The first privilege grants the user HR the flashback system privilege and the second, the select any transaction privilege. If a user wants to perform a transaction backout operation in another user’s schema, the first user must also have the necessary DML privileges on the table or tables in the second user’s schema.

Using the DBMS_FLASHBACK.TRANSACTION_BACKOUT Procedure
You can use the new DBMS_FLASHBACK.TRANSACTION_BACKOUT procedure to back out transactions. Here’s the structure of the DBMS_ FLASHBACK.TRANSACTION_BACKOUT procedure:
PROCEDURE TRANSACTION_BACKOUT
 Argument Name        Type           In/Out     Default?
 ----------------   --------------   ---------   ----------
NUMBEROFXIDS        NUMBER           IN
XIDS                XID_ARRAY        IN
OPTIONS             BINARY_INTEGER   IN           DEFAULT
SCNHINT             TIMESTAMP        IN
Here’s a brief explanation of the four key parameters in the DBMS_FLASHBACK.TRANSACTION_BACKOUT procedure:

  • numberofxids is the number of transactions you want to back out in this operation.
  • xids  A list of transaction identifiers that are passed as an array.
  • options  Enables you to specify the order in which to back out the parent and the child transactions. You can use the following four values for the options parameter:
  1. The nocascade value is the default and you use it when you don’t expect a transaction to have any dependent transactions.If you use the default value of nocascade for the options parameter, it means that you’re expecting the parent transaction doesn’t have any dependent transactions.
  2. The cascade value backs out the dependent transactions before backing out the parent transaction.
  3. The nocascade_force value backs out only the parent transactions. It ignores any dependent transactions.
  4. The noconflict_only option backs out only those rows in the parent transaction that don’t have any conflicts.
  • scnhint  You use the scnhint parameter to specify the SCN at the start of the transaction. The SCN must be before the start of the first transaction in the transaction set to be backed out.Similarly, you can replace the scnhint parameter with the timehint parameter, which enables you to provide a time hint on the start of the transaction. You must provide a timehint parameter if you’re using transaction names instead of transaction identifiers. The length of time for which the DBMS_FLASHBACK.TRANSACTION_ BACKOUT operation executes depends directly on the amount of redo generated by the transactions being backed out.

Once you execute the DBMS_FLASHBACK. TRANSACTION_BACKOUT procedure, the transactions you name aren’t automatically backed out by the database. The procedure checks the dependencies among transactions and performs the DML operations, but doesn’t commit them. Instead, it provides you with a report of its work. In the meantime, it holds locks on the rows and the tables in order to keep new transactions from affecting the backout operation. In order for the transactions to be backed out for good, you must issue a commit statement.

Using the TRANSACTION_BACKOUT Procedure

The following exercise shows you how to use the DBMS_FLASHBACK. TRANSACTION_BACKOUT procedure to back out a transaction along with its dependent transactions. Before you can execute the DBMS_FLASHBACK .TRANSACTION_BACKOUT procedure, you must first create a variable of an XID_ARRAY type. This array will hold a set of transaction identifiers as the starting point of the dependency search. Alternately, you can use a set of transaction names to identify the transactions.
declare
   trans_arr xid_array;
begin
   trans_arr := xid_array('030003000D02540','D10001000D02550');
   dbms_flashback.transaction_backout (
        numtxns         => 1,
        xids            => trans_arr,
        options         => dbms_flashback.nocascade
   );
end;
The column XIDS passes an array of transactions as input to the procedure. The default value for the options parameter is cascade, but I chose nocascade in this example. When you execute this procedure, the primary transaction and its dependent transaction are rolled back in one step. Although the database names the backout operation, for auditing purposes, Oracle recommends that you name your backout operation. Successful execution of the TRANSACTION_BACKOUT procedure means that the database backed out a single parent transaction.
TRANSACTION_BACKOUT Reports

We use this with the TRANSACTION_BACKOUT procedure to flashback the transaction ID of "060015009D030000".

BEGIN
  DBMS_FLASHBACK.transaction_backout (numtxns => 1,
                                      xids    => xid_array('060015009D030000'),
                                      options => DBMS_FLASHBACK.cascade);
END;
/
Querying the test table shows that the row has been removed.
SQL> SELECT * FROM test_user.test_tab;
no rows selected
We can use the transaction ID to query the DBA_FLASHBACK_TXN_STATE view.
SELECT *
FROM   dba_flashback_txn_state
WHERE  xid = '060015009D030000';
COMPENSATING_XID XID              DEPENDENT_XID    BACKOUT_MODE     USERNAME
---------------- ---------------- ---------------- ---------------- ------------------------------
05001800A0030000 060015009D030000 02000B00DB030000 CASCADE          SYS
1 row selected.
The COMPENSATING_XID returned from this query is used to query the DBA_FLASHBACK_TXN_REPORT view.
COLUMN xid_report FORMAT A80
SET LONG 100000
SELECT xid_report
FROM   dba_flashback_txn_report
WHERE  compensating_xid = '05001800A0030000';
XID_REPORT
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<COMP_XID_REPORT XID="05001800A0030000">
        <TRANSACTION XID="060015009D030000">
        <CHARACTERISTICS>
        </CHARACTERISTICS>
        <UNDO_SQL>
                <USQL exec="yes">
                 delete from "TEST_USER"."TEST_TAB" where "ID" = '2' and "DESCRIPTION" = 'Desc
ription for 2'
                </USQL>
        </UNDO_SQL>
XID_REPORT
--------------------------------------------------------------------------------
        <DEPENDENT_XIDS>
                <TRANSACTION XID="02000B00DB030000">
                <CHARACTERISTICS>
                </CHARACTERISTICS>
                <UNDO_SQL>
                        <USQL exec="yes">
                         update "TEST_USER"."TEST_TAB" set "DESCRIPTION" = 'Description for 2' where
"ID" = '2' and "DESCRIPTION" = 'Field'
                        </USQL>
                </UNDO_SQL>
                <DEPENDENT_XIDS>

XID_REPORT
--------------------------------------------------------------------------------
                </DEPENDENT_XIDS>
                </TRANSACTION>
        </DEPENDENT_XIDS>
        </TRANSACTION>
<EXECUTED_UNDO_SQL>
<EXEC_USQL>update "TEST_USER"."TEST_TAB" set "DESCRIPTION" = 'Description for 2'
 where "ID" = '2' and "DESCRIPTION" = 'Field'
</EXEC_USQL>
<EXEC_USQL>delete from "TEST_USER"."TEST_TAB" where "ID" = '2' and "DESCRIPTION"
 = 'Description for 2'
</EXEC_USQL>

XID_REPORT
--------------------------------------------------------------------------------
</EXECUTED_UNDO_SQL>
</COMP_XID_REPORT>
1 row selected.

 

参考至:《McGraw.Hill.OCP.Oracle.Database.11g.New.Features.for.Administrators.Exam.Guide.Apr.2008》

       http://www.oracle-base.com/articles/11g/flashback-and-logminer-enhancements-11gr1.php#flashback_data_archive

本文原创,转载请注明出处、作者

如有错误,欢迎指正

邮箱:czmcj@163.com

0
0
分享到:
评论

相关推荐

    oracle11g flashback archive 资料整理

    Oracle 11g Flashback Archive 资料整理 Oracle Flashback Archive 是 Oracle 11g 中的一项新特性,旨在提供有针对性数据表的可控时间闪回功能。Flashback Archive 可以实现对特定数据表的闪回,保留不同时间的数据...

    oracle11g 百度盘下载

    Oracle 11g是一款强大的关系型数据库管理系统,由甲骨文公司(Oracle Corporation)开发,是全球广泛应用的企业级数据库解决方案之一。在这个“Oracle11g 百度盘下载”资源中,用户可以获取到Oracle 11g的安装包,...

    oracle 10g flashback(数据恢复)

    ### Oracle 10g Flashback 数据恢复功能详解 Oracle 10g 引入了强大的 Flashback 技术,这是一系列旨在帮助管理员和开发者在出现数据丢失或损坏时能够快速恢复数据的功能集合。该技术从 Oracle 9i 开始引入,并在 ...

    Oracle 10g Flashback 概述

    Oracle 10g Flashback是Oracle数据库10g版本中引入的一个强大特性,它为数据库管理员和用户提供了恢复数据到过去某个时间点的能力,而无需依赖传统的备份和恢复过程。这个功能极大地增强了数据库的可恢复性和灵活性...

    Oracle 11g 官方中文文档集萃

    Oracle 11g是Oracle公司推出的数据库管理系统的一个重要版本,其官方中文文档集萃涵盖了该系统的核心技术、安装配置、管理维护以及高级特性等多个方面。这些文档为数据库管理员(DBA)和技术人员提供了全面的学习...

    Oracle11g中文文档

    Oracle11g是一款由甲骨文公司开发的关系型数据库管理系统,是Oracle数据库产品线中的一个重要版本。本套中文文档全面涵盖了Oracle11g的各项特性和功能,为学习和使用Oracle11g数据库提供了详实的参考资料。以下是...

    Oracle 11g 王二暖ppt文件

    Oracle 11g是甲骨文公司发布的一款企业级数据库管理系统,它在11g版本中引入了许多新特性和优化,旨在提升性能、可用性、安全性以及管理效率。"王二暖ppt文件"可能是一位名叫王二暖的专家或讲师分享的关于Oracle 11g...

    Oracle 11g课件

    Oracle 11g数据库是Oracle公司推出的一款关系型数据库管理系统,是Oracle数据库产品线中的重要版本之一。这个课件集合提供了全面的学习资源,适合教学和自学,帮助你深入理解和掌握Oracle 11g的各项功能和技术。 ...

    oracle11g官方中文帮助文档 高清完整版

    Oracle 11g是甲骨文公司发布的一款企业级数据库管理系统,它提供了广泛的功能和优化,以满足大型企业和组织的数据管理需求。这份“Oracle 11g官方中文帮助文档”是一个高清完整版的资源,旨在为中文用户提供详尽的...

    Oracle 闪回特性 FLASHBACK &amp; RECYCLEBIN

    Oracle 闪回特性 FLASHBACK & RECYCLEBIN Flashback 系列是 Oracle 数据库中的一组功能强大且实用的闪回机制,旨在帮助数据库管理员和开发者快速恢复数据库中的各种对象,包括表、数据、事务等。Flashback 系列的...

    oracle 11g数据库

    Oracle 11g数据库是Oracle公司推出的一款关系型数据库管理系统,是11g版本的简称。这个版本在前任版本的基础上进行了许多改进和增强,旨在提供更高效的数据存储、管理和分析能力。以下是一些关于Oracle 11g数据库的...

    flashback——oracle

    10g_flashback(数据恢复).txt"以及"oracle_10g_flashback.txt"这三份文档可能提供了一个全面的概述,包括Flashback日志、闪回数据库(Flashback Database)、闪回事务查询(Flashback Transaction Query)和闪回版本...

    oracle 11G高可用备份

    Oracle数据库11G高可用备份的策略和技术涵盖了从故障预防到故障恢复的多个层面,旨在确保数据库的高可用性和数据的完整性。以下将详细介绍这些策略和技术: 1. Oracle 11G数据库的高可用性:高可用性(High ...

    oracle 11g ,navicat使用

    7.闪回技术:Oracle 11g引入了闪回功能,如闪回查询(Flashback Query)、闪回表(Flashback Table)、闪回事务(Flashback Transaction)等,允许用户查看或恢复到过去某个时间点的数据状态。 8. 安全性:Oracle...

    Oracle 11g数据库应用简明教程

    Oracle 11g数据库是Oracle公司推出的一款企业级关系型数据库管理系统,广泛应用于大型数据存储、数据处理和数据分析等场景。本教程旨在提供一个Oracle 11g数据库应用的简明指南,帮助初学者快速掌握数据库的基础操作...

    Oracle11g 考试

    Oracle 11g是Oracle公司推出的数据库管理系统的一个重要版本,主要针对企业级应用提供高性能、高可用性和安全性。Oracle Certified Professional (OCP) 认证是Oracle为验证专业人士在Oracle数据库管理方面技能和知识...

    windows oracle11g 备份与还原

    Windows Oracle11g 备份与还原 Oracle11g 数据库备份与还原是数据库管理中非常重要的一部分,掌握备份与还原技术可以帮助数据库管理员快速恢复数据库,减少数据丢失的风险。本文将详细介绍 Oracle11g 数据库备份与...

    oracle11g R2 DBA操作指南@oracle.org.rar

    《Oracle 11g R2 DBA操作指南》是一份专为Oracle数据库管理员(DBA)和初学者设计的详细教程。本指南涵盖了Oracle 11g Release 2(R2)版本的主要功能和管理技巧,旨在帮助读者深入理解Oracle数据库的管理和优化。 ...

    oracle中关于flashback闪回的介绍

    ### Oracle Flashback 闪回技术详解 #### 一、引言 在Oracle数据库管理中,闪回技术(Flashback)是一种非常重要的数据恢复工具。它允许用户和管理员以一种简单而有效的方式,恢复误删、误改的数据。本文将详细介绍...

    oracle 闪回 flashback

    Oracle 10g引入了多种闪回功能,包括Flashback Database、Flashback Drop、Flashback Query以及Flashback Table。 1. **Flashback Database**: - Flashback Database允许用户将整个数据库恢复到过去的一个特定...

Global site tag (gtag.js) - Google Analytics