moonriver
作者moonriver·2012-01-18 16:42
软件开发工程师·朗新科技(中国)有限公司系统集成部

4-TABLESPACE管理

字数 10367阅读 5126评论 3赞 0
1.创建8K缓冲池
  CREATE BUFFERPOOL bufferpool8k size 1000 automatic pagesize 8k
2.创建表空间
  db2 "create tablespace sms8k pagesize 8k managed by system using('FSMS_8K_1') bufferpool bufferpool8k"
  [db2inst1@localhost ~]$ db2 list tablespace containers for 6
            Tablespace Containers for Tablespace 6
 Container ID                         = 0
 Name                                 = /home/db2inst1/mydb/mydbpath1/db2inst1/NODE0000/SQL00001/FSMS_8K_1
 Type                                 = Path
3、创建对应缓冲快对应的临时表空间
 create system temporary tablespace tmp_sms8k managed by system using('tmp_sms8k')
Q:系统临时表空间
  IBM官方说法:至少应该有一个具有数据库中存在的用户表空间的各个页大小的系统临时表空间,否则某些查询可能会失败?为什么?
 但是如何指定临时表空间的pagesize呢?
A:
(1)系统临时表空间用来存储各种数据操作(排序、重组表、创建索引、连接表)中所需的内部临时数据,虽
然可以创建任意多个系统临时表空间,但建议用户只使用大多数表所使用的页大小创建一个,默认系统临时表空间名为TEMPSPACE1。用户临时表空间用来存储已说明全局临时表(已说明全局临时表存储的是应用程序临时数据)。用户临时表空间不是在数据库创建时默认创建的。
(2)如何没有对应块大小的临时表空间,可能会遇到 SQL1585N  A system temporary table space with sufficient page ,  size does not exist.
类似这样的错误,这个时候有可能就是因为默认的临时表空间不够造成的,如果这个排序发生在 32K 的表空间的话,一般推荐创建一个相应 pagesize 缓冲大小的临时表空间来排序。
3.表空间extend
 [db2inst1@localhost ~]$ db2 "alter tablespace USERSPACE1 extend (all 20)"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL20318N  Table space "USERSPACE1" of type "AUTOMATIC STORAGE" cannot be
altered using the "EXTEND" operation.  SQLSTATE=42858
--自动管理存储不能做EXTEND
4.表空间resize/reduce
[db2inst1@localhost ~]$ db2 list tablespace containers for 5
            Tablespace Containers for Tablespace 5
 Container ID                         = 0
 Name                                 = /home/db2inst1/mydb/dmspath1/dms1.dat
 Type                                 = File
 Container ID                         = 1
 Name                                 = /home/db2inst1/mydb/dmspath1/dms2.dat
 Type                                 = File

[db2inst1@localhost ~]$ db2 "alter tablespace DMSSPACE1 reduce(FILE '/home/db2inst1/mydb/dmspath1/dms1.dat' 500)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 "alter tablespace DMSSPACE1 resize(FILE '/home/db2inst1/mydb/dmspath1/dms1.dat' 500)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$
5.表空间drop FILE
[db2inst1@localhost ~]$ db2 "alter tablespace DMSSPACE1 DROP (FILE '/home/db2inst1/mydb/dmspath1/dms1.dat')"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 "alter tablespace DMSSPACE1 DROP (FILE '/home/db2inst1/mydb/dmspath1/dms2.dat')"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL20170N  There is not enough space in the table space "DMSSPACE1" for the
specified action. Reason code = "1".  SQLSTATE=57059
--不能删除表空间的最后一个FILE
[db2inst1@localhost ~]$ db2 list tablespace containers for 5
            Tablespace Containers for Tablespace 5
 Container ID                         = 0
 Name                                 = /home/db2inst1/mydb/dmspath1/dms2.dat
 Type                                 = File

[db2inst1@localhost ~]$
6、获取tablespace 预取设置
db2 get snapshot for tablespaces on mydb >mydb.snp
[db2inst1@localhost ~]$ grep "Prefetch size" mydb.snp
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 8
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 64
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 64
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 8
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 32
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 32
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 32
  Automatic Prefetch size enabled          = Yes
  Tablespace Prefetch size (pages)         = 8
 
 7、取消tablespace caching(可以加快读取性能?)
 db2 alter tablespace dmsspace1 no file system caching
 
 Tablespace name                            = DMSSPACE1
  Tablespace ID                            = 5
  Tablespace Type                          = Database managed space
  Tablespace Content Type                  = All permanent data. Large table space.
  Tablespace Page size (bytes)             = 4096
  Tablespace Extent size (pages)           = 32
  Automatic Prefetch size enabled          = Yes
  Buffer pool ID currently in use          = 1
  Buffer pool ID next startup              = 1
  Using automatic storage                  = No
  Auto-resize enabled                      = No
  File system caching                      = No
  Tablespace State                         = 0x'00000000'
   Detailed explanation:
     Normal
 
 --临时表空间的pagesize 应至少比数据表空间大1个页大小,同时应大于查询结果集的最好行记录大小
 [db2inst1@localhost ~]$ db2 "CREATE BUFFERPOOL bufferpool16k size 1000 automatic pagesize 16k"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 "create system temporary tablespace TEMPSPACE16K pagesize 16k managed by system using ('/home/db2inst1/mydb/mydbpath2/db2inst1/NODE0000/MYDB/TMP_TBSP') bufferpool bufferpool16k"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 list tablespace containers for 8
            Tablespace Containers for Tablespace 8
 Container ID                         = 0
 Name                                 = /home/db2inst1/mydb/mydbpath2/db2inst1/NODE0000/MYDB/TMP_TBSP
 Type                                 = Path
8、基于块的缓冲池,主要用于OLAP/DSS的频繁读取的表空间
db2 create bufferpool block_bp size 4096 numblockpages 2048 blocksize 128
 
 

 

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论3 条评论

myliqjmyliqj其它中科保
2013-06-14 20:25
不错,可以学习,只是如果drop容器,做 REBALANCE 真的很慢呀--数据大。
camydcamyd数据库管理员中储粮
2013-01-08 17:28
shlei6067shlei6067联盟成员数据库管理员NJ
2012-09-29 10:09
Ctrl+Enter 发表

作者其他文章

  • 9-DB2备份恢复小结
    评论 0 · 赞 0
  • 6-创建数据库对象
    评论 0 · 赞 0
  • 7-数据移动
    评论 0 · 赞 0
  • 3-创建DB及TABLESPACES
    评论 4 · 赞 0
  • 5-DB2服务器管理
    评论 0 · 赞 0
  • X社区推广