728x90

index page 최대 개수에 대해 조사하다보니 extent 할당에 대해서도 우연히 문서를 읽게 되었습니다.

IBM Knowledge Center에 따르면 11.70.xC1 버전부터 partition header pages의 공간이 부족해지면 secondary header pages가 자동으로 할당된다고 합니다.

https://www.ibm.com/support/knowledgecenter/SSGU8G_11.70.0/com.ibm.perf.doc/ids_prf_309.htm

If you have a table that needs more extents and the database server runs out of space on the
partition header page, the database server automatically allocates extended secondary partition
header pages to accommodate new extent entries.
The database server can allocate up to 32767 extents for any partition, unless the size of a table
dictates a limit to the number of extents.

따라서 11.70 버전부터 extent가 최대 32,767개 까지 할당됩니다. 관리할 점은 줄었네요.

그렇지만 성능을 고려한다면 개수를 적게 유지하는 것이 좋겠죠.

 

아래와 같이 데이터를 대량으로 입력해서 extent 개수를 많이 늘려보았습니다.

일반적으로는 EXTENT DOUBLING 규칙에 의해 extent 크기가 2배씩 커지지만 작은 페이지 크기로 일정하게 할당되도록 NO_EXTENT_DOUBLING 옵션을 활성화 했습니다.

참고로 NO_EXTENT_DOUBLING 옵션은 11.70.xC9부터 사용가능합니다.

drop table "informix".log_01;
create table "informix".log_01
  (
    col1 varchar(50),
    col2 varchar(32),
    col3 varchar(5),
    col4 varchar(5),
    col5 varchar(10)
  ) in dbs1 extent size 16 next size 16 lock mode page;
  ...

아래의 SQL문장으로 1천만건의 레코드를 입력합니다.

$ nohup dbaccess -e demo /informix/skjeong/insert1.sql > /informix/skjeong/insert1.log 2>&1 &
$ cat insert1.sql
insert into log_01
select 'dolore eu fugiat nulla pariatur. Excepteur sint oc',
       '180e70d7-8684-4674-8d42-3c1e5f3b',
       'labor',
       'eiusm',
       level
from sysmaster:sysdual
connect by level <= 10000000;

데이터 입력중에 oncheck 명령으로 테이블의 extent 수를 확인해보았습니다.

와우! 2356개입니다. EXTENT DOUBLING이 되고 한계가 3만2천개라면 거의 제한이 없는 것으로 봐도 되겠지요.

TBLspace Report for demo:informix.log_01
    Physical Address               2:5
    Creation date                  02/17/2020 13:23:41
    TBLspace Flags                 901        Page Locking
                                              TBLspace contains VARCHARS
                                              TBLspace use 4 bit bit-maps
    Maximum row size               107
    Number of special columns      5
    Number of keys                 0
    Number of extents              2356
    Current serial value           1
    Current SERIAL8 value          1
    Current BIGSERIAL value        1
    Current REFID value            1
    Pagesize (k)                   2
    First extent size              8
    Next extent size               128
    Number of pages allocated      301056
    Number of pages used           301056
    Number of data pages           300981
    Number of rows                 5422921
    Partition partnum              2097154
    Partition lockid               2097154
    Extents
         Logical Page     Physical Page        Size Physical Pages
                    0         6:5000427           8          8
                    8         6:5000483           8          8
                   16         6:5000611          16         16
                   32         6:5000851          32         32
                   64         6:5001395          64         64
                  128         6:5002675         128        128
                  256         6:5004083         128        128
                  384         6:5005363         128        128
                  512         6:5006515         128        128
                  ...
728x90
728x90

Question

This document explains what a tblspace-tblspace (also referred as tablespace-tablespace and partition-partition) is and how it relates to other tables in an instance.

Answer

What is TBLspace TBLspace?

You are running IBM® Informix® Dynamic Server (IDS) database server and create a regular Dbspace. This Dbspace contains an internal table called TBLspace TBLspace. You cannot access the table using SQL commands.

What it does?

The TBLspace TBLspace table tracks all the partitions (tables or indexes) that you create in a Dbspace, including itself. You can track every table, detached index, or table fragment in the TBLspace TBLspace table through a partition page. The first partition page contains information about the TBLspace TBLspace table itself and the following partition pages track other tables. The partition page contains important information about a table and you can see part the data using theoncheck -pt command (oncheck  -pt database:table):


    oncheck   -pt database : table 

      database
        name of the database 
      table
        name of the table 

