DBAtlas · 데이터베이스 운영 아틀라스

exchange partition으로 대량 적재 또는 데이터 아카이브

Oracle파티셔닝

명령어

-- 1) Staging table that exactly matches the target (12.2+):
CREATE TABLE customer_app.sale_stage
  FOR EXCHANGE WITH TABLE customer_app.sale_part;

-- 2) Load the staging table and build indexes matching the local indexes:
INSERT /*+ APPEND */ INTO customer_app.sale_stage
SELECT * FROM customer_app.sale_load WHERE created_at >= DATE '2027-01-01';
COMMIT;
CREATE INDEX customer_app.sale_stage_customer_ix ON customer_app.sale_stage (customer_id);

-- 3) Swap (dictionary-only operation, no data movement):
ALTER TABLE customer_app.sale_part
  EXCHANGE PARTITION p2027 WITH TABLE customer_app.sale_stage
  INCLUDING INDEXES WITHOUT VALIDATION
  UPDATE GLOBAL INDEXES;

-- 4) Verify:
SELECT COUNT(*) FROM customer_app.sale_part PARTITION (p2027);
SELECT index_name, partition_name, status
FROM   dba_ind_partitions
WHERE  index_owner = 'CUSTOMER_APP' AND status <> 'USABLE';

하는 일

딕셔너리에서 파티션의 세그먼트와 일반 테이블의 세그먼트를 맞바꾼다. 수백만 행이 몇 초 만에 테이블로 "들어오거나" 아카이브를 위해 "나간다". FOR EXCHANGE WITH TABLE은 컬럼 및 숨은 컬럼 호환성을 보장하는 staging 테이블을 만든다.

사용 시점

DWH/ETL 대량 적재, 오래된 파티션을 아카이브 테이블로 이동, 적재 중 운영 테이블에 영향을 주지 않고 인덱스와 통계를 준비할 때.

주의

Partitioning 옵션(유료 EE)이 필요하다. WITHOUT VALIDATION은 staging 행이 파티션 경계에 맞는지 확인하지 않는다. 잘못된 데이터가 잘못된 파티션에 남아 쿼리가 잘못된 결과를 반환할 수 있으므로 확신이 없으면 WITH VALIDATION(전체 스캔)을 사용한다. UPDATE GLOBAL INDEXES 없이는 전역 인덱스가 UNUSABLE이 된다. unique/PK 제약 조건 상태는 양쪽이 일치해야 한다.

DBAtlas에서 열기 →

관련 항목