일반 테이블 파티션 전환

싱하·2024년 9월 30일
0

oracle

목록 보기
6/6

일반 원장테이블을 갑자기 파티션으로 전환해라..?

일반 테이블을 파티션을 해야할거같다는 현업의 요청..
일단 검색하면 다 나오니까 지식 줍줍

일단 안해본 작업이니 개발쪽에서 테스트 ㄱㄱ

create user imsi identified by imsi default tablespace~~ quota~~quota~~;

# CTAS로 테이블 복사
create table imsi.table as select * from [해당유저].table;

create index PK~~
create index 01~~
create index 02~~

일단 테이블, 인덱스 만들기 완료.

SQL> select dip.index_owner, dpi.table_name, dip.index_name, dip.partition_name, dip.status, dpi.locality
from dba_ind_partitions dip, dba_part_indexes dpi
where 1=1
and dpi.index_name = dip.index_name
and dpi.table_name ='table'
and dip.index_owner = 'IMSI'
order by dip.index_name, dip.partition_name;

=> no rows selected

파티셔닝이 안되어있으니깐 당연한 결과다. 이제 파티션 ㄱㄱ

파티션 테이블로 변환

SQL> alter table imsi.table modify partition by range(column1)(
partition p_2023 values less than ('2024'),
partition p_2024 values less than ('2025'),
partition p_max values less than (MAXVALUE)) online
update indexes
(imsi.table_PK local tablespace TBS_INDEX,
imsi.table_IDX1 local tablespace TBS_INDEX,
imsi.table_IDX2 local tablespace TBS_INDEX);

인덱스가 여러개면 이렇게 그냥 바꾸면 된다.
파티션을 하고나서는 인덱스가 로컬로 있어야 관리적인 면에서 용이함.

확인작업

SQL> select dip.index_owner, dpi.table_name, dip.index_name, dip.partition_name, dip.status, dpi.locality
from dba_ind_partitions dip, dba_part_indexes dpi
where 1=1
and dpi.index_name = dip.index_name
and dpi.table_name ='table'
and dip.index_owner = 'IMSI'
order by dip.index_name, dip.partition_name;

owner	table_name	index_name	partition_name	status	locality
-----------------------------------------------------------------
imsi	table		table_PK	p_2023			usable	local
imsi	table		table_PK	p_2024			usable	local
imsi	table		table_PK	p_max			usable	local
imsi	table		table_idx1	p_2023			usable	local
imsi	table		table_idx1	p_2024			usable	local
imsi	table		table_idx1	p_max			usable	local
imsi	table		table_idx2	p_2023			usable	local
imsi	table		table_idx2	p_2024			usable	local
imsi	table		table_idx2	p_max			usable	local

파티션 별로 local index 로의 변환이 잘 된것을 확인할 수 있음.

회고

처음에는 insert as select 으로 데이터 넣고 rename 으로 테이블 바꾸고 index재생성하려고했는데 너무 1차원적인 방법이였다.
이번 작업을 통해서 좋은 방법하나 얻었으니 까먹지말고 기억해둬야겠다

profile
끄적끄적...

0개의 댓글

관련 채용 정보