반응형
/********************************************************************************************
-- Title : [10g] 플래쉬백 Table Level : Flashback Table - ver.dbrang
-- Reference : dbrang.tistory.com
-- Key word : flashback 플래쉬백 테이블
********************************************************************************************/

/************************************************
-- Table Level : Flashback Table
************************************************/
-- 테이블 생성
-- drop table scott.ttt2;
create table scott.ttt2
( a number not null primary key
, b number not null
, c varchar2(10) not null
) tablespace users;

-- 데이터 입력(천천히 반복)
insert into scott.ttt2 values (1,1,'111');
commit;

insert into scott.ttt2 values (2,2,'222');
commit;

insert into scott.ttt2 values (3,3,'333');
commit;

insert into scott.ttt2 values (4,4,'444');
commit;

insert into scott.ttt2 values (5,5,'555');
commit;

insert into scott.ttt2 values (6,6,'666');
commit;

-- 입력 확인
select * from scott.ttt2;

-- Version Query
select scott.ttt2.*
     , versions_startscn, versions_endscn, versions_xid, versions_operation
     , versions_starttime, versions_endtime
from scott.ttt2 versions between scn minvalue and maxvalue;

-- ROW MOVEMENT 설정
-- ROW 이동이 발생하기에 허용
alter table scott.ttt2 enable row movement;

-- A=3 이전으로 복구(STARTSCN확인)
select scott.ttt2.*
     , versions_startscn, versions_endscn, versions_xid, versions_operation
     , versions_starttime, versions_endtime
from scott.ttt2 versions between scn minvalue and maxvalue;

-- 복구
-- 테이블 DDL 발생시 복구 불가
flashback table scott.ttt2
to scn '890255';

-- 복구 확인
select * from scott.ttt2;

-- 5분전으로 복구
flashback table scott.ttt2
to timestamp (systimestamp - interval '5' minute);

-- 복구 확인
select * from scott.ttt2;

-- ROW MOVEMENT 해제
alter table scott.ttt2 disable row movement;
 

/************************************************
-- Table Level : Recycle Bin
************************************************/
-- 인덱스 생성
create index scott.ix_ttt2
on scott.ttt2(c)
tablespace users;

-- 테이블 삭제
drop table scott.ttt2;

-- 삭제 확인
select * from dba_tables
where owner = 'SCOTT' and table_name = 'TTT2';

-- 휴지통 확인
select * from dba_recyclebin
where owner = 'SCOTT' and original_name = 'TTT2';

-- 테이블 복구
flashback table scott.ttt2
to before drop;

-- 복구 확인
select * from dba_tables
where owner = 'SCOTT' and table_name = 'TTT2';

-- 인덱스명 확인
-- 인덱스명은 휴지통에서 복구시 원위치 되지 않음
select * from dba_indexes
where owner = 'SCOTT' and table_name = 'TTT2';

-- 인덱스명 변경
alter index scott."BIN$s74u+VeX1OzgQAB/AQAVOA==$0"
rename to pk_ttt2;

alter index scott."BIN$s74u+VeY1OzgQAB/AQAVOA==$0"
rename to ix_ttt2;

-- 인덱스명 변경 확인
select * from dba_indexes
where owner = 'SCOTT' and table_name = 'TTT2';

-- 강제 삭제
drop table scott.ttt2 purge; /* 테이블 완전 삭제 */
purge table scott.ttt;       /* 휴지통에서 해당 테이블 완전 삭제 */
purge recyclebin;            /* 휴지통 비우기 */
 
 

 
반응형

+ Recent posts