【Oracle Database】闪回(FlashBack)
admin
2023-04-17 14:02:19
0
闪回版本查询
SQL> set line 200
SQL> col starttime for a30
SQL> col endtime for a30
SQL> col operation for a30

SQL> select to_char(versions_starttime,'yyyy-mm-dd hh34:mi:ss') starttime,to_char(versions_endtime,'yyyy-mm-dd hh34:mi:ss') endtime,
   versions_xid xid,versions_operation operation from soe.customers versions
   between timestamp to_date('2018-09-22 14:00:00','yyyy-mm-dd hh34:mi:ss') and sysdate where versions_xid is not null;
STARTTIME                      ENDTIME                        XID              OPERATION
------------------------------ ------------------------------ ---------------- ------------------------------
2018-09-22 14:00:36                                           05001100B8030000 U
2018-09-22 13:59:59                                           05000700B8030000 U
2018-09-22 14:00:25                                           08001B00CC030000 U
2018-09-22 14:00:14                                           05001000B8030000 I
2018-09-22 14:00:20                                           09001700C9030000 I
2018-09-22 14:00:05                                           0B00200041000000 I
2018-09-22 14:00:05                                           09000700CA030000 I
2018-09-22 14:00:11                                           03001800B4030000 I
8 rows selected.

闪回事务查询
SQL> select undo_sql from flashback_transaction_query where xid = hextoraw('03001800B4030000');
UNDO_SQL
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
delete from "SOE"."LOGON" where ROWID = 'AAAVU+AAGAAAavRAB6';
delete from "SOE"."CARD_DETAILS" where ROWID = 'AAAVU4AAHAAAQEoABz';
delete from "SOE"."ADDRESSES" where ROWID = 'AAAVU3AAHAAAbuoAAy';
delete from "SOE"."CUSTOMERS" where ROWID = 'AAAVU2AAGAAAaqxAAO';

SQL> select undo_sql from flashback_transaction_query where xid = hextoraw('08001B00CC030000');
UNDO_SQL
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
update "SOE"."CUSTOMERS" set "PREFERRED_ADDRESS" = '1162533' where ROWID = 'AAAVU2AAGAAACC9AAS';
delete from "SOE"."ADDRESSES" where ROWID = 'AAAVU3AAHAAAbumAA5';


闪回表--scn
SQL> alter table soe.customers enable row movement;

Table altered.
SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    975317

SQL> select dbms_flashback.get_system_change_number from dual; 

GET_SYSTEM_CHANGE_NUMBER
------------------------
                 1217679
                 
SQL> delete from soe.customers where nls_territory = 'Korea';

12470 rows deleted.

SQL> commit;

Commit complete.


SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    962847

SQL> flashback table soe.customers to scn 1217679;

Flashback complete.

SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    975317
    
闪回表--timestamp    
SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    975317

SQL> select dbms_flashback.get_system_change_number from dual; 

GET_SYSTEM_CHANGE_NUMBER
------------------------
                 1221943

SQL> select scn_to_timestamp(1221943) scn from dual;

SCN
---------------------------------------------------------------------------
23-SEP-18 04.17.24.000000000 PM


SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    975317


SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
------------------------
                 1222481

SQL> select scn_to_timestamp(1222481) scn from dual;

SCN
---------------------------------------------------------------------------
23-SEP-18 04.22.21.000000000 PM


SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    975340

SQL> flashback table soe.customers to timestamp to_timestamp('2018-09-23 16:17:24','yyyy-mm-dd hh34:mi:ss');

Flashback complete.


SQL> select count(*) from soe.customers;

  COUNT(*)
----------
    975317


闪回删除
SQL> show parameter recyclebin;
NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
recyclebin                           string                            ON

SQL> drop table warehouses;
Table dropped.

SQL> show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
WAREHOUSES       BIN$doc0/FwhEVPgU8kBqMBrow==$0 TABLE        2018-09-23:17:07:50

SQL> flashback table warehouses to before drop;
Flashback complete.

SQL> select count(*) from warehouses;
  COUNT(*)
----------
      1000
      
