DB2数据库的创建和表空间创建更改

1.创建数据库

create database testdb automatic storage yes on /database using codeset UTF-8 territory cn collate using system  PAGESIZE 32768 

on /database 表示数据库安装目录 using codeset   XXXX terriory XXX 指定数据库编码集和区域


1.1显示实例下创建的数据库 

list db directory


2.数据库连接

connect to testdb

3.创建缓冲池

create bufferpool bp32k size 10000 pagesize 32k  size表示页数,pagesize表示页大小,size*pagesize就是缓冲池的内存大小

4.创建数据库管理(DMS)的数据表空间

create large tablespace tbs_data pagesize 32k managed by database using (file '/data1/tbs_data/cont0' 1g, file '/data1/tbs_data/cont1' 1g) extentsize 32 prefetchsize automatic bufferpool bp32k no file system caching


5.创建系统管理(SMS)的临时表空间

create temporary tablespace tbs_temp pagesize 32k mamaged by system using  ('/data1/tbs_temp')  bufferpool bp32k

using 指定表空间的容器,SMS支持的容器类型只是目录

6.创建(SMS)管理的用户临时表空间

create user temporary tablespace tbs_user_temp pagesize 32k managed by system using ('/data1/tbs_usertemp') bufferpool bp32k


7.创建自动存储管理(Automatic Storage)的表空间

7.1 create tablespace tbs_index pagesize 32k bufferpool bp32k

7.2 create tablespace tbs_data2 initialsize 500M increasesize 500M maxsize 1000G

只有建库时启用了automatic storage yes,表空间才支持自动存储管理


8.显示每个表空间核心信息

list tablespaces

8.1显示指定表空间相关信息

list tablespace containers for [表空间标识ID] show detail

8.2比list tablespaces更详细的显示表空间信息

get snapshot for tablespaces on [数据库名]


9.显示表空间的配置信息,使用情况和容器信息

db2pd -d [数据库名] tablespaces


10.表空间容器的更改

10.1  alter tablespace add/drop/extend/reduce/resize 

//add和drop操作,表空间会发生数据重新平衡(rebalance),对于reduce和resize操作,需要确保更改后的表空间容器有足够的空间,否则db2会拒绝该操作。

10.2 alter tablespace begin new stripe set

//begin new stripe set 选项是当已有容器使用完后,再使用新增加的容器,该选项不会在容器间做Rebalance ,不会对系统造成性能影响,但它会造成数据偏移。

使用方法:alter tablespace data_ts2 add(file '/data1/ts2/cont2' 50G)

10.3  alter database db_name add storage on db_path3

//对于自动存储管理的表空间,无法在表空间级进行容器更改,只能在数据库级别,因为自动存储路径是在建库时指定的。可以使用add storage on 选项为数据库添加新的存储路径。

猜你喜欢

转载自blog.csdn.net/m0_38002798/article/details/80996548