!flashback 버전.png!
SQL> select supplemental_log_data_min from v$database
2 /
SUPPLEMENTAL_LOG
----------------
NO
SQL>alter database add supplemental log data;
Database altered
SQL> select supplemental_log_data_min from v$database
2 /
SUPPLEMENTAL_LOG
----------------
YES
SQL> create table fmem
2 (name varchar2(10)
3 ,addr varchar2(10)
4 ,tel varchar2(10)
5 );
Table created
SQL>insert into fmem values('박동주','부천','111');
1 row created
SQL>insert into fmem values('서진수','강남','222');
1 row created
SQL>insert into fmem values('채미','전남','333');
1 row created
SQL>commit;
Commit complete.
SQL> select * from fmem;
NAME ADDR TEL
-------------------- -------------------- --------------------
박동주 부천 111
서진수 강남 222
채미 전남 333
SQL> update fmem set name = '안지혜' where tel = '111';
1 row updated.
SQL> commit;
Commit complete.
SQL> update fmem set name = '김세실' where tel = '333';
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from fmem;
NAME ADDR TEL
-------------------- -------------------- --------------------
안지혜 부천 111
서진수 강남 222
김세실 전남 333
** 변경 이력을 찾는 Flashback Version Query 수행
SQL> select versions_startscn st_scn, versions_endscn endscn,
2 versions_xid txid, versions_operation opt, name
3 from fmem versions between scn minvalue and maxvalue
4* where tel = '111';
SQL> ST_SCN ENDSCN TXID OP NAME
---------- ---------- ---------------- -- --------------------
3566236 0500100032030000 U 안지혜
3566164 3566236 01000200C7020000 I 박동주
** scn_to_timestamp을 이용한 발생시간 Query
SQL> select scn_to_timestamp(3566236) from dual;
SCN_TO_TIMESTAMP(3566236)
------------------------------------------------------------
15/12/07 20:16:36.000000000
SQL> update fmem set name = '박동주' where tel = '111';
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from fmem;
NAME ADDR TEL
-------------------- -------------------- --------------------
박동주 부천 111
서진수 강남 222
김세실 전남 333
SQL>create table fruits
(no number
,name varchar2(10)
,price number);
SQL> insert into fruits values(1,'apple',1000);
1 row created.
SQL> insert into fruits values(2,'grape',1500);
1 row created.
SQL> insert into fruits values(3,'orange',800);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from fruits;
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 1500
3 orange 800
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
3567107
SQL> update fruits
2 set price = 2000
3 where no = 2
SQL> /
1 row updated.
SQL>
SQL>
SQL>
SQL> commit;
Commit complete.
SQL> select * from fruits
2 /
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 2000
3 orange 800
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
3567136 <= grape 가격이 2000원으로 변경된 scn
SQL> update fruits
2 set price = 1000
3 where no = 3
4 /
1 row updated.
SQL>
SQL>
SQL> select * from fruits
2 /
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 2000
3 orange 1000
SQL> commit;
Commit complete.
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
3567168 <= orange 가격을 800 -> 1000원으로 업데이트한 scn
* orange 가격이 800원인 때로 Flashback
SQL>flashback table fruits to scn '3567107'
flashback table fruits to scn '3567107'
ERROR at line 1:
ORA-08189 : cannot flashback the table bacause row movement is not enabled
SQL> alter table fruits enable row movement;
Table altered
SQL>flashback table fruits to scn '3567107'
Flashback complete
SQL> select * from fruits
2 /
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 2000
3 orange 800
SQL> select * from fruits;
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 1500
3 orange 800
SQL> update fruits
2 set price = 3000;
3 rows updated
SQL> commit;
Commit complete.
SQL> select * from fruits;
NO NAME PRICE
---------- -------------------- ----------
1 apple 3000
2 grape 3000
3 orange 3000
SQL>delete from fruits;
3 rows deleted
SQL>select * from fruits;
no rows selected
SQL>commit;
Commit complete.
SQL>flashback table fruits
2 to timestamp(systimestamp - interval '2' minute);
Flashback complete
SQL>select * from fruits;
no rows selected
SQL>flashback table fruits
2 to timestamp(systimestamp - interval '5' minute);
SQL> select * from fruits;
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 1500
3 orange 800
* 시간을 너무 이전 시점으로 설정할 경우 에러 발생
SQL>flashback table fruits
2 to timestamp(systimestamp - interval '90' minute);
flashback table fruits
*
ERROR at line 1:
ORA-01466:unable to read data - table definition has changed
SQL> select * from fruits;
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 1500
3 orange 1000
SQL>update fruits set price = 3000;
3 rows updated
SQL>commit;
Commit complete.
SQL>alter table fruits add (qty number default 0);
Table altered
SQL> select * from fruits;
NO NAME PRICE QTY
---------- -------------------- ---------- ---------
1 apple 3000 0
2 grape 3000 0
3 orange 3000 0
SQL>flashback table fruits
2 to timestampe(systimestamp - interval '6' minute);
Flashback complete <= 컬럼을 추가하고 한 후 flashback을 수행합니다
SQL> select * from fruits;
NO NAME PRICE QTY
---------- -------------------- ---------- ---------
1 apple 1000
2 grape 2000
3 orange 1000
SQL>alter table fruits drop column qty;
Table altered <= 컬럼을 삭제
SQL> select * from fruits;
NO NAME PRICE
---------- -------------------- ----------
1 apple 1000
2 grape 2000
3 orange 1000
SQL>flashback table fruits
2 to timestampe(systimestamp - interval '8' minute);
flashback table fruits
*
ERROR at line 1:
ORA-01466:unable to read data - table definition has changed
SQL>flashback table fruits
2 to timestampe(systimestamp - interval '6' minute);
flashback table fruits
*
ERROR at line 1:
ORA-01466:unable to read data - table definition has changed