存在多个系统临时表空间时,DB2如何选择?

来源:互联网 发布:putty上传文件到linux 编辑:程序博客网 时间:2024/05/17 15:40
问题:DB2中如果有多个系统临时表空间,那么到底会用到哪一个呢?


解答:
信息中心提到的关于临时表空间的选择顺序如下,并没有提到32K的表空间一定会优先使用32K的系统临时表空间,只是说优化器会进行选择,但也没有提供更详细的信息,DB2优化器会优先选择缓冲池大的:

如果数据库使用多个临时表空间,并且需要新的临时对象,那么优化器将为此对象选择相应的页大小。然后将把该对象分配到具有相应页大小的临时表空间中。如果存在多个临时表空间具有该页大小,那么将以循环方式选择表空间。在大多数情况下,建议对于任何一个页大小,不要使用多个临时表空间。 

https://www.ibm.com/support/knowledgecenter/zh/SSEPGG_9.5.0/com.ibm.db2.luw.admin.dbobj.doc/doc/c0052067.html

In general, when temporary table spaces of different page sizes exist, the optimizer will choose the temporary table space whose buffer pool can hold the most number of rows(in most cases that means the largest buffer pool).  

https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.dbobj.doc/doc/c0004975.html


如果您希望数据库使用指定的临时表空间,可以只保留指定的临时表空间,将系统自己创建的临时表空间删掉。

我下面做了一个测试,测试表明,在32K永久表空间里的表进行排序时,在存在32K系统临时表空间的情况下,也可能用到4K的系统临时表空间,而非32K的:

1. 排序相关内存调小,确保会用到临时表空间

db2 get dbm cfg | find /i "SHEAPTHRES" Sort heap threshold (4KB)                  (SHEAPTHRES) = 250db2 get db cfg for sample | find /i "sort" Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = 250 Sort list heap (4KB)                         (SORTHEAP) = 16

2. 创建两个系统临时表空间,一个4K的,一个32K的,其中前者的缓冲池较大,并删除系统自带的临时表空间。最后创建一个32K的永久表空间。

db2 "connect to sample"db2 "create bufferpool buf4k IMMEDIATE size 10000 automatic pagesize 4 k"db2 "create bufferpool buf32k IMMEDIATE size 100 automatic pagesize 32 k" db2 "create system temporary tablespace mysystmp4k pagesize 4 k managed by database using (file 'contmp1' 200) bufferpool buf4k"db2 "create system temporary tablespace mysystmp32k pagesize 32 k managed by database using (file 'contmp2' 200) bufferpool buf32k"db2 "drop tablespace TEMPSPACE1"db2 "create tablespace tbs32k pagesize 32 k managed by system using ('c:\contmppah') bufferpool buf32k"


3. 在32K的表空间里创建一张表,并导入数据,这里我导入了几十万条数据,也是为了确保用到临时表空间

db2 "create table t3(id int, name char(20)) in tbs32k"db2 "load from t3.del of del insert into t3 nonrecoverable"db2 "select * from t3 order by name"ID          NAME----------- --------------------SQL0289N  Unable to allocate new pages in table space "MYSYSTMP4K".SQLSTATE=57011

可以看到,虽然T3是在32K页大小的表空间中,但排序时用的却是4K的系统临时表空间,同时可以在诊断日志中看到如下报错:

2017-06-07-10.24.37.406000+480 E3506705F1169        LEVEL: Error
PID     : 10400                TID : 11740          PROC : db2syscs.exe
INSTANCE: DB2INST1             NODE : 000           DB   : SAMPLE
APPHDL  : 0-510                APPID: *LOCAL.DB2INST1.170607020154
AUTHID  : MIAOQINGSONG         HOSTNAME: ADMINIB-PR7US3I
EDUID   : 11740                EDUNAME: db2agent (SAMPLE)
FUNCTION: DB2 UDB, buffer pool services, sqlbAllocateExtent, probe:996
MESSAGE : ADM6044E  The DMS table space "MYSYSTMP4K" (ID "4") is full.  If this
          is an autoresize or automatic storage DMS tablespace, the maximum
          table space size may have been reached or the existing containers or
          storage paths cannot grow any more. Additional space can be added to
          the table space by either adding new containers or extending existing
          ones using the ALTER TABLESPACE SQL statement. If this is an
          autoresize or automatic storage DMS table space, additional space can
          be added by adding containers to an autoresize table space or by
          adding new storage paths to the storage group it is using.

2017-06-07-10.24.37.437000+480 I3507876F1278        LEVEL: Warning
PID     : 10400                TID : 11740          PROC : db2syscs.exe
INSTANCE: DB2INST1             NODE : 000           DB   : SAMPLE
APPHDL  : 0-510                APPID: *LOCAL.DB2INST1.170607020154
AUTHID  : MIAOQINGSONG         HOSTNAME: ADMINIB-PR7US3I
EDUID   : 11740                EDUNAME: db2agent (SAMPLE)
FUNCTION: DB2 UDB, buffer pool services, sqlbObtainDataExtent, probe:800
MESSAGE : ZRC=0x85020021=-2063466463=SQLB_END_OF_CONTAINER
          "DMS Container space full"
DATA #1 : Object descriptor, PD_TYPE_SQLB_OBJECT_DESC, 104 bytes
    Obj: {pool:4;obj:2;type:128} Parent={4;2}
    lifeLSN:       0090353724100706
    tid:           0 0  0
    extentAnchor:                  64
    initEmpPages:                  32
    poolPage0:                     96
    poolflags:   0x              4112
    objectState: 0x                27
    lastSMP:                        0
  pageSize:                    4096
  extentSize:                    32
  bufferPoolID:                   3
  partialHash:           2147614724
  objDescAttributes:                  0
  objDescEHLState: 0x0000000000000000
  bufferPool:    0x00000000237a9dc0
  pdef:          0x00000000237cb040


最后,附上如何找到耗尽临时表空间的应用
http://www-01.ibm.com/support/docview.wss?uid=swg21992464

原创粉丝点击