19 Direct-Path INSERT


Introduction to Direct-Path INSERT

오라클은 table에 데이터를 입력하는데 두가지 방식을 사용합니다.


  • 전통적인 insert operation은 table내의 free space를 재사용합니다. 기존의 데이터와 새로 insert 되는 데이터가 같이 저장되며, 참조 constraint도 자동으로 관리합니다.
  • direct-path insert operation은 새로 입력되는 데이터를 기존의 table내에 존재하는 데이터 이후에 저장합니다. buffer cache를 거치지 않고 바로 datafile에 저장되며, table내의 free space를 사용하지 않습니다. 또한 참조 constraint도 무시됩니다. 이러한 일련의 procedure로 인해 performance가 향상됩니다.

이러한 direct-path insert operation은 direct-path insert 구문이나 sql loader의 direct-path option을 이용해 사용될 수 있습니다. 


Advantages of Direct-Path INSERT

Direct-path insert는 다음의 performance 잇점을 갖습니다.


  • direct-path insert 시 redo와 undo entry들의 logging을 disable 할 수 있습니다. 반면 전통적인 insert operation은 free space 사용과 참조무결성을 위해 반드시 이러한 entry들에 대해서 logging을 해야 합니다.
  • 새 로운 데이터가 저장된 테이블을 생성하기 위해서 create table과 insert into를 사용하거나 create table .. as select 구문을 사용할 수 있습니다. create table 과 direct-path insert를 이용해 데이터를 insert 한 경우 기존 테이블에 존재하는 인덱스도 자동으로 변경됩니다. 반면 create table as select 구문을 사용한 경우 insert는 추후 재생성해야 합니다.
  • Direct-path insert는 serial/parallel mode 둘다 transaction이 하나의 단위로 처리된다 (transaction atomicity). 그러나 sql loader의 parallel-patch load의 경우 transaction atomicity를 보장하지 않는다.
  • parallel direct-path load의 경우 에러가 발생하면 index는 load 후 UNUSABLE로 빠질 수 있다. 반면 parallel direct-path INSERT 구문의 경우 index update시 에러가 발생하면 rollback 된다.

Serial and Parallel Direct-Path INSERT

parallel DML mode에서 insert 할 경우 direct-path INSERT가 default 이다. parallel DML mode로 사용하기 위해서 다음의 요구사항이 필요하다.


  • Oracle Enterprise Edition을 사용해야 한다.
  • ALTER SESSION { ENABLE | FORCE } PARALLEL DML; 명령으로 parallel DML 기능을 enable 해야한다. 
  • table 생성시 또는 그 이후 table에 대한 parallel attribute를 지정하거나 insert 구문내에 parallel hint를 지정한다.


direct-path INSERT를 disable 하기 위해 NOAPPEND hint를 insert 구문에 지정해 줘야 한다.

serial mode로 insert 할때 INSERT 구문 뒤에 APPEND hint를 사용하거나 INSERT 구문 내의 subquery의 SELECT 구문 바로 뒤에 APPEND hint를 지정해 줘야 한다.

Direct-Path INSERT Into Partitioned and Nonpartitioned Tables

Direct-path INSERT는 partition/non-partition table 모두 사용가능하다.

Serial Direct-Path INSERT into Partitioned and Nonpartitioned Tables

Single process insert의 경우 table segment나 각 partition segment의 HWM 뒤에 데이터가 insert 된다.

commit이 수행되면 HWM는 새로운 값으로 update 되며 user에게 데이터가 보이게 된다.

Parallel Direct-Path INSERT into Partitioned Tables

Partition table에 대한 parallel direct-path insert는 serial direct-path insert와 유사하다.

각각의 parallel execution server는 하나 또는 여러 partition에 할당된다. 하나의 partition에 대해 한개 이상의 parallel execution server process가 할당되진 않는다.

(Each parallel execution server is assigned one or more partitions, with no more than one process working on a single partition.)

각 parallel execution server는 할당된 partition segment의 HWM 이후에 데이터를 insert 한다.

commit이 수행되면 HWM는 update 되며 새로운 데이터는 user에게 보이게 된다.

Parallel Direct-Path INSERT into Nonpartitioned Tables

