flashback技術之---flashback Transaction Query
SQL> SELECT xid, operation, start_scn,commit_scn, logon_user, undo_sql
2 FROM flashback_transaction_query
3 WHERE xid IN (SELECT versions_xid FROM t VERSIONS between scn 314690 and 314700);
XID OPERATION START_SCN COMMIT_SCN LOGON_USER UNDO_SQL
---------------- ---------- ---------- ---------- ---------- ------------------------------------------------------------
01002600C2000000 INSERT 314698 314699 SCOTT delete from "SCOTT"."T" where ROWID = 'AAALOBAADAAAAASAAC';
01002600C2000000 BEGIN 314698 314699 SCOTT
08001100D4000000 INSERT 314692 314694 SCOTT delete from "SCOTT"."T" where ROWID = 'AAALOBAADAAAAASAAB';
08001100D4000000 BEGIN 314692 314694 SCOTT
--聯合flashback version query和flashback transaction query,可以將使用者某個事務做的誤操作進行恢復:
SQL> CREATE TABLE emp
2 (empno NUMBER PRIMARY KEY,
3 empname VARCHAR2(16),
4 salary NUMBER);
Table created.
SQL> INSERT INTO emp VALUES (111, 'Mike', 555);
1 row created.
SQL> commit;
Commit complete.
SQL> CREATE TABLE dept
2 (deptno NUMBER,
3 deptname VARCHAR2(32));
Table created.
SQL> INSERT INTO dept VALUES (10, 'Accounting');
1 row created.
SQL> commit;
Commit complete.
--此時,emp和dept兩個表中各自有一條資料
--接下來另一個事務誤刪了empno=111的資料:
SQL> UPDATE emp SET salary = salary + 100 WHERE empno = 111;
1 row updated.
SQL> INSERT INTO dept VALUES (20, 'Finance');
1 row created.
SQL> DELETE FROM emp WHERE empno = 111;
1 row deleted.
SQL> commit;
Commit complete.
--另外一個事務插入了一條empno=111的資料,ename與之前的不同
SQL> INSERT INTO emp VALUES (111, 'Tom', 777);
1 row created.
SQL> UPDATE emp SET salary = salary + 100 WHERE empno = 111;
1 row updated.
SQL> UPDATE emp SET salary = salary + 50 WHERE empno = 111;
1 row updated.
SQL> commit;
Commit complete.
--此時,DBA發現了這個錯誤,需要將empno=111的資料恢復,執行如下查詢
SQL> SELECT versions_xid XID, versions_startscn START_SCN,
2 versions_endscn END_SCN, versions_operation OPERATION,
3 empname, salary FROM scott.emp
4 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
5 where empno = 111;
XID START_SCN END_SCN OPERATION EMPNAME SALARY
---------------- ---------- ---------- ---------- ---------------- ----------
09000800E3000000 367562 I Tom 927
06002900BD000000 367525 D Mike 555
09000200E3000000 350554 367525 I Mike 555
--在查詢結果中,sql的實際執行順序是從下往上執行的,也就是09000200E3000000==>06002900BD000000==>09000800E3000000
--可以看到事務06002900BD000000執行了delete操作,從flashback_transaction_query檢視中查到該事務:
SQL> SELECT xid, start_scn, commit_scn,operation OP,logon_user,undo_sql
2 FROM flashback_transaction_query
3 WHERE xid = HEXTORAW('06002900BD000000');
XID START_SCN COMMIT_SCN OP LOGON_USER
---------------- ---------- ---------- -------------------------------- ----------
UNDO_SQL
------------------------------------------------------------
06002900BD000000 367517 367525 DELETE SCOTT
insert into "SCOTT"."EMP"("EMPNO","EMPNAME","SALARY") values
('111','Mike','655');
06002900BD000000 367517 367525 INSERT SCOTT
delete from "SCOTT"."DEPT" where ROWID = 'AAALOEAABAAAMraAAB
';
06002900BD000000 367517 367525 UPDATE SCOTT
XID START_SCN COMMIT_SCN OP LOGON_USER
---------------- ---------- ---------- -------------------------------- ----------
UNDO_SQL
------------------------------------------------------------
update "SCOTT"."EMP" set "SALARY" = '555' where ROWID = 'AAA
LOCAABAAAMrKAAA';
06002900BD000000 367517 367525 BEGIN SCOTT
根據undo_sql,可以將資料恢復。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10972173/viewspace-738213/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- flashback技術之---flashback query
- flashback技術之---flashback version query
- flashback總結六之Flashback_Transaction_Query
- Oracle10g的Flashback之Flashback Transaction QueryOracle
- oracle10g之flashback version query 和flashback transaction query 實驗Oracle
- flashback version query和 flashback transaction query簡單應用
- 【實驗】【Flashback】Flashback Transaction Query功能實踐
- oracle 10g flashback version query 和 flashback transaction query實驗Oracle 10g
- flashback技術之---flashback drop
- flashback技術之---flashback table
- flashback技術之---flashback databaseDatabase
- oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- flashback總結四之Flashback_Query
- Oracle閃回技術--Flashback Version QueryOracle
- 聊聊閃回事務查詢Flashback Transaction Query
- flashback_transaction_query的資料來源!
- 【閃回特性之閃回事務查詢】Flashback Transaction Query
- flashback總結五之Flashback_Query_Version(上)
- 【Flashback】Flashback Query功能實踐
- flashback_transaction_query資料保留的時間
- 全面學習oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- flashback總結五之Flashback_Query_Version(下)_補充
- 閃回之 Flashback Query (dml表、過程、函式、包等)、Flashback version Query函式
- 【徵文】全面學習oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- 使用FLASHBACK_TRANSACTION_QUERY查詢回滾事務SQLSQL
- Flashback Query Benefits (368)
- oracle檢視flashback_transaction_query中列operation為unknownOracle
- Flashback閃回技術
- ORACLE Flashback Query偽列Oracle
- Oracle OCP 1Z0 053 Q387(FLASHBACK_TRANSACTION_QUERY)Oracle
- Oracle OCP 1Z0 053 Q63(flashback_transaction_query)Oracle
- Oracle OCP 1Z0 053 Q677(Flashback Transaction Query)Oracle
- oracle flashback技術詳解Oracle
- Oracle Flashback 技術 總結Oracle
- Oracle Flashback技術總結Oracle
- flashback query閃回資料
- flashback drop/query/table/database/archiveDatabaseHive
- Flashback Query閃回查詢