When you create a TBLspace TBLspace table, it has an initial extent of 50 pages on version 7.x and 250 pages on 9.x. In addition, when the first extent gets full, a new extent is allocated in one of the chunks of the Dbspace. This may cause a problem because if you create a new extent of the TBLspace TBLspace table on a chunk that needs to be dropped the server will report an error saying that the chunk is not empty. This will happen even if there is no user data in it. 
Even though the TBLspace TBLspace is not accessible through SQL you can still see the extents that are allocated in the chunks of the Dbspace using theoncheck -pe command. 

    Example: 

    The following is a partial output of an  oncheck -pe run on an IDS 7.x system. It is the first extent (50 pages) of the TBLspace TBLspace in chunk 2:

      DBspace Usage Report: dbs1        Ownner: informix  Created: 10/11/2003 

      Chunk: 2 /informix/dbs1_chunk1 Size Used  Free 
                                      5000   53  4947 

      Disk usage for Chunk 2      Start  Length 

      ------------------------------------------- 
       OTHER RESERVED Pages         0      2 
       CHUNK FREE LIST PAGE         2      1 
        TBLSPACE TBLSPACE             3      50 
       FREE                        53     4947 

      Chunk: 3 /informix/dbs1_chunk2 Size Used Free 
                                      5000   3  4997 
      Disk usage for Chunk 3        Start   Length 
      -------------------------------------------- 
         OTHER RESERVED Pages         0      2 
         CHUNK FREE LIST PAGE         2      1 
         FREE  


728x90
728x90

Since IDS Version 10.00 dbspaces can be created with other than the default 2k/4k pagesize.


This feature has multiple benefits:

less disk I/O with larger pagesizes (8k ... 16k)

more rows per data/index page (max. 255 Rows / data page)

higher upper limit of rows per table (max. 16777216 pages / table fragment)

higher upper limit of table/index extents

reduce "-136 ISAM error: no more extents." Errors



Example (stores_demo database):

 


IDS 7.31, 9.40, 10.00, 11.50 / 2k dbspace pagesize:

database_name   stores_demo


tabname         customer

dbspace_name    root_dbs

extents_act     140

max_extents     232

 




IDS 10.00, 11.50 / 16k dbspace pagesize:

database_name   stores_demo

tabname         customer

dbspace_name    dat_dbs16k_001

extents_act     351

max_extents     2023

 

 


You can use the following select to show the upper limit of table/index extent sizes:


 

SELECT --+ORDERED,INDEX(a,systabs_pnix),INDEX(b,sysptnhdridx),INDEX(c,syspaghdridx),INDEX(d,sysdbstab_dbsnum)

       a.dbsname AS database_name,

       a.tabname,

       d.name AS dbspace_name,

       b.nextns AS extents_act,

       TRUNC(c.pg_frcnt / 8) + b.nextns AS max_extents

 FROM sysmaster:sysdbstab d,

      sysmaster:syspaghdr c,

      sysmaster:systabnames a,

      sysmaster:sysptnhdr b

  WHERE c.pg_partnum = sysmaster:partaddr(d.dbsnum, 1)

    AND sysmaster:bitval(c.pg_flags, 2) = 1

    AND c.pg_nslots = 5

    AND a.partnum = sysmaster:partaddr(d.dbsnum, c.pg_pagenum)

    AND a.partnum = b.partnum;



https://www.ibm.com/developerworks/community/blogs/informix_admins_blog/entry/ids_pagesize_and_maximum_number_of_extents5?lang=en

http://www-304.ibm.com/support/knowledgecenter/api/content/nl/ko/SSGU8G_11.50.0/com.ibm.perf.doc/ids_prf_311.htm

http://www-304.ibm.com/support/knowledgecenter/api/content/nl/ko/SSGU8G_11.50.0/com.ibm.perf.doc/ids_prf_316.htm

728x90
728x90

LMT(Locally Managed Tablespace)사용하기



작성일: 2002-11-11
작성자: 강명규(kang@dbakorea.pe.kr)
OS: Linux 2.4.19
Oralce: Oracle EE 8.1.7

미리 말하자면, 당신의 오라클서버가 이 기능을 지원한다면 무조건 이 기능을 사용하라.

오라클은 tablespace, extent, data block 이라는 관점에서 공간할당(Space Allocation)을 관리한다.
간단히 data block < extent < tablespace 라고 생각하면 되겠다.
data block은 보통 몇개의 OS블럭으로 구성되는 DB의 기본 I/O단위가 된다.
extent는 또 몇개의 오라클 data block으로 구성된다.
보통 테이블등의 오브젝트는 이 extent단위로 할당을 받아 segment를 이루게 된다.
tablespace는 이 모든 것들을 포함하는 컨테이너로서의 역활을 수행한다.


