1. 程式人生 > >DB2中storage group的概念,以及建立各種型別的表空間

DB2中storage group的概念,以及建立各種型別的表空間

DB2的表空間根據是否是自動儲存型別的,可以分為兩種,Automatic Storage(AS)和非Automatic Storage,如果是Automatic Storage型別的,建立時不能指定容器的路徑,那麼DB2是怎麼知道它存放的位置的呢?這裡要引申出一個概念:Storage Group, 一個Storage Group定義了一個或者多個路徑,示例如下:

db2 "CREATE STOGROUP storage_group_name ON 'path1', ..., 'pathn'" 

當然,db2已經建立好了一個storage group,叫IBMSTOGROUP,它是預設的storage group,如果建立AS型別的表空間的時候,不指定‘USING STOGROUP',那就會使用IBMSTOGROUP storage group.

下面看一個例項,建立一個數據庫,並自定義一個storage group, 檢視storage group 的資訊:

$ db2 "create db test"

$ db2 "connect to test"

$ db2 "create STOGROUP MQSGROUP ON '/home/db2users/e105q6a/conpath1', '/home/db2users/e105q6a/conpath2'" 

$db2 "SELECT VARCHAR(STORAGE_GROUP_NAME, 30) AS STOGROUP, STORAGE_GROUP_ID, VARCHAR(DB_STORAGE_PATH, 40) AS STORAGE_PATH FROM TABLE(ADMIN_GET_STORAGE_PATHS('',-1)) AS T"

STOGROUP                       STORAGE_GROUP_ID STORAGE_PATH                            
------------------------------ ---------------- ----------------------------------------
IBMSTOGROUP                                   0 /home/db2users/e105q6a                  
MQSGROUP                                      1 /home/db2users/e105q6a/conpath1         
MQSGROUP                                      1 /home/db2users/e105q6a/conpath2         

  3 record(s) selected.

建立各種型別的表空間  
a)AS型別的SMS: $ db2 "create user temporary tablespace usrtmp1 managed by automatic storage"
b)AS型別的DMS: $ db2 "create regular tablespace rglrtbs1 managed by automatic storage USING STOGROUP MQSGROUP"
c)非AS型別的SMS: $ db2 "create tablespace tbs1 managed by system using ('/home/db2users/e105q6a/path1')"
d)非AS型別的DMS: $ db2 "create tablespace tbs2 managed by database using (file 'con2' 4000)"

從下面簡化的輸出中可以看到,建立資料庫時自帶的幾個表空間都是AS型別的,且使用了IBMSTOGROUP。表空間rglrtbs1使用了自定義的storage group.
$ db2pd -db test -tab

Database Member 0 -- Database TEST -- Active -- Up 0 days 00:16:02 -- Date 2017-02-25-10.28.54.331489

Tablespace Configuration:
Address            Id   AS  AR  Type Content  SGID  Name
0x070000005D9687E0 0    Yes Yes DMS  Regular  0     SYSCATSPACE
0x070000005D975980 1    Yes No  SMS  SysTmp   0     TEMPSPACE1
0x070000005D982B20 2    Yes Yes DMS  Large    0     USERSPACE1
0x0700000061E48FC0 3    Yes Yes DMS  Large    0     SYSTOOLSPACE
0x0700000064080200 4    Yes No  SMS  UsrTmp   0     USRTMP1
0x070000006408D3A0 5    Yes Yes DMS  Regular  1     RGLRTBS1
0x070000006409A540 6    No  No  SMS  Regular  -     TBS1
0x07000000640B4960 7    No  No  DMS  Large    -     TBS2

Containers:
Address            TspId  Type   Container 
0x07000000552EFD60 0      File   /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000000/C0000000.CAT
0x070000005D990000 1      Path   /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000001/C0000000.TMP
0x070000005122FAC0 2      File   /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000002/C0000000.LRG
0x0700000061E58000 3      File   /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000003/C0000000.LRG
0x0700000061E1B000 4      Path   /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000004/C0000000.UTM
0x0700000061E22000 5      File   /home/db2users/e105q6a/conpath1/e105q6a/NODE0000/TEST/T0000005/C0000000.USR
0x0700000061E22230 5      File   /home/db2users/e105q6a/conpath2/e105q6a/NODE0000/TEST/T0000005/C0000001.USR
0x0700000061E245C0 6      Path   /home/db2users/e105q6a/path1
0x07000000640C2E80 7      File   /home/db2users/e105q6a/e105q6a/NODE0000/SQL00001/con2

參考資料:
https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.rtn.doc/doc/r0055331.html
https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000929.html