查看数据库:db2 list db directory
查看数据库应用:db2 list applications
查看数据库应用和进程号:db2 list applications show detail
查看数据库表空间:db2pd -db <db_name> -tablespace
查看数据库配置:db2 get db cfg for <db_name>
查看配置实例参数:db2 get dbm cfg ; db2 update dbm cfg using ... ; db2 reset dbm cfg (恢复默认参数); 实例配置参数保存在 sqllib/db2systm文件中
查看配置DAS实例参数:db2 get admin cfg ; db2 update admin cfg using ...; db2 reset admin cfg ;
连接数据库:db2 connect to <db_name>
db2 connect to <db_name> user[user_name] using [password]
断开数据库连接:db2 connect reset/db2 terminate
创建数据库:db2 create db <db_name>
(dft_extent_sz 4
catalog tablespace managed by database using (FILE 'C:\111.dat' 2000, FILE 'C:\222.dat' 2000) extentsize 8 prefetchsize 16
temporary tablespace managed by system using ('C:\333.dat', 'C:\444.dat')
user tablespace managed by database using (FILE 'C:\555.dat' 1200 extentsize 24 prefetchsize 48)
automatic storage on path1,path2
autoresize yes
initialsize 200M
increasesize 20%
maxsize none
using codeset=GBK territory=CN )
automatic storage--默认设置,设置数据库为自动存储,即DMS自动存储
autoresize yes--表空间用光时,自动扩展
initialsize 200M--初始表空间大小为200MB, 每个容器100MB, 因为指定了两个path.
maxsize none--不限制表空间最大大小
using codeset=GBK territory=CN--指定数据库代码页为中文
using codeset=UTF-8 territory=US 指定代码页为unicode编码,可支持XML数据
创建表空间:db2 create tablespace <name> managed by automatic storage; DMS自动存储的数据库建立表空间, managed by可省略。
db2 create tbalespace <name> managed by system using () ; 未开启自动存储的数据库使用SMS方式建立表空间
db2 create tbalespace <name> managed by database using () extentsize 4; 未开启自动存储的数据库使用DMS方式建立表空间
extentsize 4--每个容器最多写入4个数据页; extentsize 4M--每个容器最多写入4M大小的数据
prefetchsize 4--从表空间预获取的数据页数量; prefetchsize 4M--预获取数据大小