2010년 1월 29일 금요일

DB_FILE_MULTIBLOCK_READ_COUNT(MBRC)

출처 :   ( oracleclub.com )   http://wiki.oracleclub.com/display/DBSTUDY/DB_FILE_MULTIBLOCK_READ_COUNT                  

DB_FILE_MULTIBLOCK_READ_COUNT(MBRC)

  • 정의 : Full Table Scan 시에만 영향을 미치는 파라미터.     한번의 I/O 작업으로 읽어들이는 최대 블럭 수. Multi Block I/O 에 관련된 파라미터
  • 값 설정하기
    1. db_block size * db_file_multiblock_read_count <= 오라클의 최대 I/O 크기(64KB)
    2. default value : O/S에 따라서 다름 (Linux redhat itanium : 16)
      일반적으로 db_block_buffers와 Processes에 의해서 결정되며 4~32 정도가 많이 사용됨
    3. FULL TABLE SCAN과 DB_FILE_MULTIBLOCK_READ_COUNT
      FULL TABLE SCAN을 할 때에는 DB_FILE_MULTIBLOCK_READ_COUNT 이 설정된 만큼을 한꺼번에 데이터를 가져옴
      ex) DB_FILE_MULTIBLOCK_READ_COUNT=8 이고 db_block_size가 8k라면 8*8=64k 만큼을 한꺼번에 가져옴

      1. extent의 크기가 작을 경우 : multiblock I/O로 데이터를 읽지 않고 single block I/O를 사용해서 읽음 (I/O의 단위 : Block)
      2. extent안의 블록들이 db_file_multiblock_read_count 보다 작게 되면 db file sequential read(single block I/O시에) 라는 event 발생
      3. MBRC크기보다 큰 extent는 multiblock I/O로 읽다가 extent가 끝나는 부분에 MBRC크기 보다 작은 block이 남아있을 경우에는 single block I/O로 읽음
      4. full scan할 때에는 extent의 크기가 MBRC가 설정된 크기보다 작을 경우에는 single block I/O로 읽게 되므로 성능저하가 될 수 있고, MBRC가 설정된 값에 따라서 optimizer가 full scan or index scan 여부 결정
      5. 단점 : 이 파라미터가 크게 설정되어 있다면 블록을 읽어올 때, 설정된 값만큼 읽어오므로 buffer pool에서 다른 블록들이 flush될 수 있음

    4. INDEX SCAN과 DB_FILE_MULTIBLOCK_READ_COUNT
      1. Index scan시에는 db_block_size의 설정이 중요
      2. B-tree Index 에서 블록 크기가 8KB(db_block_size=8KB) 라면 2KB 인 경우보다 거의 4배 빨리 데이터를 읽음
      3. Index Block 의 Pctfree가 너무 크고 인덱스의 Entry Size 가 늘어나지 않으며 기존의 인덱스 값에 새로운 레코드가 더 이상 추가되지 않을 경우 : 공간의 낭비가 심하게 되므로 적절한 값으로 조정

      4. index range scan 을 위해 index full scan 이나, fast full index 을 피하는 방법
        • index full scan , FFIS 를 선택한 이유 : index 의 LEAFCNT(leaf block count)전체를 읽는 cost < branch level (BLEVEL) 의 cost, 또는 CLUFAC(clustering factor) 의 cost
        • 해결 방법
          • index 의 height 를 줄이기 위해 db_block_size를 늘림
          • ndex reorganization 수행
          • 임시적인 방법 : FFIS 나 full index scan cost 를 높이기 위해 index cost 를 결정하는 파라미터를 조정 (아래 3개의 파라미터 값을 작게 조정)

            fast_full_scan_enabled =false
            db_file_multiblock_read_count
            sort_area_size



  • System Statistics와 DB_FILE_MULTIBLOCK_READ_COUNT
    1. System Statistics가 없는 상황 : db_file_multiblock_read_count, optimizer_index_cost_adj와 같은 파라미터들이 Index Scan과 Table Scan중 어느 것을 선택할지를 결정하는데 큰 역할 함

    2. System Statistics가 정상적으로 수집된 경우 : DB_FILE_MULTIBLOCK_READ_COUNT 파라미터가 Optimizer의 비용 계산에 고려되지 않음.
      1. mbrc는 Optimizer에 의해 실행 계획이 생성될 때는 무시되지만 실제 Fetch과정에서 db_file_multiblock_read_count 크기만큼 Multi Block I/O함
  • 10g R2 MBRC를 대신하는 parameter
    1. _db_file_optimizer_read_count : System Statistics가 없는 경우에 Optimizer가 비용을 계산하기 위해 사용. System Statistics가 수집된 경우에는 이 값은 무시
    2. _db_file_exec_read_count : 쿼리를 실행하는 과정에서 Multi Block I/O를 수행할 때 한번에 읽을 블록 수를 결정. System Statistics의 수집 여부와 무관하게 사용





