2009년 4월 2일 목요일

PARTITION TABLE의 관리를 위한 COMMAND 게시일: 2006. 12. 10 오후 11:33

제품 : ORACLE SERVER

작성날짜 : 2004-08-16

PARTITION TABLE의 관리를 위한 COMMAND
=====================================


Purpose



--------------------------------------------------------------------------------
Oracle8 부터 사용가능한 Partition table을 handling 하기 위한
다양한 command들을 확인해 보자.

SCOPE



--------------------------------------------------------------------------------
8~10g Standard Edition 에서는 Partitioning Option 은 지원하지 않는다.

Explanation



--------------------------------------------------------------------------------

예제 아래와 같이 partition table을 생성한다.

SQL> create table part_tbl
( in_date number primary key ,
empno number,
ename varchar2(20),
job varchar2(20) )
partition by range (in_date)
(partition part_tbl_03 values less than (20000331)
tablespace pts_03,
partition part_tbl_04 values less than (20000430)
tablespace pts_04,
partition part_tbl_05 values less than (20000531)
tablespace pts_05,
partition part_tbl_06 values less than (20000630)
tablespace pts_06,
partition part_tbl_07 values less than (20000731)
tablespace pts_07,
partition part_tbl_08 values less than (20000831)
tablespace pts_08,
partition part_tbl_09 values less than (20000930)
tablespace pts_09,
partition part_tbl_10 values less than (20001031)
tablespace pts_10 );

1. partition 을 add하는 방법

11월과 12월에 대해 partition을 add하고 싶은 경우 다음과 같이 할 수 있다.

SQL> alter table part_tbl add partition part_tbl_11
values less than (20001130) tablespace pts_11;

SQL> alter table part_tbl add partition part_tbl_12
values less than (20001231) tablespace pts_12;


2. 특정 partition 을 삭제하는 방법

8월에 해당하는 partition을 없애고 싶은 경우는 다음과 같이 실행한다.

SQL> alter table part_tbl drop partition part_tbl_08;

drop된 후에 새로 8월에 해당하는 데이타가 입력되면
9월의 partition이 less then (20000930) 으로 되어 있으므로
9월에 해당하는 partition에 저장된다.


3. partition을 나누는 방법

1월, 2월에 해당하는 partition을 생성하려면 partition을
add하는 것으로는 불가능하고 기존의 partition에서 split 해야 한다.

SQL> alter table part_tbl split partition part_tbl_03
at (20000229)
into (partition part_tbl_02 tablespace pts_02,
partition part_tbl_03_1 tablespace pts_03);

위와 같이 하면 기존의 partition에서 2월29일을 기준으로 2월과 3월로
partition이 나눈다. 그리고 나서 다시 split 해야한다.

SQL> alter table part_tbl split partition part_tbl_02
at (20000131)
into (partition part_tbl_01 tablespace pts_01,
partition part_tbl_02_1 tablespace pts_02);


4. partition name을 변경하는 방법

partition name 을 바꾸고 싶다면 다음과 같이 실행한다.

SQL> alter table part_tbl rename partition part_tbl_02_1 to part_tbl_02;
SQL> alter table part_tbl rename partition part_tbl_03_1 to part_tbl_03;


5. partition의 tablespace를 옮기는 방법

partition part_tbl_10을 저장하는 tablespace를 pts_10 에서 pts_10_1로
바꾸고 싶은 경우 아래와 같은 command를 사용한다.

SQL> alter table part_tbl move partition part_tbl_10
tablespace pts_10_1 nologging;


6. 특정 partition의 data를 truncate하는 방법

partition의 data를 모두 삭제하려면 truncate하는 방법을 사용할 수가
있는 데, truncate는 rollback 이 불가능하며 특정 partition 전체를
삭제하므로 주의하여 사용하여야 한다.

SQL> alter table part_tbl truncate partition part_tbl_02;


7. Partition table의 물리적인 속성 변경

partition table은 특정 partition의 속성만 변경할 수 있고,
table의 속성을 변경하여 전체 partition에 대해 동일한 변경을 할 수 있다.

SQL> alter table part_tbl storage( next 10M);
-> part_tbl 의 모든 partition의 next 값이 변경된다.

SQL> alter table part_tbl modify partition part_tbl_05
storage ( maxextents 1000 );
-> part_tbl_05 partition의 maxextents 값만 변경한다.


8. Index의 관리

위와 같이 partition table 관련 작업을 한 후에는 table에 걸려 있는
local(partitioned) index 나 global index를 반드시 rebuild해 주어야 한다.

특정 partition의 index를 rebuild 하려면

SQL> alter index ind_part_tbl rebuild partition i_part_tbl_02;


그리고 global index를 rebuild하려면

SQL> alter index part_tbl_pk rebuild;


Reference Document


partition table에서의 index 관리에 대해서는 를 참고.

댓글 없음:

댓글 쓰기