SQL> alter index "BIN$doc0/FwgEVPgU8kBqMBrow==$0" rename to warehouses_pk;
Index altered.

SQL> alter table warehouses rename constraint "BIN$doc0/FwfEVPgU8kBqMBrow==$0" to warehouses_pk;
Table altered.


闪回数据库
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             322962312 bytes
Database Buffers          687865856 bytes
Redo Buffers               55848960 bytes
Database mounted.

SQL> alter database flashback on;
Database altered.

SQL> alter database open;
Database altered.

SQL> select dbid,name,flashback_on,current_scn from v$database;

      DBID NAME                        FLASHBACK_ CURRENT_SCN
---------- --------------------------- ---------- -----------
1085678857 KING                        YES            1229459

SQL> show parameter db_flashback

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
db_flashback_retention_target        integer                           1440

SQL> alter session set nls_date_format='yyyy-mm-dd hh34:mi:ss';
Session altered.

SQL> select count(*) from orders;

  COUNT(*)
----------
   1430069
   
SQL> select sysdate from dual;
SYSDATE
-------------------
2018-09-24 13:43:57

SQL> truncate table orders;
Table truncated.

SQL> select count(*) from orders;

  COUNT(*)
----------
         0
         
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             322962312 bytes
Database Buffers          687865856 bytes
Redo Buffers               55848960 bytes
Database mounted.

SQL> flashback database to timestamp to_timestamp('2018-09-24 13:43:57','yyyy-mm-dd hh34:mi:ss');
Flashback complete.

SQL> alter database open read only;
Database altered.

SQL> conn soe/soe
Connected.
SQL> select count(*) from orders;

  COUNT(*)
----------
   1430069
   
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             322962312 bytes
Database Buffers          687865856 bytes
Redo Buffers               55848960 bytes
Database mounted.

SQL> alter database open resetlogs;
Database altered.

SQL> conn soe/soe
Connected.
SQL> select count(*) from orders;

  COUNT(*)
----------
   1430069


总结:闪回版本查询,闪回事务查询,闪回表与UNDO有关,与闪回日志没有任何关系
     闪回删除与recyclebin有关,与闪回日志没有任何关系
     闪回数据库与闪回日志有关


相关内容

热门资讯

徐巧芯剖析赖清德:最怕自己丢掉... 海峡导报综合报道 大罢免投票一周年纪念活动26日举行,台北市长蒋万安出席并怒轰,民进党一年过后仍没有...
中国红十字会总会紧急向广东调拨... 记者从中国红十字会总会了解到,针对台风“红霞”给广东造成的灾情,中国红十字会总会启动四级应急响应,紧...
这些少年,正被“毒蛋”围猎 李梦抽了几口电子烟,吐出了白色的烟雾,有一股浓烈的水果香味。随后,她看着自己握电子烟的手,跟身边人说...
蒋万安号召“倒阁”,卢秀燕认为... 海峡导报综合报道 台北市长蒋万安27日抛出震撼议题,表示多名民代向他提议推动“倒阁”,要求台行政机构...
特朗普将在白宫会见两位重要客人 俄乌战争仍未结束,美伊冲突又有升级风险。在此背景下,美国总统特朗普将在白宫接见乌克兰和以色列领导人。...
新租客打扫卧室柜子上掉落4万元... 近日,莲前西路某小区内,张倩签下一套房子的租赁合同。当天上午,她带着12岁的大女儿周馨怡和11岁的小...
六部门通告:禁止涉军队退役报废... 关于禁止涉军队退役报废装备销售活动的通告近年来,部分经营者在线上线下公开销售涉及我军退役报废装备(指...
九寨沟景区发生泥石流,部分道路... 7月26日,九寨沟风景名胜区管理局发布泥石流灾害通报:2026年7月26日15时50分,九寨沟景区局...
空调26度不凉是什么原因 从空调内部元器件来说,不凉的原因有可能是温度传感器出现故障了,也有可能是空调压缩机或者铜管出现问题,...
鲸鸿动能携手香港国际机场、鸿蒙...   2026 年 7 月 25 日,十余位鸿蒙车主组成的车队从珠海出发,经港珠澳大桥通关抵达香港国际...