versions_xid ~ versions_operstion
11g WS2.ch11 Flashback
-----------------------------
■ Flashback Query
-----------------------------
HR@orcl>select salary from employees where employee_id = 100;
SALARY
----------
24000
HR@orcl>update employees set salary = 30000 where employee_id = 100;
1 row updated.
HR@orcl>commit;
Commit complete.
HR@orcl>select salary from employees where employee_id = 100;
SALARY
----------
30000
HR@orcl>flashback query
2 select salary from employees
3 as of timestamp(systimestamp - interval '5' minute)
4 where employee_id = 100;
flashback query
*
ERROR at line 1:
ORA-00905: missing keyword
HR@orcl>ed
Wrote file afiedt.buf
1 select salary from employees
2 as of timestamp(systimestamp - interval '5' minute)
3* where employee_id = 100
HR@orcl>/
SALARY
----------
24000
HR@orcl>ed
Wrote file afiedt.buf
1 update employees
2 set salary = (select salary from employees
3 as of timestamp(systimestamp - interval '5' minute)
4* where employee_id = 100)
HR@orcl>/
107 rows updated.
HR@orcl>ed
Wrote file afiedt.buf
1 update employees
2 set salary = (select salary from employees
3 as of timestamp(systimestamp - interval '5' minute) <- second minute hour 모두 가능
4* where employee_id = 100)
HR@orcl>select salary from employees where employee_id = 100;
SALARY
----------
24000
-------------------------------------------
■ Flashback versions query(10g New Feature)
-------------------------------------------
SYS@orcl>alter database add supplemental log data; <- 비활성화 상태에서는 해당 컬럼(필드) 정보에 대한
변경분만 저장되고 add 활성화되면 해당 log에 대한 row data가 모두 저장이 되서 versions transaction query에서는 필수 옵션이다.
Database altered.
HR@orcl>create table fvq_table as select * from employees;
Table created.
select employee_id, first_name, last_name, salary
from fvq_table
where department_id in (10,20);
EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
----------- -------------------- ------------------------- ----------
200 Jennifer Whalen 4400
201 Michael Hartstein 13000
202 Pat Fay 6000
HR@orcl>update fvq_table set salary=15000 where employee_id = 201;
1 row updated.
HR@orcl>commit;
Commit complete.
HR@orcl>update fvq_table set first_name='OCM' where employee_id = 202;
1 row updated.
HR@orcl>commit;
Commit complete.
select employee_id, first_name, last_name, salary
from fvq_table
3 where department_id in (10,20);
EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
----------- -------------------- ------------------------- ----------
200 Jennifer Whalen 4400
201 Michael Hartstein 15000
202 OCM Fay 6000
SYS@orcl>flashback table hr.employees to timestamp (systimestamp - interval '25' minute);
flashback table hr.employees to timestamp (systimestamp - interval '25' minute)
*
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
salary가 모두 24000이 되서 table level로 되돌림
SYS@orcl>alter table hr.employees enable row movement;
Table altered.
SYS@orcl>flashback table hr.employees to timestamp (systimestamp - interval '25' minute);
Flashback complete.
select ora_rowscn, employee_id, first_name, last_name, salary
from fvq_table
3 where employee_id=202;
ORA_ROWSCN EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
---------- ----------- -------------------- ------------------------- ----------
1129971 202 OCM Fay 6000
select versions_xid, versions_startscn, versions_operation, employee_id, first_name, last_name, salary
from fvq_table versions between scn minvalue and maxvalue
3 where department_id in (10,20);
VERSIONS_XID VERSIONS_STARTSCN V EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
---------------- ----------------- - ----------- -------------------- ------------------------- ----------
0100180017020000 1130441 U 202 OCM Fay 6000
0100100017020000 1130391 U 201 Michael Hartstein 15000
1130391 U 202 OCM Fay 6000
200 Jennifer Whalen 4400
201 Michael Hartstein 13000
202 Pat Fay 6000
6 rows selected.
HR@orcl>select scn_to_timestamp(1130391) from dual;
SCN_TO_TIMESTAMP(1130391)
---------------------------------------------------------------------------
13-OCT-15 05.41.45.000000000 PM
-----------------------------
■ Flashback transaction query
---------------------------
HR@orcl>select operation, undo_sql, start_scn
2 from flashback_transaction_query
3 where xid=hextoraw('0100180017020000'); <헥사값
from flashback_transaction_query
*
ERROR at line 2:
ORA-01031: insufficient privileges
HR@orcl>conn / as sysdba
Connected.
SYS@orcl>grant select any transaction to hr; <꼭 필요한 권한
Grant succeeded.
SYS@orcl>conn hr/hr
Connected.
1 select operation, undo_sql, start_scn
2 from flashback_transaction_query
3* where xid=hextoraw('0100180017020000')
HR@orcl>/
HR@orcl>/
OPERATION
--------------------------------
UNDO_SQL
------------------------------------------------------------------------------------------------------------------------------------------------------
START_SCN
----------
UPDATE
update "HR"."FVQ_TABLE" set "FIRST_NAME" = 'OCM' where ROWID = 'AAASRxAAEAAAAIbAAJ';
1130440
BEGIN
1130440
HR@orcl>conn / as sysdba
Connected.
SYS@orcl>select current_scn from v$database;
CURRENT_SCN
-----------
1131229
1 select xid, operation, start_scn, start_timestamp, commit_scn, commit_timestamp, undo_sql
2 from flashback_transaction_query
3 where table_name = 'FVQ_TABLE'
4* and commit_scn between 1130391 and 1131229
SYS@orcl>/
XID OPERATION START_SCN START_TIMESTAMP COMMIT_SCN COMMIT_TIMESTAMP
---------------- -------------------------------- ---------- ------------------- ---------- -------------------
UNDO_SQL
------------------------------------------------------------------------------------------------------------------------------------------------------
0100180017020000 UPDATE 1130440 2015-10-13:17:42:06 1130441 2015-10-13:17:42:06
update "HR"."FVQ_TABLE" set "FIRST_NAME" = 'OCM' where ROWID = 'AAASRxAAEAAAAIbAAJ';
0100100017020000 UPDATE 1130017 2015-10-13:17:35:12 1130391 2015-10-13:17:41:45
update "HR"."FVQ_TABLE" set "SALARY" = '15000' where ROWID = 'AAASRxAAEAAAAIbAAI';
0100100017020000 UPDATE 1130017 2015-10-13:17:35:12 1130391 2015-10-13:17:41:45
update "HR"."FVQ_TABLE" set "FIRST_NAME" = 'Pat' where ROWID = 'AAASRxAAEAAAAIbAAJ';
0100100017020000 UPDATE 1130017 2015-10-13:17:35:12 1130391 2015-10-13:17:41:45
update "HR"."FVQ_TABLE" set "SALARY" = '13000' where ROWID = 'AAASRxAAEAAAAIbAAI';
SYS@orcl>update "HR"."FVQ_TABLE" set "FIRST_NAME" = 'Pat' where ROWID = 'AAASRxAAEAAAAIbAAJ';
1 row updated.
SYS@orcl>update "HR"."FVQ_TABLE" set "SALARY" = '13000' where ROWID = 'AAASRxAAEAAAAIbAAI';
1 row updated.
SYS@orcl>select employee_id, first_name, last_name, salary
2 from hr.fvq_table
3 where department_id in (10,20);
EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
----------- -------------------- ------------------------- ----------
200 Jennifer Whalen 4400
201 Michael Hartstein 13000
202 Pat Fay 6000
SYS@orcl>drop table hr.fvq_table purge;
Table dropped.
'스터디북' 카테고리의 다른 글
[10/14] 정리 (0) | 2015.10.14 |
---|---|
[10/13] admin 기본 연습 (0) | 2015.10.13 |
[10/13] 실습 - 3 Backupset의 병렬화 (0) | 2015.10.13 |
[10/13] 실습 - 2 RMAN을 이용한 Duplicate 복제 DB 생성 (0) | 2015.10.13 |
[10/13] 실습 - 1 RMAN - current redolog file (0) | 2015.10.13 |