#创建Administration Server
[iyunv@localhost DB2_ESE_9.5]# cd /opt/ibm/db2/V9.5/instance/
[iyunv@localhost instance]# ./dascrt -u db2das1
SQL4406W The DB2 Administration Server was started successfully.
DBI1070I Program dascrt completed successfully.
#创建实例
[iyunv@localhost instance]# ./db2icrt -u db2inst1 db2inst1
DBI1070I Program db2icrt completed successfully.
#设置DB2 TCP/IP连接模式
[iyunv@localhost instance]# su db2inst1
[db2inst1@localhost instance]$ db2set DB2COMM=TCPIP
[db2inst1@localhost instance]$ db2 update dbm cfg using SVCENAME DB2_db2inst1
#修改连接端口为50000
[db2inst1@localhost instance]$ su root
[iyunv@localhost instance]# vi /etc/services
#添加防火墙开放50000、50001、50002、50003
[iyunv@localhost instance]# vi /etc/sysconfig/iptables
#添加自启动
[iyunv@localhost instance]# vi /etc/rc.d/rc.local
#start db2
cd /home/db2das1
su - db2das1 -c "db2admin start"
cd /home/db2inst1
su - db2inst1 -c "db2start"
#添加license
[iyunv@localhost instance]# /opt/ibm/db2/V9.5/adm/db2licm -a /tmp/db2/db2ese_c_v95.lic
#设置环境变量
[iyunv@localhost ~]# vi /etc/profile
#for db2
export PATH=/home/db2inst1/sqllib/bin:$PATH
#刷新环境变量
[iyunv@localhost ~]# source /etc/profile
#建库
db2 create database test using codeset utf-8 territory CN pagesize 16 K
db2问题集锦
问题一,
创建实例的时候 [iyunv@db01 db2home]# /opt/ibm/db2/V9.5/instance/db2icrt -a server -u db2fenc1 db2inst1 /opt/ibm/db2/V9.5/instance/db2iutil: line 4700: 24711 Segmentation fault (core dumped) ${DB2DIR?}/instance/db2isrv -addfcm -i ${INSTNAME?}
在/etc/hosts中添加 ip 和主机名即可
问题二
[db2inst1@db01 ~]$ db2start
02/03/2012 23:25:57 0 0 SQL1042C An unexpected system error occurred.
SQL1032N No start database manager command was issued. SQLSTATE=57019
关闭selinux 即可
问题三
$ db2 connect to database user user using password
SQL1084C Shared memory segments cannot be allocated. SQLSTATE=57019
sysctl 中增加kernel.shmmax 直到可以登录数据库为止。
或者减小db2 dbm的 INSTANCE_MEMORY 的值用db2 update dbm cfg using INSTANCE_MEMORY 100000(这个值自己定义)
问题四
$ db2 connect to database_name user user using password
SQL30082N Security processing failed with reason "24" ("USERNAME AND/OR
PASSWORD INVALID"). SQLSTATE=08001
解决方法:linux下db2用户名不能超过8个字符,windows下不能超过30个字符。
问题五:DB2 SQL error: SQLCODE: -1218, SQLSTATE: 57011
db2 force application all
db2stop
db2set DB2_OVERRIDE_BPF=100000 #这是把默认bufferpool大小设置为400M , 4kx100000
db2start
问题六:SQL1117N A connection to or activation of database "databasename" cannot be made
because ofROLL-FORWARD PENDING. SQLSTATE=57019
db2 => rollforward database databasename to end of logs and stop
Rollforward Status
Input database alias = databasename
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed =S0000001.LOG - S0000001.LOG
Last committed transaction = 2010-08-04-11.39.27.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
然后就可以connect to databasename了
参考: http://www.kuniel.net/2009/09/29/db2-restore-with-rollforward/
问题七:ResolvingError 3:DB2 return code is -4214
Check that the user name and password are specified correctly.
Check that the password does not contain special characters, such as the dollar sign ($).
PS:个人认为,加密方式如果抱错的话,密码改短点,别用特殊符号。
问题八:查看锁表以及解锁
方法一:
使用SecureCRT
db2 "get snapshot for locks on 数据库名"
db2 "force application(进程hander)"
杀掉死锁进程
方法二:
用管理员帐户登陆,在"管理员模式下"
使用select agent_id,tabname,lock_mode from table(snap_get_lock('BL_DEVP')) as aa
查看:进程hander,表名,锁模式
然后进控制中心,选择对应数据库,右键选择"应用程序",找到对应进程hander,选"强制"杀掉死锁进程
问题九:
SQL0964C errors because the DB2 transaction log is full
If you receive an SQL0964C error, adjust the DB2® log file settings.
Description
In enterprise environments where the amount of raw log data exceeds 30 GB per day, the default DB2 log file setting might be insufficient and result in the following error:SQL0964C The transaction log for the database is full. SQLSTATE=57011
WorkaroundSet the DB2 log file size to a larger size and increase the number of secondary log files. You must restart DB2 after making these changes. Connect to the Tivoli® Security Information and Event Manager database, CIFDB.
Set the log file size to 65536.
update db cfg for db_nameusing LOGFILSIZ 65536
Increase the number of secondary log files to 160.
update db cfg for db_nameusing LOGSECOND 160
Restart the DB2 service.
db2stop
db2start
For example:
update db cfg for CIFDB using LOGFILSIZ 65536
update db cfg for CIFDB using LOGSECOND 160
问题十:db2 v9 解锁
db2 update monitor switches using lock on
db2 get snapshot for locks on xxxxx > lock.txt
找到进程后
db2 "force application(XXXXX)"