【DB2数据库表空间日常管理命令】

1、创建pagesize为32kb的bufferpool
create bufferpool bp32k size 2000 pagesize 32k


2、查看bufferpool属性
select * from syscat.bufferpools


3、更改缓冲池大小
alter bufferpool bp32k size 10

--查看系统缓冲池
select * from syscat.bufferpools
alter bufferpool IBMDEFAULTBP size 4000
alter bufferpool BUF_HGQW size 40


4、创建数据页为32kb数据块为1024kb预取值为默认,且不使用文件系统缓存的大型DMS表空间
create large tablespace tbs_data pagesize 32k managed by database using (file '/database/tbs_data/cont0' 100M,file '/database/tbs_data/cont1' 100M) extentsize 32 prefetchsize automatic bufferpool bp32k no file system caching

5、创建 数据页为32kb的SMS系统临时表空间
create temporary tablespace tbs_temp pagesize 32k managed by system using ('/database/tbs_temp') bufferpool bp32k

6、创建 数据页为32kb的SMS用户临时表空间
create user temporary tablespace tbs_user_temp pagesize 32k managed by system using('/database/tbs_usertemp') bufferpool bp32k


7、创建 数据页为32kb的自动存储管理表空间
create tablespace tbs_index pagesize 32k bufferpool bp32k

8、创建初始大小为100MB,增量为100MB,最大大小为100GB的 自动存储管理表空间
create tablespace tbs_data2 initialsize 100M increasesize 100M maxsize 100G


9、查看表空间信息
list tablespaces
list tablespaces show detail
db2pd -d testdb -tablespaces
get snapshot for tablespaces on testdb
也可以查看sysibmadm.snaptbsp和sysibmadm.snapcontainer这两个视图


10、查看表空相关的容器信息
list tablespace containers for 7    #tablespace id
list tablespace containers for 7 show detail


11、分配空间

如果DMS表空间对应的存储中还有未分配空间,可通过alter tablespace的extend、reduce或resize选项扩展已有表空间容器的大小。其中extend用来扩展容器大小,reduce用来缩减已有容器大小,resize重新设定容器大小。对于reduce和resize,需确保更改后的表空间有足够空间,否则DB2拒绝操作。
alter tablespace tbs_data extend (file '/database/tbs_data/cont0' 10M)


12、增加容器

如果表空间容器已经没有剩余空间,可通过add选项增加容器,当然必要的情况下也可以通过drop选项删除容器。对于add和drop操作会在容器间发生数据重新平衡(rebalance)。如果数据量很大,rebalance时间有可能很久,对系统可能造成很大影响。
alter tablespace tbs_data add(file '/database/tbs_data/cont2' 100m)


13、数据偏移

如果使用begin new strip set选项则会在现有容器空间用完时使用新增容器,该选项使数据不会在容器间做rebalance,但会造成数据偏移。
alter tablespace tbs_data begin new stripe set (file '/database/tbs_data/cont3' 100m)

14、查看自动存储管理表空间路径
db2pd -d testdb -storagepaths


15、对于自动存储管理表空间,无法在表空间级进行容器更改,只能在数据级别,因为自动存储路径是在建库时指定的。可以使用add storage on选项为数据库添加新的存储路径。在v9.7版本之前,自动存储路径只能增加,不能删除。新增加的存储路径不会备表空间立即使用,只有在已有存储路径文件系统空间满了,才会使用新增路径,增加路径只是为了解决容量问题。v9.7版本之后,只要对使用自动存储管理的表空间执行rebalance,则该表空间可以立即使用新增存储路径。

alter database testdb add storage on '/database/czm'
alter tablespace 7 rebalance


16、将DMS表空间转换成自动存储管理表空间
alter tablespace tbs_data managed by automatic storage
alter tablespace tbs_data rebalance

17.修改某一列的属性
设置test表的tname列为null和not null
alter table test alter tname drop not null
alter table test alter tname set not NULL

alter table staff drop column years

alter table staff alter job set data type varchar (20)

猜你喜欢

转载自gaojingsong.iteye.com/blog/2282314
今日推荐