Non-partition table에 대한 parallel direct-path insert는 각각의 parallel execution server가 temporary segment를 만들며 이 temporary segment에 데이터를 insert 한다.

commit이 수행되면 parallel execution coordinator가 temporary segment를 table segment로 merge 한다.

Direct-Path INSERT and Logging Mode

Direct-path INSERT는 redo entry와 undo entry를 logging 할지를 선택 할 수 있다.


  • table, partition, index, LOB storage에 대해 생성시나 추후 logging mode를 설정할 수 있다. 
  • 만약 LOGGING이나 NOLOGGING을 설정하지 않았다면..
    • partition 의 경우 해당 table의 logging attribute를 따른다.
    • table이나 index의 경우 tablespace의 logging attribute를 따른다.
    • LOB storage의 경우 만약 CACHE option으로 정의 된 경우 LOGGING이 default attribute로 설정된다. 만약 CACHE option이 지정되지 않은 경우 해당 tablespace의 logging attribute를 따른다.
  • CREATE TABLESPACEALTER TABLESPACE 명령으로 logging attribute를 지정할수 있다.


Direct-Path INSERT with Logging

logging mode에서 direct-path insert가 수행될 경우 oracle은 full redo logging을 수행한다.


Direct-Path INSERT without Logging

NOLOGGING 으로 Direct-path insert 할 경우 oracle은 redo entry와 undo retry를 logging 하지 않습니다.

그러나 새로운 extent를 invalid로 marking하기 위한 최소한은 log와 data dictionary 변경에 대한 내용은 logging 합니다.

NOLOGGING은 performance를 증가시키지만 media recovery가 필요한 경우 redo 정보가 없기때문에 변경된 데이터에 대해 logical corruption을 발생하게 됩니다. 

따라서 NOLOGGING mode에서 direct-insert 한 경우 반드시 backup이 필요합니다.


Additional Considerations for Direct-Path INSERT

Index Maintenance with Direct-Path INSERT

오라클은 direct-patch INSERT 이후 table의 index에 대한 변경 사항을 적용합니다.

parallel direct-path INSERT의 경우 parallel execution server에 의해, serial direct-path INSERT의 경우 single process에 의해 수행됩니다.

Index 관리에 따른 performance 저하를 피하기 위해 insert 수행 전 index를 drop하고 rebuild 할 수 있습니다.

Space Considerations with Direct-Path INSERT

direct-patch INSERT의 경우 table의 free-list내의 공간을 사용하지 않기때문에 기존의 INSERT 방식에 비해 많은 공간을 요구하게 된다. 

serial direct-path INSERT와 partition table에 대한 parallel direct-path INSERT의 경우 해당 segment의 HWM 이후에 데이터를 저장하게 됩니다. 

이로 인해 추가적인 공간이 더 필요하게 된다. 


non-partition table에 대한 parallel direct-path INSERT의 경우 각각의 parallel degree 만큼의 temporary segment가 생성되어 추가적인 공간이 더 필요하다.

만약 non-partition table이 locally managed tablespace내에 automatic mode로 생성되지 않았다면 NEXT, PCTINCREASE, MININUM EXTENT 등의 storage parameter를

적정한 수치로 지정해 주어야 한다.


  • 각각의 extent size가 너무 작을 경우 object의 extent 갯수에 영향을 미친다.
  • parallel insert 결과가 segment내의 공간을 낭비하지 않도록 적당한 extent size를 갖어야 한다.


direct-path insert 이후 이들 storage parameter를 serial operation에 맞도록 다시 설정한다.

Locking Considerations with Direct-Path INSERT

direct-path INESRT 시 해당 table에 대한 exclusive lock이 요구된다. 따라서 다른 user들은 해당 table에 대해 insert, update, delete, index create/build operation이 제한된다. 

데이터에 대한 query는 지원되며 direct-insert 이전의 데이터만 보여진다.




'Oracle Database' 카테고리의 다른 글

Listener 접속 단계 및 성능 측정  (0) 2009.07.07
Oracle's Dev2DBA newsletter - 2009/07  (0) 2009.07.07
sequence cache & pining  (0) 2009.06.30
오라클의 에러  (0) 2009.06.25
Cluster I/O Fencing – exclusion strategy  (0) 2009.06.23

+ Recent posts