閃回查詢
閃回查詢
主要實驗了閃回技術
a. 開啟補充日誌(當使用閃回事物查詢時需要追加補充日誌)
SQL> alter database add supplemental log data;
Database altered.
b. 建立測試用表SCOTT.TEST_QUERY
drop table scott.test_query;
create table scott.test_query (id number, name varchar2(10), salary number);
--插入員工john, william, lisa的工資資訊
SQL> insert into scott.test_query values(1,'John',5000);
1 row created.
SQL> insert into scott.test_query values(2,'William',6000);
1 row created.
SQL> insert into scott.test_query values(3,'Lisa',7000);
1 row created.
SQL> commit;
Commit complete.
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),CURRENT_SCN from v$database;
TO_CHAR(SYSDATE,'YY CURRENT_SCN
------------------- -----------
2013-03-31 14:32:17 1056363
--插入新員工chris的工資資訊
SQL> insert into scott.test_query values (4,'Chris',4000);
1 row created.
SQL> commit;
Commit complete.
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),CURRENT_SCN from v$database;
TO_CHAR(SYSDATE,'YY CURRENT_SCN
------------------- -----------
2013-03-31 14:32:40 1056383
----模擬一次錯誤的修改操作
SQL> update scott.test_query set salary=0 where name='John';
1 row updated.
SQL> update scott.test_query set salary=10000 where name='Lisa';
1 row updated.
SQL> commit;
Commit complete.
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),CURRENT_SCN from v$database;
TO_CHAR(SYSDATE,'YY CURRENT_SCN
------------------- -----------
2013-03-31 14:33:06 1056404
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),CURRENT_SCN from v$database;
TO_CHAR(SYSDATE,'YY CURRENT_SCN
------------------- -----------
2013-03-31 14:33:22 1056410
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),CURRENT_SCN from v$database;
TO_CHAR(SYSDATE,'YY CURRENT_SCN
------------------- -----------
2013-03-31 14:33:26 1056412
-- 上調工資10%
SQL> update scott.test_query set salary=salary*1.1;
4 rows updated.
SQL> commit;
Commit complete.
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),CURRENT_SCN from v$database;
TO_CHAR(SYSDATE,'YY CURRENT_SCN
------------------- -----------
2013-03-31 14:33:46 1056422
--發現資料被錯誤修改
SQL> select * from scott.test_query;
ID NAME SALARY
---------- ---------- ----------
1 John 0
2 William 6600
3 Lisa 11000
4 Chris 4400
c. 嘗試使用閃回查詢確定正確的時間點
SQL> select * from scott.test_query as of timestamp to_date('2013-03-31 14:33:46','yyyy-mm-dd hh24:mi:ss');
ID NAME SALARY
---------- ---------- ----------
1 John 0
2 William 6600
3 Lisa 11000
4 Chris 4400
SQL> select * from scott.test_query as of timestamp to_date('2013-03-31 14:32:40','yyyy-mm-dd hh24:mi:ss');
ID NAME SALARY
---------- ---------- ----------
1 John 5000
2 William 6000
3 Lisa 7000
4 Chris 4000
SQL> select * from scott.test_query as of timestamp to_date('2013-03-31 14:32:17','yyyy-mm-dd hh24:mi:ss');
ID NAME SALARY
---------- ---------- ----------
1 John 5000
2 William 6000
3 Lisa 7000
d. 使用閃回版本查詢確定JOHN工資發生的所有變化
SQL> set line 200
SQL> col VERSIONS_STARTTIME for a25
SQL> col VERSIONS_XID for a20
SQL> col id for 999
SQL> col name for a7
select VERSIONS_STARTTIME,VERSIONS_OPERATION,VERSIONS_XID,id,name,salary
2 from scott.test_query VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE where name='John';
VERSIONS_STARTTIME V VERSIONS_XID ID NAME SALARY
------------------------- - -------------------- ---- ------- ----------
31-MAR-13 02.33.39 PM U 03001E0031030000 1 John 0
31-MAR-13 02.32.57 PM U 08001800F9030000 1 John 0
31-MAR-13 02.32.08 PM I 0300200031030000 1 John 5000
e. 使用閃回事物查詢確定該錯誤執行的事物做的所有變更
SQL> set line 200
SQL> COL UNDO_SQL FOR A40
SQL> COL OPERATION FOR A10
SQL> col name for a20
SQL> col table_name for a20
SQL> SELECT operation, undo_sql, START_SCN,
(select name from scott.test_query where rowid=flashback_transaction_query.ROW_ID) name
FROM flashback_transaction_query
WHERE xid = HEXTORAW('08001800F9030000')
ORDER BY undo_change#;
OPERATION UNDO_SQL START_SCN NAME
---------- ---------------------------------------- ---------- --------------------
UPDATE update "SCOTT"."TEST_QUERY" set "SALARY" 1056386 Lisa
= '7000' where ROWID = 'AAATFYAAEAAAAIX
AAC';
UPDATE update "SCOTT"."TEST_QUERY" set "SALARY" 1056386 John
= '5000' where ROWID = 'AAATFYAAEAAAAIX
AAA';
BEGIN 1056386
SELECT operation, undo_sql, START_SCN,
(select name from scott.test_query where rowid=flashback_transaction_query.ROW_ID) name
FROM flashback_transaction_query
WHERE xid = HEXTORAW('03001E0031030000')
ORDER BY undo_change#;
OPERATION UNDO_SQL START_SCN NAME
---------- ---------------------------------------- ---------- --------------------
UPDATE update "SCOTT"."TEST_QUERY" set "SALARY" 1056416 Chris
= '4000' where ROWID = 'AAATFYAAEAAAAIX
AAD';
UPDATE update "SCOTT"."TEST_QUERY" set "SALARY" 1056416 Lisa
= '10000' where ROWID = 'AAATFYAAEAAAAI
XAAC';
UPDATE update "SCOTT"."TEST_QUERY" set "SALARY" 1056416 William
= '6000' where ROWID = 'AAATFYAAEAAAAIX
AAB';
OPERATION UNDO_SQL START_SCN NAME
---------- ---------------------------------------- ---------- --------------------
UPDATE update "SCOTT"."TEST_QUERY" set "SALARY" 1056416 John
= '0' where ROWID = 'AAATFYAAEAAAAIXAAA
';
BEGIN 1056416
f. 修正資料
update scott.test_query set salary=5500 where name='John';
update scott.test_query set salary=7700 where name='Lisa';
commit;
g.另外也可以使用閃回表回退到錯誤操作發生前的時間點
SQL> alter table scott.test_query enable row movement;
Table altered.
SQL> flashback table scott.test_query to scn 1056383;
Flashback complete.
SQL> select * from scott.test_query;
ID NAME SALARY
---- -------------------- ----------
1 John 5000
2 William 6000
3 Lisa 7000
4 Chris 4000
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/438414/viewspace-757502/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DM7閃回與閃回查詢
- Oracle 11G 閃回技術 閃回版本查詢和閃回事務查詢Oracle
- DM8 閃回查詢
- Oracle 11G 閃回技術 使用Oracle閃回事務查詢Oracle
- MySQL 覆蓋索引、回表查詢MySql索引
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- Oracle查詢回滾大事務所需時間Oracle
- 拉鍊表的建立、查詢和回滾
- 2.6.3 指定閃回區
- Oracle資料庫閃回Oracle資料庫
- flashback query閃回資料
- SQL查詢的:子查詢和多表查詢SQL
- 還傻傻分不清MySQL回表查詢與索引覆蓋?MySql索引
- mysql-分組查詢-子查詢-連線查詢-組合查詢MySql
- 複雜查詢—子查詢
- 查詢——二分查詢
- my2sql資料閃回SQL
- 詳解oracle資料庫閃回Oracle資料庫
- 【趙強老師】MySQL的閃回MySql
- 【PDB】pdb閃回,Oracle還原點Oracle
- Oracle 閃回資料庫測試Oracle資料庫
- mysql閃回工具binlog2sqlMySql
- Oracle閃回技術--Flashback Version QueryOracle
- MYSQL學習筆記25: 多表查詢(子查詢)[標量子查詢,列子查詢]MySql筆記
- Elasticsearch複合查詢——boosting查詢Elasticsearch
- 查詢演算法__Fibonacci查詢演算法
- group by,having查詢 ”每**“的查詢
- 淺析微信支付:申請退款、退款回撥介面、查詢退款
- 工具分享丨資料閃回工具MyFlash
- 【RECO_ORACLE】Oracle閃回PDB的方法Oracle
- Flashback Drop閃回刪除功能實踐
- dg_閃回資料庫實驗資料庫
- [20180423]表空間閃回與snapshot standby
- Orcale利用閃回功能恢復資料
- oracle 精確查詢和模糊查詢Oracle
- pgsql查詢優化之模糊查詢SQL優化
- MySQL - 資料查詢 - 簡單查詢MySql
- 離線查詢與線上查詢
- 查詢演算法__插值查詢演算法