DB2 添加新分区到分区组(DATABASE PARTITION GROUP)后,数据并未分布

问题:

 DB2 DPF环境中, 往分区组中添加了新的分区之后,发现数据并没有分布到新添加的分区上, 即使是添加分区之后新创建的表空间也是如此。


原因:

 When a database partition is added to a database partition group, a catalog entry is made for the database partition (see SYSCAT.DBPARTITIONGROUPDEF). The distribution map is changed immediately to include the new database partition, along with an indicator (IN_USE) that the database partition is in the distribution map if either:
    --no table spaces are defined in the database partition group or
    --no tables are defined in the table spaces defined in the database partition group and the WITHOUT TABLESPACES clause was not specified.


The distribution map is not changed and the indicator (IN_USE) is set to indicate that the database partition is not included in the distribution map if either:
    --Tables exist in table spaces in the database partition group or
    --Table spaces exist in the database partition group and the WITHOUT TABLESPACES clause was specified (unless all of the table spaces are defined to use automatic storage, in which case the WITHOUT TABLESPACES clause is ignored)


To change the distribution map, the REDISTRIBUTE DATABASE PARTITION GROUP command must be used. This redistributes any data, changes the distribution map, and changes the indicator. Table space containers need to be added before attempting to redistribute data if the WITHOUT TABLESPACES clause was specified.


问题重现:

PARTITION GROUP GOURP0123原本包含了分区0~3,并且创建了表空间tbs1。

现新添加分区4,之后创建表空间tbs2,并导入数据。 发现新添加的分区4上面根本没有数据。


1.) 初始状态:
$ db2start
2015-12-16 11:26:57     1   0   SQL1063N  DB2START processing was successful.
2015-12-16 11:26:57     2   0   SQL1063N  DB2START processing was successful.
2015-12-16 11:26:58     3   0   SQL1063N  DB2START processing was successful.
2015-12-16 11:26:58     4   0   SQL1063N  DB2START processing was successful.
2015-12-16 11:26:59     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.

db2 "CREATE DATABASE SAMPLE"
db2 "CREATE DATABASE PARTITION GROUP GOURP0123  ON DBPARTITIONNUMS (0,1,2,3)"
db2 "CREATE TABLESPACE "TBS1" IN  GOURP0123 MANAGED BY DATABASE USING (FILE 'c:\conpath\partition0' 5000) ON DBPARTITIONNUMS (0) USING (FILE 'c:\conpath\partition1' 5000) ON DBPARTITIONNUMS (1) USING (FILE 'c:\conpath\partition2' 5000) ON DBPARTITIONNUMS (2) USING (FILE 'c:\conpath\partition3' 5000) ON DBPARTITIONNUMS (3)"
db2 "create table t1(id int) in TBS1"
db2 "import from c:\t1.del of del insert into t1"
db2 "SELECT DBPARTITIONNUM(ID) as PARTITION_NUM, COUNT(*) as ROW_NUM FROM T1 GROUP BY DBPARTITIONNUM(ID) ORDER BY DBPARTITIONNUM(ID)"
PARTITION_NUM ROW_NUM
------------- -----------
            0         237
            1         258
            2         251
            3         254
  4 record(s) selected.

2.)添加新的分区4到partition group,并创建新的表空间TBS2。 发现TBS1和TBS2中的数据均未分布到新添加的分区中
db2 " ALTER DATABASE PARTITION GROUP GOURP0123 ADD DBPARTITIONNUM (4) WITHOUT TABLESPACES"
SQL1759W  Redistribute database partition group is required to change database
partitioning for objects in database partition group "GOURP0123" to include
some added database partitions or exclude some dropped database partitions.
SQLSTATE=01618

db2 "CREATE TABLESPACE "TBS2" IN  GOURP0123 MANAGED BY DATABASE USING (FILE 'c:\conpath\TBS2_0' 5000) ON DBPARTITIONNUMS (0) USING (FILE 'c:\conpath\TBS2_1' 5000) ON DBPARTITIONNUMS (1) USING (FILE 'c:\conpath\TBS2_2' 5000) ON DBPARTITIONNUMS (2) USING (FILE 'c:\conpath\TBS2_3' 5000) ON DBPARTITIONNUMS (3) USING (FILE 'c:\conpath\TBS2_4' 5000) ON DBPARTITIONNUMS (4) "
db2 "create table t2 like t1 in TBS2"
db2 "insert into t2 select * from t1"
db2 "SELECT DBPARTITIONNUM(ID) as PARTITION_NUM, COUNT(*) as ROW_NUM FROM T2 GROUP BY DBPARTITIONNUM(ID) ORDER BY DBPARTITIONNUM(ID)"
PARTITION_NUM ROW_NUM
------------- -----------
            0         237
            1         258
            2         251
            3         254
  4 record(s) selected.
  
db2 "SELECT DBPARTITIONNUM(ID) as PARTITION_NUM, COUNT(*) as ROW_NUM FROM T1 GROUP BY DBPARTITIONNUM(ID) ORDER BY DBPARTITIONNUM(ID)"
PARTITION_NUM ROW_NUM
------------- -----------
            0         237
            1         258
            2         251
            3         254
  4 record(s) selected.  
    
db2 "select DBPARTITIONNUM, IN_USE from SYSCAT.DBPARTITIONGROUPDEF  where DBPGNAME='GOURP0123'"
DBPARTITIONNUM IN_USE
-------------- ------
             0 Y
             1 Y
             2 Y
             3 Y
             4 T
  5 record(s) selected.

解决:

修改原表空间TBS1定义,在节点4上添加新容器,并重新分布partition group
db2 "ALTER TABLESPACE TBS1 ADD (file 'c:\conpath\partition4' 5000) ON dbpartitionnums(4)"
SQL1759W  Redistribute database partition group is required to change database
partitioning for objects in database partition group "GOURP0123" to include
some added database partitions or exclude some dropped database partitions.
SQLSTATE=01618

db2 "REDISTRIBUTE DATABASE PARTITION GROUP GOURP0123 NOT ROLLFORWARD RECOVERABLE UNIFORM"

db2 "SELECT DBPARTITIONNUM(ID) as PARTITION_NUM, COUNT(*) as ROW_NUM FROM T1 GROUP BY DBPARTITIONNUM(ID) ORDER BY DBPARTITIONNUM(ID)"
PARTITION_NUM ROW_NUM
------------- -----------
            0         184
            1         196
            2         206
            3         206
            4         208
  5 record(s) selected.

db2 "SELECT DBPARTITIONNUM(ID) as PARTITION_NUM, COUNT(*) as ROW_NUM FROM T2 GROUP BY DBPARTITIONNUM(ID) ORDER BY DBPARTITIONNUM(ID)"
PARTITION_NUM ROW_NUM
------------- -----------
            0         184
            1         196
            2         206
            3         206
            4         208
  5 record(s) selected.


参考资料:

IBM信息中心

你可能感兴趣的:(DB2)