Thursday, September 24, 2015

Changing hostname of the DB2 server. What updates in DB2 need to be made?

Changing hostname of the DB2 server. What updates in DB2 need to be made?

In general you will get the following error if you change your hostname:
db2 => list database directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = UNICADB
 Database name                        = UNICADB
 Local database directory             = /apps/db2data/unicadb
 Database release level               = 10.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

db2 => drop database UNICADB
SQL1031N  The database directory cannot be found on the indicated file system.
SQLSTATE=58031
db2 => quit
DB20000I  The QUIT command completed successfully.
[db2inst1@rhel65dbs ~]$ db2 "connect to unicadb"
SQL1031N  The database directory cannot be found on the indicated file system.
SQLSTATE=58031
[db2inst1@rhel65dbs ~]$ db2start
09/24/2015 23:36:20     0   0   SQL6048N  A communication error occurred during START or STOP DATABASE MANAGER processing.
SQL1032N  No start database manager command was issued.  SQLSTATE=57019

 Here's a good link on what to do. And another link to troubleshoot.

For me, here's what I did:

0. Login as db2inst1 and shutdown
db2stop

1. Login as root:
[root@rhel65dbs sqllib]# db2set -g DB2SYSTEM=rhel65dbs.local.com
[root@rhel65dbs sqllib]# db2set -g
DB2SYSTEM=rhel65dbs.local.com
DB2INSTDEF=db2inst1
DB2ADMINSERVER=dasusr1
[root@rhel65dbs sqllib]# uname -a
Linux rhel65dbs.local.com 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

2. Locate db2nodes.cfg in one of the following directories:
UNIX/Linux:
<db2 instance home directory>/sqllib/db2nodes.cfg
3. In the db2nodes.cfg file change <current hostname> to <new hostname>.
4. Login as db2inst1 and verify:
[root@rhel65dbs sqllib]# su - db2inst1
[db2inst1@rhel65dbs ~]$ db2set -g
DB2SYSTEM=rhel65dbs.local.com
DB2INSTDEF=db2inst1
DB2ADMINSERVER=dasusr1
5. Startup and connect:
[root@rhel65dbs sqllib]# su - db2inst1
[db2inst1@rhel65dbs ~]$ db2start
09/25/2015 00:09:06     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@rhel65dbs ~]$ db2 "connect to unicadb"

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = DB2INST1
 Local database alias   = UNICADB


A useful list of IBM DB2 commands

https://wiki.base22.com/display/btg/A+useful+list+of+IBM+DB2+commands

List all databases in an instance

1. LIST DATABASE DIRECTORY

db2 => list database directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = UNICADB
 Database name                        = UNICADB
 Local database directory             = /apps/db2data/unicadb
 Database release level               = 10.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =


2. LIST ACTIVE DATABASES
    (An active database is available for connection and use by any application)

db2 => list active database
SQL0104N  An unexpected token "database" was found following "ACTIVE". 
Expected tokens may include:  "DATABASES".  SQLSTATE=42601
db2 => list active databases

                           Active Databases

Database name                              = UNICADB
Applications connected currently           = 1
Database path                              = /apps/db2data/unicadb/db2inst1/NODE0000/SQL00001/MEMBER0000/


Monday, December 22, 2014

Run DB2 SQL Scripts on command line

Use this:


1. login as the db user - if on unix use db2profile to set environment
2.  run db2 and connect to the db2 instance
3. quit
4. run the script using
      db2 -tvf < script name>

Note: some may require special options:
db2 +c -td@ -vf <script  name>

The above means auto commit is on, use @ as the delimiter for every SQL in the script.

For more details:
db2 ? options

Saturday, December 20, 2014

Create sample unicadb database on DB2 on linux


CREATE DATABASE UNICADB AUTOMATIC STORAGE YES ON '/apps/db2data/unicadb' DBPATH ON '/apps/db2data/unicadb' USING CODESET UTF-8 TERRITORY US PAGESIZE 32 K

CONNECT TO UNICADB

CREATE BUFFERPOOL UNICA32KBPOOL  SIZE 3000 PAGESIZE 32K 

CREATE REGULAR TABLESPACE UNICA PAGESIZE 32K MANAGED BY AUTOMATIC STORAGE BUFFERPOOL UNICA32KBPOOL  AUTORESIZE YES


create bufferpool unicasys32kbpool size 500 pagesize 32K

CREATE TEMPORARY TABLESPACE TEMPSPACE2 pagesize 32k MANAGED BY AUTOMATIC STORAGE BUFFERPOOL unicasys32kbpool


REVOKE USE OF TABLESPACE USERSPACE1 FROM PUBLIC
 
GRANT USE OF TABLESPACE UNICA TO USER UMP WITH GRANT OPTION 

GRANT USE OF TABLESPACE UNICA TO USER UC  WITH GRANT OPTION

GRANT USE OF TABLESPACE UNICA TO USER UMO WITH GRANT OPTION

Thursday, December 18, 2014

Installing DB2 Data Studio on Linux - libswt-pi-gtk.so error

If you can the following errors, it means you don't have 32bit GTK components installed:

unica@rhel-server-6 staging]$ ./install
00:00.38 ERROR [main] com.ibm.cic.agent.internal.ui.AgentUI reportStatus
  Could not load SWT library. Reasons:
      /apps/staging/configuration/org.eclipse.osgi/bundles/109/1/.cp/libswt-pi-gtk-4237.so (libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory)
      swt-pi-gtk (Not found in java.library.path)
      /home/unica/.swt/lib/linux/x86/libswt-pi-gtk-4237.so (libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory)
      /home/unica/.swt/lib/linux/x86/libswt-pi-gtk.so (/home/unica/.swt/lib/linux/x86/liblibswt-pi-gtk.so.so: cannot open shared object file: No such file or directory)
  java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
    /apps/staging/configuration/org.eclipse.osgi/bundles/109/1/.cp/libswt-pi-gtk-4237.so (libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory)
    swt-pi-gtk (Not found in java.library.path)
    /home/unica/.swt/lib/linux/x86/libswt-pi-gtk-4237.so (libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory)
    /home/unica/.swt/lib/linux/x86/libswt-pi-gtk.so (/home/unica/.swt/lib/linux/x86/liblibswt-pi-gtk.so.so: cannot open shared object file: No such file or directory)

    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:331)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
    at org.eclipse.swt.internal.gtk.OS.<clinit>(OS.java:22)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    ...
The displayed failed to initialize.  See the log /apps/staging/configuration/1418895329737.log for details.

To solve:

yum install gtk2.i686 gtk2-engines.i686 PackageKit-gtk-module.i686 PackageKit-gtk-module.x86_64 libcanberra-gtk2.x86_64 libcanberra-gtk2.i686

Wednesday, December 17, 2014

rdma and log_mtts_per_seg when installing DB2 10.5

I got the following errors when running db2prereqcheck:

Validating "rdma" ...
Found package "rdma" on host "localhost.localdomain".
DBT3566E  The db2prereqcheck utility detected that the service named "rdma" is not enabled on host "localhost.localdomain".
   ERROR : Requirement not matched.


Validating "modprobe.conf" ...
DBT3588W  The db2prereqcheck utility was unable to validate the configuration of the log_mtts_per_seg parameter on the following host machine: "localhost.localdomain". Reason code: "1".
   WARNING : Requirement not matched.


After doing some research, since I am not using the DB2 PureScale features, it should be OK to ignore these errors.