** 관련자료 :

   

2010년 1월 11일 월요일

linux block trace [blktrace]

block trace 란 리눅스에서 Disk I/O 가 일어날때,
linux 하위 level 에서 어떻게 Block 단위의 I/O 가 일어났는지 알아낼수 있는 Tool
DB 접근에서 주로 DB recovery 나 join 시의 DIsk I/O 패턴을 알아내는데 유용하다.

1. yum install blktrace-1.0.1-3.XX .. 를 인스톨 한다. ( block trace 뜨는 프로그램 )
http://rpm.pbone.net/index.php3/stat/3/srodzaj/1/search/blktrace 


2. seekwatcher 다운로드 ( 생성한 block trace 를 image 로 정리해서 보여줌 )
   - 미리 설치할 package : http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99.1/matplotlib-0.99.1.2.tar.gz/download 
 
   - seekwatcher http://oss.oracle.com/~mason/seekwatcher/seekwatcher-0.12.tar.bz2 

3. seekwatcher 압출을 풀면 seekwatcher 란 실행파일이 생성 됨 이 파일을 /usr/bin 에 복사후 사용

blktrace 실행


1. mkdir /trace
2. blktrace -d /dev/target_device
3. cd /trace 에 device_name.blktrace 파일이 생성 된다.

seekwatcher 실행


seekwatcher  -t trace파일


exception


 

