学习笔记:4-TABLESPACE管理

前言:搞了10年的Oracle,最近开始学习DB2,从牛书《循序渐进DB2.DBA系统管理、运维与应用案例学习笔记》开始,将我学习过程中的测试命令及过程和大家共享,遇到的问题也如实写在上面,希望和大家一起学习!
大家也可以参考我的BLOG:http://www.db2china.net/home/space.php?uid=45420&do=blog,欢迎大家指正,谢谢!

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
参与10

8同行回答

huangweiranhuangweiran项目经理IBM
学习学习!!!!显示全部
学习学习!!!!收起
互联网服务 · 2013-10-07
浏览1779
北方明月北方明月系统架构师鞍钢股份
学习了显示全部
学习了收起
互联网服务 · 2012-07-04
浏览1723
小笨熊小笨熊软件工程师西安未来国际信息股份有限公司
学习中。。。显示全部
学习中。。。收起
IT分销/经销 · 2012-07-04
浏览1685
yanggang_homeyanggang_home软件工程师lovo
学习了。。。显示全部
学习了。。。收起
教育/培训 · 2012-06-11
浏览1663
hu_fangyuanhu_fangyuan其它nanjingxinwangshixun
学习了,哥们你10年oracle经验学DB2上手很快吧显示全部
学习了,哥们你10年oracle经验学DB2上手很快吧收起
2012-04-19
浏览1611
永无止境永无止境数据库管理员xd
学习,感谢分享!显示全部
学习,感谢分享!收起
电信设备制造商 · 2012-04-17
浏览1677
czbankadminczbankadmin软件开发工程师浙商银行
有个疑问,drop file有什么作用?在什么场景会需要使用?显示全部
有个疑问,drop file有什么作用?在什么场景会需要使用?收起
互联网服务 · 2012-04-05
浏览1652
cg07cg07系统工程师联通
学习了,呵呵显示全部
学习了,呵呵收起
互联网服务 · 2012-02-15
浏览1723

提问者

moonriver
软件开发工程师朗新科技(中国)有限公司系统集成部
擅长领域: 数据库服务器数据库巡检

相关问题

相关资料

相关文章

问题状态

  • 发布时间:2012-01-18
  • 关注会员:2 人
  • 问题浏览:10247
  • 最近回答:2013-10-07
  • X社区推广