1. Transaction 1 은 5개의 rows 를 입력.
2. Transaction 2 는 2개의 rows 를 update.
3. Transaction 3 은 또다시 3개의 rows 를 update, 그 중 1개는 Transaction 2 에서 이미 update 한 1개의 row 와 관련.
4. Transaction 4 는 또 다른 1개의 row 를 update. 이것은 이전의 Transaction 2 와 아무런 관련이 없다.
5. 여기서는 이미 Commit 된 Transaction 들 중에서 Transaction 2 를 Roll Back 하고자 했고 Transaction 2 와 연관 있는 Transaction 3 도 함께 Roll back 처리 됨을 확인.
6. Transaction 4 는 그냥 그대로 반영된 상태로 남아 있다는 것을 확인.
sqlplus "/ as sysdba"
ALTER USER HR IDENTIFIED BY hr ACCOUNT UNLOCK;
ALTER SYSTEM SET db_recovery_file_dest_size = 10737418240 SCOPE=BOTH;
shutdown immediate
startup mount
alter database archivelog;
alter database open;
archive log list
exit
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
GRANT EXECUTE ON dbms_flashback TO hr;
GRANT select any transaction TO hr;
/*== Create test data for flashback transaction ==*/
connect hr/hr
/*== Test transaction 1 ==*/
INSERT INTO hr.regions VALUES (10,'Pole');
INSERT INTO hr.regions VALUES (20,'Moon');
INSERT INTO hr.regions VALUES (30,'Venus');
INSERT INTO hr.regions VALUES (40,'Mars');
INSERT INTO hr.regions VALUES (50,'Saturn');
COMMIT;
/*== Test transaction 2 ==*/
/*== Region 10 and 20 has a WAW dependency on transaction 1 ==*/
UPDATE hr.regions SET region_name='Two Poles' WHERE region_id = 10;
UPDATE hr.regions SET region_name='Many Moons' WHERE region_id = 20;
COMMIT;
/*== Test transaction 3 ==*/
/*== Region 10 has a WAW dependency on transaction 1 and 2 ==*/
/*== Region 40 and 50 has a WAW dependency on transaction 1 ==*/
UPDATE hr.regions SET region_name='No star' WHERE region_id = 10;
UPDATE hr.regions SET region_name='Red star' WHERE region_id = 40;
UPDATE hr.regions SET region_name='Big star' WHERE region_id = 50;
COMMIT;
/*== Test transaction 4 ==*/
/*== Region 30 has a WAW dependency on transaction 1 ==*/
UPDATE hr.regions SET region_name='Still called Venus' WHERE region_id = 30;
COMMIT;
connect / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
prompt "Setup for Flashback Transaction completed"
exit
Nonconflict Only - 대상 Transaction의 충돌하지 않는 변경 사항만 취소.
Nocascade Force - 대상 Transaction의 모든 변경 사항이 취소.
Cascade - 대상 Transaction의 모든 변경 사항과 종속 Transaction의 모든 변경 사항이 취소.
BEGIN
DBMS_FLASHBACK.transaction_backout (numtxns => 1,
xids => xid_array('060015009D030000'),
options => DBMS_FLASHBACK.cascade);
END;
/
SELECT *
FROM dba_flashback_txn_state
WHERE xid = '060015009D030000';
SELECT xid_report
FROM dba_flashback_txn_report
WHERE compensating_xid = '05001800A0030000';
SQL 실행
Flashback Transaction을 커밋하기 전에 SQL 질의를 실행하여 변경으로 인한 영향을 확인할 수 있습니다.
---------------------------------
[exec=yes] update "HR"."REGIONS" set "REGION_NAME" = 'Moon' where "REGION_ID" = '20' and
"REGION_NAME" = 'Many Moons'
[exec=no] update "HR"."REGIONS" set "REGION_NAME" = 'Pole' where "REGION_ID" = '10' and
"REGION_NAME" = 'Two Poles'
---------------------------------
[exec=no] update "HR"."REGIONS" set "REGION_NAME" = 'Saturn' where "REGION_ID" = '50' and
"REGION_NAME" = 'Big star'
[exec=no] update "HR"."REGIONS" set "REGION_NAME" = 'Mars' where "REGION_ID" = '40' and
"REGION_NAME" = 'Red star'
[exec=no] update "HR"."REGIONS" set "REGION_NAME" = 'Two Poles' where "REGION_ID" = '10' and
"REGION_NAME" = 'No star'