How to create DB2 Instance on Linux

DB2 Instance is a run time environment under which database runs. Instance is used to configure run time environment using Database Manager Configuration (DBM) parameters and registry variables. You can have multiple instance on same server depending upon your server resource configuration. Databases are unique within the instance. You cannot have 2 database with same name in one instance but you can have 2 database with same name in different instance on same server. E.g. You cannot have 2 database with same name i.e. TESTDB in one instance i.e. db2i1 but you can have 2 database with same name i.e. TESTDB in two instance on server i.e. db2i1 and db2i2. In this blog we will see step by step procedure to create DB2 Instance on Linux server. This same steps can be followed for not only Linux environment but it is applicable for any unix environment which is supported by DB2.

Prerequisite :


To create DB2 instance on linux server you would need 2 OS user (instance id and fenced id)  which is not mapped with any other DB2 instance.
DB2 instance username should not be more than 8 character long. If you want to use more than 8 character long username for DB2 instance then ensure your operating system supports long ids.
DB2 Instance username cannot be GUESTS, LOCAL, PUBLIC, USERS, ADMINS. It cannot begin with IBM, SQL, SYS

Creating OS Users:


useradd -d <user home directory> <username>
-d option is optional
 

[root@MaxwellDBA /]# useradd  db2inst1

[root@MaxwellDBA db2]# useradd db2inst1
useradd: user 'db2inst1' already exists
[root@MaxwellDBA db2]# useradd db2fenc1

drwxrwxr-x 2 db2fenc1 db2fenc1  76 Sep  8 04:46 db2fenc1
drwxrwxr-x 6 db2inst1 db2inst1 147 Sep  8 05:43 db2inst1
[root@MaxwellDBA home]# 

Set password for both user (instance and fenced user) using passwd command

[root@MaxwellDBA db2]# passwd db2inst1
Changing password for user db2inst1.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@MaxwellDBA db2]# passwd db2fenc1
Changing password for user db2fenc1.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@MaxwellDBA db2]# 

Instance Creation:


To create DB2 instance in non-root installation you would need root privilege.
Change working directory to <db2 installation folder>/instance
To get db2 installation path use db2ls command

[root@MaxwellDBA V11.5]# cd install
[root@MaxwellDBA install]# ls -ltr
total 152
-r-xr-xr-x 1 bin  bin   9607 Nov 23  2021 db2un.rsp
-r-xr-xr-x 1 bin  bin  13082 Nov 23  2021 db2ls
-r-xr--r-- 1 bin  bin  18411 Nov 23  2021 db2_deinstall_exec
-r-xr--r-- 1 bin  bin  40524 Nov 23  2021 db2_deinstall
-r-xr-xr-x 1 bin  bin  20225 Nov 23  2021 db2chgpath
drwxr-xr-x 2 bin  bin     38 Nov 23  2021 tsamp
drwxr-xr-x 2 bin  bin     40 Nov 23  2021 pcmk
-r-xr-xr-x 1 bin  bin  44624 Sep  8 04:32 db2ls_exec
drwxr-xr-x 2 root root    54 Sep  8 04:33 logs
[root@MaxwellDBA install]# pwd
/opt/ibm/db2/V11.5/install
[root@MaxwellDBA install]# db2ls

Install Path                       Level   Fix Pack   Special Install Number   Install Date                  Installer UID 
---------------------------------------------------------------------------------------------------------------------
/opt/ibm/db2/V11.5               11.5.7.0        0                            Thu Sep  8 04:33:52 2022 CST             0 
[root@MaxwellDBA install]# 

Under instance directory list db2icrt file
ls -lrt db2icrt

[root@MaxwellDBA instance]# pwd
/opt/ibm/db2/V11.5/instance
[root@MaxwellDBA instance]# ls -ltr db2icrt
-r-xr--r-- 1 root root 51760 Sep  8 04:32 db2icrt
[root@MaxwellDBA instance]# 

Execute db2icrt to create instance


./db2icrt -u <fenced id> <db2instance id>

[root@MaxwellDBA instance]# ./db2icrt -u db2fenc1 db2inst1
DBI1446I  The db2icrt command is running.


DB2 installation is being initialized.

 Total number of tasks to be performed: 4 
Total estimated time for all tasks to be performed: 309 second(s) 

Task #1 start
Description: Setting default global profile registry variables 
Estimated time 1 second(s) 
Task #1 end 

Task #2 start
Description: Initializing instance list 
Estimated time 5 second(s) 
Task #2 end 

Task #3 start
Description: Configuring DB2 instances 
Estimated time 300 second(s) 
Task #3 end 

Task #4 start
Description: Updating global profile registry 
Estimated time 3 second(s) 
Task #4 end 

The execution completed successfully.

For more information see the DB2 installation log at "/tmp/db2icrt.log.448613".
DBI1070I  Program db2icrt completed successfully.


[root@MaxwellDBA instance]# 

Connect to DB2 instance
su - <db2instance id>

[root@MaxwellDBA home]# cd /opt/ibm/db2/V11.5/instance
[root@MaxwellDBA instance]# su - db2inst1
Last login: Thu Sep  8 05:43:57 CST 2022 on pts/0
[db2inst1@MaxwellDBA ~]$ ls -ltr
total 4
drwxrwsr-t 20 db2inst1 db2inst1 4096 Sep  8 05:44 sqllib
[db2inst1@MaxwellDBA ~]$ 

After successful instance creation in your instance user home directory you would find sqllib directory.

Start DB2 Instance

db2start

[db2inst1@MaxwellDBA ~]$ db2start
09/08/2022 05:51:57     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@MaxwellDBA ~]$

As I have installed trail version of DB2 11.5 I got warning message.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值