■ Flashback

YoonSeo Park ·2024년 1월 30일
post-thumbnail

Flashback

undo_retention 기간동안 가능
, 지났다면 로그마이너로 쿼리추출해야한다.

■ Flashback Query

  • 특정 시간에 query를 수행할 수 있다.
  • select 문의 as of 절을 사용하여 데이터를 확인할 시간 기록을 지정할 수 있다.
  • 데이터 불일치 분석에 유용하다.

● 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 문
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

■ Flashback version query

: 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

  • Flashback 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';

■ Flashback Table

: 백업으로 복원하지 않고 테이블을 특정 시점으로 recovery 할 수 있다.

  • 데이터베이스는 온라인 상태를 유지 한다.
  • flashback table 작업을 수행하기 위해 언두 테이블스페이스에서 데이터를 사용한다.
  • 권한 부여
    • 객체 권한
grant flashback on '테이블명' to '유저명'
  • 시스템 권한
grant flashback any table to '유저명';
  • flashback table에 대한 행 이동이 활성화 되어있어야 한다.

● 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.
profile
DB 공부를 하고 있는 사람입니다. 글을 읽어주셔서 감사하고 더 좋은 글을 쓰기 위해 노력하겠습니다 :)

0개의 댓글