DATABASE/Oracle
[Oracle] interval partition table 주기적으로 파티션 삭제하기
DBnA
2023. 7. 11. 11:05
728x90
반응형
인터벌 파티션 테이블로 생성된 테이블의 일정 보관 기간이 지나면 데이터 삭제가 필요.
oracle job 통해 배치 생성하여 주기적으로 데이터 관리 진행함
declare
cursor c_del_partition is
select object_name as tb_nm,
subobject_name as partition_nm
from ALL_OBJECTS
where owner = [스키마명]
and object_type = 'TABLE PARTITION'
and generated = 'Y' -- 시스템생성여부 : 인터벌파티션의 경우 자동생성되므로 시스템생성여부가 Y임
and ( object_name = [인터벌파티션테이블명] and created < trunc(sysdate)-10 ) ; --10일보관
;
begin
for c in c_del_partition
loop
l_ddl_str := 'alter table '||c.tb_nm||' drop partition '||c.partition_nm||'';
begin
execute immediate l_ddl_str;
exception
when others then
l_err_code := ''||SQLCODE;
l_err_msg := SQLERRM || ' ( ' || c.partition_nm || ' ) ' ;
insert into TB_ERR_LOG (wrk_tbl_nm, err_cd, err_msg) values (c.tb_nm,l_err_code,l_err_msg);
commit;
end;
end loop;
end;
all_object의 generated, created 컬럼 활용하여 삭제 대상 파티션 선정 후
파티션 삭제 진행
728x90
반응형