/usr/lib/python2.6/site-packages/matplotlib/rcsetup.py:117: UserWarning: rcParams key "numerix" is obsolete and has no effect;
 please delete it from your matplotlibrc file
  warnings.warn('rcParams key "numerix" is obsolete and has no effect;\n'
   

  cd $HOME
  rm .matplotlib/



[root@ljh8324-skku /]# blktrace -d /dev/sdb1
Invalid debug path /sys/kernel/debug: 0/Success

$ mount -t debugfs debugfs /sys/kernel/debug

 


 








fedora 부트로더 복구


1. fedora cd 를 넣고 F5 ( rescue ) 모드로 진입 ..

2. shell 모드로 진입후 /sbin/grub 실행

3. grub > root (hd0, 1) 부터 해당하는 리눅스 파티션이 나올때 까지 실행 (hd0,1 ~ n )

4. setup (hd0)

5. quit 후 재부팅 ..

2009년 12월 23일 수요일

Automatic PGA Memory Management

What is Automatic PGA Memory Management?
Initialization parameters
SORT_AREA_SIZE and HASH_AREA_SIZE are used to specify the maximum amount of memory for each session in Oracle8i or earlier.
In Oracle9i, the following parameters specify the maximum amount of the PGA memory available to all server processes for every instance.
(
PGA: Program Global Area)

PGA_AGGREGATE_TARGET
Specify the total amount of PGA memory available to instance. You can dynamically change the parameter at instance level. Set the parameter to any value between 10M and 4096G-1 bytes.

WORKAREA_SIZE_POLICY
Specify if the size of the SQL workarea should be tuned automatically or manually.
AUTO: tune automatically
MANUAL: tune manually

When
WORKAREA_SIZE_POLICY is set to MANUAL, the maximum amount of memory is defined by the parameter such as HASH_AREA_SIZE. When WORKAREA_SIZE_POLICY is set to AUTO, the maximum amount of memory is defined automatically and the parameters such as HASH_AREA_SIZE are ignored.
If
PGA_AGGREGATE_TARGET is set, WORKAREA_SIZE_POLICY will be set to AUTO by default.

How to determine
PGA_AGGREGATE_TARGET.
The following formula is used as a guideline.

OLTP systems:
PGA_AGGREGATE_TARGET=(total actual memory*80%)*20%

DSS systems:
PGA_AGGREGATE_TARGET=(total actual memory*80%)*50%

PGA_AGGREGATE_TARGET of DSS systems is determined larger than that of OLTP systems because DSS systems normally access large amount of data by sorting with ORDER BY or GROUP BY.

There three types of SQL workarea executions as follows:
optimal: workarea execution of which all processes such as sort are executed on memory
onepass: workarea execution that requires the minimum writes to a disk
multipass: workarea execution that requires heavy writes to a disk because SQL workarea is too low

The following are standard tuning goal:
workarea execution - optimal >= 90%
workarea execution - multiplass = 0%

Most of the workarea executions are executed in optimal mode to reduce workarea execution - onepass.
The following query enables you to monitor the status of PGA memory in V$STSSTAT.

select name
,value
,100*(value/
decode((select sum(value) from v$sysstat where name like 'workarea
exec%'),0,null,(select sum(value) from v$sysstat where name like 'workarea
exec%'))) pct
from v$sysstat
where name like 'workarea exec%'
/

NAME                             VALUE        PCT
----------------------------------------------------------------------
workarea executions - optimal    1529         100
workarea executions - onepass       0           0
workarea executions - multipass     0           0

If VALUE of workarea execution - multiplass is not 0% or VALUE of workarea executions - onepass exceeds 10%, you need to increase PGA_AGGREGATE_TARGET. If VALUE of workarea executions - optimal is 100%, you may reduce PGA_AGGREGATE_TARGET.



2009년 12월 22일 화요일

10053 trace

on
 alter session set events '10053 trace name context forever';


off
ALTER SESSION SET EVENTS '10053 trace name context OFF';


file ( oracle 11g )
$ORACLE_HOME/diag/rdbms/orcl/trace


2009년 11월 9일 월요일

oracle pivot

LISTAGG : oracle 11g r2 에서 새로 추가된 함수. 기존에 존재 하던
pivot 함수( 또는 복잡한 SQL) 보다 간결하고 간단하게 구현하도록 제공하고 있다.

Syntax :
LISTAGG   ( <expr> [ ,  <delimiter> )   WITHIN  GROUP   ( ORDER BY  <oby_expression_list> )

사용자 삽입 이미지
 

그외에 다른 방법으로 사용 가능한 SQL


1. PL /SQL

 create or replace type t_vc as table of varchar2(4000);
/

create or replace function pivot return t_vc pipelined
as
  v_last_deptno emp.deptno%type := null;
  v_line  varchar2(4000);
begin
  for r in (select deptno , ename from emp order by deptno) loop
    if v_last_deptno is null then
      v_line:=rpad(r.deptno,11) || ': ';
      v_last_deptno := r.deptno;
    end if;
    if r.deptno <> v_last_deptno then
      pipe row(v_line);
      v_line:=rpad(r.deptno,11) || ': ';
      v_last_deptno := r.deptno;
    end if;
    v_line := v_line || rpad(r.ename,11);
  end loop;
  pipe row(v_line);
  return;
end pivot;
/


출력결과

SQL> select * from table(pivot);

COLUMN_VALUE
-----------------------------------------------------------------------------------------------------------------------------------
10    : CLARK KING    MILLER
20    : JONES FORD    ADAMS      SMITH  SCOTT
30    : WARD TURNER    ALLEN      JAMES  BLAKE     MARTIN


2. SQL ( DECODE 사용 )

SELECT   a.deptno
    ,        MAX(DECODE(a.r, 1,a.ename))
             || MAX(DECODE(a.r, 2,', ' || a.ename))
             || MAX(DECODE(a.r, 3,', ' || a.ename))
             || MAX(DECODE(a.r, 4,', ' || a.ename))
             || MAX(DECODE(a.r, 5,', ' || a.ename))
             || MAX(DECODE(a.r, 6,', ' || a.ename))
             || MAX(DECODE(a.r, 7,', ' || a.ename))
             || MAX(DECODE(a.r, 8,', ' || a.ename))
             || MAX(DECODE(a.r, 9,', ' || a.ename))
             || MAX(DECODE(a.r,10,', ' || a.ename)) names
   FROM    (SELECT t.deptno
            ,      t.ename
            ,      ROW_NUMBER()
                   OVER (PARTITION BY t.deptno
                         ORDER BY     NULL) r
            FROM   emp t) a
   GROUP BY a.deptno
   ORDER BY a.deptno
   /

출력결과

    DEPTNO NAMES
---------- ----------------------------------------------------------------------------------------------------------------------
 10 CLARK, KING, MILLER
 20 JONES, FORD, ADAMS, SMITH, SCOTT
 30 WARD, TURNER, ALLEN, JAMES, BLAKE, MARTIN


 3. SQL ( sys_connect_by_path )

select deptno,
 substr( max( sys_connect_by_path( ename, '; ') ), 3 ) names
 from ( select deptno, ename, row_number() over ( partition by deptno order by ename ) rn
   from emp )
 start with rn = 1
 connect by prior deptno = deptno and
   prior rn+1 = rn
 group by deptno
 order by deptno
/

출력결과


     DEPTNO NAMES
---------- ----------------------------------------------------------------------------------------------------
 10 CLARK; KING; MILLER
 20 ADAMS; FORD; JONES; SCOTT; SMITH
 30 ALLEN; BLAKE; JAMES; MARTIN; TURNER; WARD


참고자료 :

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:766825833740