Dictionary managed tablespaces
별다른 조치를 하지 않았다면 테이블스페이스의 공간할당에 대한 관리는
다른 오브젝트와 동일하게 Data Dictionary가 한다.
오라클 8.0.x이전 버전의 경우, 이것만이 가용한 방식이다.


Locally Managed Tablespaces (LMT)
하지만 8.1.x이후부터는 '테이블스페이스에 의한 extent관리'라고 불리는 공간할당관리옵션을 사용할 수 있다.
테이블스페이스에 대한 extent allocation 관리를 해당 테이블스페이스 자신이 스스로 할 수 있다는 것이다.
즉, 성능병목현상을 유발할 수 있는 Data Dictionary에 의한 관리로부터 벗어날 수 있다는 것이다.
이러한 테이블스페이스는 자신이 소유한 각 데이터파일에 대한 블럭의 사용유무를 추적하기 위해 '비트맵'을 유지한다.
비트맵내의 각 비트(bit)는 블럭 혹은 블럭들의 그룹에 해당한다.


LMT의 장점
1. temporary tablespace에 적합하게 사용될 수 있다.
2. 주기적인 tablespace의 coalesce가 불필요하다.
   (tablespace의 coalesce를 모른다면 자신이 DBA인가 의심하십시오)
3. 모든 extent는 균등한 크기를 갖게 하며, 테이블스페이스레벨에서 이를 강제하여
   사용자의 잘못된 extent크기지정의 위험을 피할 수 있다.

주의점
1. temporary tablespace에는 UNIFORM extent allocation만 가능
2. NEXT, PCTINCREASE, MINEXTENTS, MAXEXTENTS, and DEFAULT STORAGE 저장옵션은 유효하지 않다.


EXTENT할당 방식
오라클이 새로운 extent를 할당할 수 있는 자유공간을 찾는 방식은 다음과 같다.
해당 테이블스페이스가 소유한 데이터파일들중 한 놈을 선택, 그 데이터파일의 '비트맵'을 검색하여
요구되는 개수의 인접 자유블럭(adjacent free block)을 가진 놈을 찾는다.
만일, 데이터파일이 충분한 인접자유공간을 가지고 있지 못한다면, 또다른 놈을 검색할 것이다.
extent가 할당해제될때, 오라클은 해당 데이터파일의 비트맵을 수정한다.




EXTENT할당(Extent Allocation)방식에는 2가지가 있다.

Automatic Extent Allocation
사용자는 초기 extent크기만을 결정하고, 이후의 추가적인 extent는 오라클이 결정한다.
(이때, extent크기는 64KB, 1MB, 8MB, 64MB 순으로 사용될 것이다. )

SQL> create tablespace ts_dbakorea_lmt_auto
  2  datafile '/u01/app/oracle/oradata/db/ts_dbakorea_lmt_auto01.dbf' size 10m
  3  extent management local autoallocate;  

Tablespace created.

SQL>

Uniform Extent Allocation
생성될 extent크기를 사용자가 정할 수 있다.(default: 1MB)
이후, 생성되는 모든 extent는 초기에 정한 이 extent의 크기를 가지게 된다.
따라서, 이 테이블스페이스내에서 생성되는 테이블, 인덱스등은 모두 같은(균등한) extent크기를 가지게 될 것이다.
당연히 tablespace의 fragmetation은 발생하지 않으므로, coalesce과정이 필요없다.

SQL> create tablespace ts_dbakorea_lmt_uni
  2  datafile '/u01/app/oracle/oradata/db/ts_dbakorea_lmt_uni01.dbf' size 10m
  3  extent management local uniform size 1m;

Tablespace created.

SQL>


자, 그럼 dba_tablespaces에 질의하여 tablespace의 정보를 확인해 보자.
당연히, TS_DBAKOREA_LMT_UNI, TS_DBAKOREA_LMT_AUTO는 extent_management가 local로 되어 있다.
allocation_type은 uniform의 경우 UNIFORM으로, AUTOALLOCATE의 경우 SYSTEM으로 되어 있음을 알수 있다.
특의하게 TS_DBAKOREA_LMT_AUTO의 경우 NEXT_EXTENT가 정해져 있지 않음을 유의하자.

