
undo_retention 기간동안 가능
, 지났다면 로그마이너로 쿼리추출해야한다.
● 1. 작업
create table hr.emp_30
as select * from hr.employees where department_id=30;
SYS@ora11g> select current_scn, systimestamp from v$database;
CURRENT_SCN
-----------
SYSTIMESTAMP
---------------------------------------------------------------------------
1594267
27-JAN-24 10.41.00.373688 AM +09:00
update hr.emp_30
set salary =3000
where employee_id=114;
commit;
SYS@ora11g> select current_scn, systimestamp from v$database;
CURRENT_SCN
-----------
SYSTIMESTAMP
---------------------------------------------------------------------------
1594466
27-JAN-24 10.44.55.764264 AM +09:00
● 2. Flashback Query
- as of timestamp
: 특정시간대 쿼리를 확인할수있다
대신, undo_retention 기간동안만 가능
SYS@ora11g> select salary
from hr.emp_30 as of timestamp to_timestamp('2024/01/27 10:42:00','yyyy/mm/dd hh24:mi:ss')
where employee_id = 114;
SALARY
----------
11000
: version 절을 사용하여 두 point-in-time 또는 두 SCN 사이에 존재하는 행의 모든 버전을 검색할 수 있다.
● 1. 작업
SYS@ora11g> select count(*) from hr.emp_30;
COUNT(*)
----------
6
SYS@ora11g> select current_scn, systimestamp from v$database;
CURRENT_SCN
-----------
SYSTIMESTAMP
---------------------------------------------------------------------------
1595132
27-JAN-24 10.56.45.924870 AM +09:00
SYS@ora11g> update hr.emp_30 set salary=salary*1.1 where employee_id=115;
1 row updated.
SYS@ora11g> delete from hr.emp_30 where employee_id =116;
1 row deleted.
SYS@ora11g> commit;
Commit complete
● 2. Flashback version query
SYS@ora11g> select salary
from hr.emp_30 as of timestamp to_timestamp('2024/01/27 10:56:45','yyyy/mm/dd hh24:mi:ss');
SALARY
----------
3000
3100
2900
2800
2600
2500
6 rows selected.
select versions_xid, employee_id, last_name, salary
from hr.emp_30 versions between scn minvalue and maxvalue;
select versions_xid, employee_id, last_name, salary
from hr.emp_30 versions between timestamp to_timestamp('2024/01/27 10:56:45','yyyy/mm/dd hh24:mi:ss')
and to_timestamp('2024/01/27 10:57:00','yyyy/mm/dd hh24:mi:ss');
select versions_xid, employee_id, last_name, salary
from hr.emp_30 versions between scn minvalue
and '1595132';
: 백업으로 복원하지 않고 테이블을 특정 시점으로 recovery 할 수 있다.
- 권한 부여
- 객체 권한
grant flashback on '테이블명' to '유저명'
- 시스템 권한
grant flashback any table to '유저명';
● 1. 작업
select current_scn, systimestamp from v$database;
1596824 24/01/27 11:17:02.488599000 +09:00
delete from hr.emp_30;
commit;
● 2. 테이블을 활성화 작업
SYS@ora11g> alter table hr.emp_30 enable row movement;
Table altered.
● 3. flashback table
SYS@ora11g> flashback table hr.emp_30 to timestamp to_timestamp('2024/01/27 11:17:00','yyyy/mm/dd hh24:mi:ss');
Flashback complete.
SYS@ora11g> select count(*) from hr.emp_30;
COUNT(*)
----------
5
● 4. 테이블 비활성화
SYS@ora11g> alter table hr.emp_30 disable row movement;
Table altered.