메뉴 건너뛰기

bysql.net

5. Direct Path I/O

2010.07.10 23:40

balto 조회 수:12189


- 블록 I/O는 DB 버퍼캐시를 경유하여 기 적재 여부를 확인한 다음 I/O를 한다. 재사용 가능성이 없는 임시 세그먼트 블록같은 경우 버퍼캐시를 경유하지 않는 것이 더 유리한데, 이같이 버퍼캐시를 경유하지 않고 곧 바로 데이터 블록을 읽고쓰는 방법이 Direct Path I/O이다.

- Direct Path I/O를 사용하는 경우

 Temp 세그먼트 블록들을 읽고 쓸때

 병렬쿼리로 Full Scan을 수행할 때

 nocache 옵션을 지장한 LOB 컬럼을 읽을 때

 direct 옵션을 지정하고 export를 수행할 때

 parallel DML을 수행할 때

 Direc Path Insert를 수행할 때


Direct Path Read/Write Temp

- 데이터를 정렬할 때 PGA 메모리에 할당되는 Sort Area를 이용한다. Sort Area가 부족해지면 Temp 테이블 스페이스를 사용하는데, Direct Path I/O를 사용한다. direct path write temp / direct path read temp 이벤트로 측정된다.

fig6-6.jpg 



create table t as select * from all_objects;

 

alter session set workarea_size_policy=manual;

alter session set sort_area_size=524299;

 

********************************************************************************

select *

from (select a.*, rownum no from (select * from t order by object_name) a )

where  no < 10

 

call     count       cpu    elapsed       disk      query    current        rows

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

Parse        1      0.00       0.00          0          3          0           0

Execute      1      0.00       0.00          0          0          0           0

Fetch        2      0.17       0.21       1036        696         14           9

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

total        4      0.17       0.22       1036        699         14           9

 

Misses in library cache during parse: 1

Optimizer mode: ALL_ROWS

Parsing user id: 5 

 

Rows     Row Source Operation

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

      9  VIEW  (cr=696 pr=1036 pw=704 time=111423 us)

  50262   COUNT  (cr=696 pr=1036 pw=704 time=312458 us)

  50262    VIEW  (cr=696 pr=1036 pw=704 time=211931 us)

  50262     SORT ORDER BY (cr=696 pr=1036 pw=704 time=161664 us)

  50262      TABLE ACCESS FULL T (cr=696 pr=332 pw=0 time=53728 us)

 

 

Elapsed times include waiting on following events:

  Event waited on                             Times   Max. Wait  Total Waited

  ----------------------------------------   Waited  ----------  ------------

  SQL*Net message to client                       2        0.00          0.00

  db file scattered read                         44        0.00          0.01

  db file sequential read                         5        0.00          0.00

  direct path write temp                        298        0.00          0.00

  direct path read temp                         473        0.00          0.03

  SQL*Net message from client                     2        0.04          0.04

********************************************************************************



Direct Path Read

- 병렬쿼리로 Full Scan할 경우 사용가능, 병렬도(DOP)를 2로 주고 병렬쿼리를 실행하면 수행속도가 2배 이상 빨라지는 이유이다. direct path read 이벤트가 발생한다.

- 버퍼캐시에 내용이 기록되지 않은 상태에서 병렬로 Direct Path Read를 실행하면 Dirty Read가 생기므로 메모리와 디스크간 동기화를 한다음 실행한다. 10gR2부터는 필요한 세그먼트만 동기화를 하고 실행한다.


Direct Path Write

- 병렬 DML을 실행하거나, Direct Path Insert 방식으로 insert할 때 사용한다. direct path write 이벤트가 발생한다.

- Direct Path Insert 방식으로 insert 하는 방법

 insert ... select 문장에 /*+append*/ 힌트 사용

 병렬모드로 insert

 direct 옵션을 지정하고 SQL*Loader(sqlldr)로 데이터를 로드

 CTAS(create table ... as select) 문장을 실행

- Direct Path Insert 방식으로 insert 하는 알고리즘

 테이블 세그먼트나 각 파티션 세그먼트의 HWM(high water mark) 바깥 아무도 읽지 않는

 영역에  순차적으로 입력하므로 UNDO 발생도 최소

- 기능 활성화 방법(일반 insert 문을 logging 하지 않는 방법은 없다.)

alter table t nologging; (이 방법으로 테이블을 nologging 시킨다.)

insert into t nologging select * from test; (nologging은 테이블 t의 별칭일 뿐 nologging 기능과는 무관)

- Direct Path Insert 방식은 Exclusive 모드 테이블 Lock이 걸린다.

  (일반 DML은 Row Exclusive 모드 테이블 Lock을 사용하므로 다른 트랜잭션 DML은 막지 않는다.)

 alter session enable parallel dml;

 delete /*+parallel(b 4) */ from big_table b; -> Exclusive 모드 TM lock