SQL> select tablespace_name, initial_extent, next_extent, min_extents, max_extents,
  2  pct_increase, extent_management, allocation_type
  3  from dba_tablespaces;

TABLESPACE_NAME      INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE EXTENT_MAN ALLOCATIO
-------------------- -------------- ----------- ----------- ----------- ------------ ---------- ---------
SYSTEM                        65536       65536           1  2147483645           50 DICTIONARY USER
RBS                          524288      524288           8        4096           50 DICTIONARY USER
TOOLS                         32768       32768           1        4096            0 DICTIONARY USER
TEMP                          65536       65536           1                        0 DICTIONARY USER
USERS                        131072      131072           1        4096            0 DICTIONARY USER
INDX                         131072      131072           1        4096            0 DICTIONARY USER
TS_DBAKOREA_LMT_UNI         1048576     1048576           1  2147483645            0 LOCAL      UNIFORM
TS_TEST                       20480       20480           1         249           50 DICTIONARY USER
TS_CORRUPT_TEST               20480       20480           1         249           50 DICTIONARY USER
TS_TEMP                       20480       20480           1         249           50 DICTIONARY USER
TS_DBAKOREA_LMT_AUTO          65536                       1  2147483645              LOCAL      SYSTEM

11 rows selected.

SQL>

AUTOALLOCATE의 경우, 처음 테이블의 크기(처음 EXTENT의 크기)는 64KB부터 시작한다.
테이블의 크기가 1MB가 될때까지 EXTENT는 64KB단위로 증가하고, 1MB가 된 이후부터는
EXTENT의 크기가 1MB단위로 증가하게 된다. 이후부터는 약간 다른데 64MB가 되었을때 8MB,
1GB가 되었을때 64MB단위로 EXTENT가 증가하게 된다. 따라서 위의 질의에서 NEXT_EXTENT가
명확히 보이지 않는 것이다.

LMT의 경우에서, EXTENT의 크기는 테이블스페이스 레벨에서만 관리되어 진다.
즉, LMT내의 테이블등의 오브젝트는 모두 테이블스페이스의 저장옵션을 따라 정해진다.





temporary tablespace를 locally managed로 변환하기

SQL> drop tablespace temp;

Tablespace dropped.

SQL> create temporary tablespace temp
  2  tempfile '/u01/app/oracle/oradata/db/ts_temp_lmt_uni01.dbf' size 10m
  3  extent management local uniform size 2m;

Tablespace created.

SQL> select tablespace_name, initial_extent, next_extent, min_extents, max_extents,
  2  pct_increase, extent_management, allocation_type
  3  from dba_tablespaces;

TABLESPACE_NAME                INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE EXTENT_MAN ALLOCATIO
------------------------------ -------------- ----------- ----------- ----------- ------------ ---------- ---------
SYSTEM                                  65536       65536           1  2147483645           50 DICTIONARY USER
RBS                                    524288      524288           8        4096           50 DICTIONARY USER
TOOLS                                   32768       32768           1        4096            0 DICTIONARY USER
TEMP                                  2097152     2097152           1                        0 LOCAL      UNIFORM
USERS                                  131072      131072           1        4096            0 DICTIONARY USER
INDX                                   131072      131072           1        4096            0 DICTIONARY USER
TS_DBAKOREA_LMT_UNI                   1048576     1048576           1  2147483645            0 LOCAL      UNIFORM
TS_TEST                                 20480       20480           1         249           50 DICTIONARY USER
TS_CORRUPT_TEST                         20480       20480           1         249           50 DICTIONARY USER
TS_DBAKOREA_LMT_AUTO                    65536                       1  2147483645              LOCAL      SYSTEM

10 rows selected.

이렇게 생성된 temporary tablespace는 v$datafile이 아닌 v$tempfile에서만 보여진다.

SQL> select name from v$datafile;

NAME
----------------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/db/system01.dbf
/u01/app/oracle/oradata/db/rbs01.dbf
/u01/app/oracle/oradata/db/tools01.dbf
/u01/app/oracle/oradata/db/users01.dbf
/u01/app/oracle/oradata/db/indx01.dbf
/u01/app/oracle/oradata/db/ts_corrupt_test01.dbf
/u01/app/oracle/oradata/db/ts_test01.dbf
/u01/app/oracle/oradata/db/ts_dbakorea_lmt_uni01.dbf
/u01/app/oracle/oradata/db/ts_dbakorea_lmt_auto01.dbf

9 rows selected.

SQL> select name from v$tempfile;

NAME
----------------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/db/ts_temp_lmt_uni01.dbf

SQL>


더 많은 내용을 원한다면 dba_free_space, dba_extents뷰도 확인해보면 좋을 것이다.

이제 dictionary managed tablespace를 locally managed tablespace로 변경해 보겠다.
상호간의 변경은 8.1.6이상에서만 가능하므로 주의하기 바란다. 현재 필자는 8.1.7에서 테스트했다.
8.1.5는 locally managed tablespace -> dictionary managed tablespace 로의 변환만이 가능하다고 한다.

locally managed tablespace -> dictionary managed tablespace : DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_FROM_LOCAL
dictionary managed tablespace -> locally managed tablespace : DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL

temporary와 system tablespace는 locally managed 에서 dictionary-managed로 변환이 불가능하다.
SYSTEM의 경우, 새로 DATABASE를 생성할때 할 수 밖에.. 다른 방법이 있으려나?
오라클사는 locally managed tablespace를 사용하기를 권장하고 있므로 지금부터 바꿔보는 것은 어떨까?


SQL> select tablespace_name, extent_management, allocation_type
  2  from dba_tablespaces;

TABLESPACE_NAME                EXTENT_MAN ALLOCATIO
------------------------------ ---------- ---------
SYSTEM                         DICTIONARY USER
RBS                            DICTIONARY USER
TOOLS                          DICTIONARY USER
TEMP                           LOCAL      UNIFORM
USERS                          DICTIONARY USER
INDX                           DICTIONARY USER
TS_DBAKOREA_LMT_UNI            LOCAL      UNIFORM
TS_TEST                        DICTIONARY USER
TS_CORRUPT_TEST                DICTIONARY USER
TS_DBAKOREA_LMT_AUTO           LOCAL      SYSTEM

10 rows selected.

SQL> exec dbms_space_admin.tablespace_migrate_to_local('TOOLS');

PL/SQL procedure successfully completed.

SQL> exec dbms_space_admin.tablespace_migrate_to_local('RBS');

PL/SQL procedure successfully completed.

SQL> exec dbms_space_admin.tablespace_migrate_to_local('USERS');

PL/SQL procedure successfully completed.

SQL> exec dbms_space_admin.tablespace_migrate_to_local('INDX');

PL/SQL procedure successfully completed.

SQL> exec dbms_space_admin.tablespace_migrate_to_local('TS_TEST');

PL/SQL procedure successfully completed.

SQL> exec dbms_space_admin.tablespace_migrate_to_local('TS_CORRUPT_TEST');

PL/SQL procedure successfully completed.

SQL> select tablespace_name, extent_management, allocation_type
  2  from dba_tablespaces;

TABLESPACE_NAME                EXTENT_MAN ALLOCATIO
------------------------------ ---------- ---------
SYSTEM                         DICTIONARY USER
RBS                            LOCAL      USER
TOOLS                          LOCAL      USER
TEMP                           LOCAL      UNIFORM
USERS                          LOCAL      USER
INDX                           LOCAL      USER
TS_DBAKOREA_LMT_UNI            LOCAL      UNIFORM
TS_TEST                        LOCAL      USER
TS_CORRUPT_TEST                LOCAL      USER
TS_DBAKOREA_LMT_AUTO           LOCAL      SYSTEM

10 rows selected.

SQL> select tablespace_name, initial_extent, next_extent, min_extents, max_extents,
  2  pct_increase, extent_management, allocation_type
  3  from dba_tablespaces;

TABLESPACE_NAME                INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE EXTENT_MAN ALLOCATIO
------------------------------ -------------- ----------- ----------- ----------- ------------ ---------- ---------
SYSTEM                                  65536       65536           1  2147483645           50 DICTIONARY USER
RBS                                    524288      524288           8        4096           50 LOCAL      USER
TOOLS                                   32768       32768           1        4096            0 LOCAL      USER
TEMP                                  2097152     2097152           1                        0 LOCAL      UNIFORM
USERS                                  131072      131072           1        4096            0 LOCAL      USER
INDX                                   131072      131072           1        4096            0 LOCAL      USER
TS_DBAKOREA_LMT_UNI                   1048576     1048576           1  2147483645            0 LOCAL      UNIFORM
TS_TEST                                 20480       20480           1         249           50 LOCAL      USER
TS_CORRUPT_TEST                         20480       20480           1         249           50 LOCAL      USER
TS_DBAKOREA_LMT_AUTO                    65536                       1  2147483645              LOCAL      SYSTEM

10 rows selected.

SQL>

728x90

+ Recent posts