Tuesday, July 30, 2024

IBM DB2 STOP and START

 #!/bin/bash

# Function to stop Db2
stop_db2() {
echo “Stopping Db2…”
db2stop
if [ $? -eq 0 ]; then
echo “Db2 stopped successfully.”
else
echo “Regular stop failed. Attempting forceful stop…”
db2stop force
if [ $? -eq 0 ]; then
echo “Db2 stopped forcefully.”
else
echo “Failed to stop Db2.”
fi
fi
}

# Function to start Db2
start_db2() {
echo “Starting Db2…”
db2start
if [ $? -eq 0 ]; then
echo “Db2 started successfully.”
else
echo “Failed to start Db2.”
fi
}

# Main script
if [ “$1” == “stop” ]; then
stop_db2
elif [ “$1” == “start” ]; then
start_db2
else
echo “Usage: $0 [stop|start]”
exit 1
fi

Install DB2 V10.5 using GUI

 Table of Content:

1. Hardware Requirements

2. Verify OS version

3. Download DB2 software

4. Untar Software

5. DB2 Installation Prerequisites

6. Set the DISPLAY Environment

7. Invoke ./db2setup

8. Validation

9. Verification

1. Hardware Requirements

2. Verify OS version

[root@pcs1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
[root@pcs1 ~]#

3. Download Software

Download DB2 from www.ibm.com


4. Untar Software

[root@pcs1 ~]# mkdir -p /u01/IBM/db2
[root@pcs1 stage]# tar -xvf v10.5fp10_linuxx64_server_t.tar.gz -C /u01/IBM/db2

[root@pcs1 stage]# cd /u01/IBM/db2
[root@pcs1 db2]# ls -ltr
total 4
drwxr-xr-x. 5 root root 4096 Jul  4  2018 server_t
[root@pcs1 db2]# cd server_t
[root@pcs1 server_t]# ls -ltr
total 116
drwxr-xr-x.  4 root root    84 Jul  4  2018 nlpack
-r-xr-xr-x.  1 bin  bin   5642 Jul  4  2018 db2prereqcheck
-r-xr-xr-x.  1 bin  bin   5798 Jul  4  2018 db2_deinstall
-r-xr-xr-x.  1 bin  bin   5650 Jul  4  2018 db2setup
-r--r--r--.  1 bin  bin  41540 Jul  4  2018 db2checkCOL.tar.gz
-r-xr-xr-x.  1 bin  bin   5632 Jul  4  2018 db2ls
-r--r--r--.  1 bin  bin   4987 Jul  4  2018 db2checkCOL_readme.txt
-r-xr-xr-x.  1 bin  bin   5883 Jul  4  2018 db2ckupgrade
-r-xr-xr-x.  1 bin  bin   5668 Jul  4  2018 db2_install
-r-xr-xr-x.  1 bin  bin   5686 Jul  4  2018 installFixPack
drwxr-xr-x. 10 bin  bin   4096 Jul  4  2018 ibm_im
drwxr-xr-x.  6 bin  bin   4096 Jul  4  2018 db2
[root@pcs1 server_t]#


5. DB2 Installation Prerequisites

[root@pcs1 server_t]# ls -ltr db2prereqcheck
-r-xr-xr-x. 1 bin bin 5642 Jul  4  2018 db2prereqcheck
[root@pcs1 server_t]#
[root@pcs1 server_t]# ./db2prereqcheck
..............
..............
Summary of prerequisites that are not met on the current system:
   DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/libpam.so*".


DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.5".


DBT3563E  The db2prereqcheck utility determined that SELinux is enabled, which is not supported with GPFS.

[root@pcs1 server_t]#


6. Set the DISPLAY Environment

If you are using X emulation then set the DISPLAY environmental variable.

[root@pcs1 server_t]# export DISPLAY=192.168.2.1:0.0;


7. Invoke ./db2setup

[root@pcs1 server_t]# ls -ltr
total 116
drwxr-xr-x.  4 root root    84 Jul  4  2018 nlpack
-r-xr-xr-x.  1 bin  bin   5642 Jul  4  2018 db2prereqcheck
-r-xr-xr-x.  1 bin  bin   5798 Jul  4  2018 db2_deinstall
-r-xr-xr-x.  1 bin  bin   5650 Jul  4  2018 db2setup
-r--r--r--.  1 bin  bin  41540 Jul  4  2018 db2checkCOL.tar.gz
-r-xr-xr-x.  1 bin  bin   5632 Jul  4  2018 db2ls
-r--r--r--.  1 bin  bin   4987 Jul  4  2018 db2checkCOL_readme.txt
-r-xr-xr-x.  1 bin  bin   5883 Jul  4  2018 db2ckupgrade
-r-xr-xr-x.  1 bin  bin   5668 Jul  4  2018 db2_install
-r-xr-xr-x.  1 bin  bin   5686 Jul  4  2018 installFixPack
drwxr-xr-x. 10 bin  bin   4096 Jul  4  2018 ibm_im
drwxr-xr-x.  6 bin  bin   4096 Jul  4  2018 db2
[root@pcs1 server_t]#
[root@pcs1 server_t]#
[root@pcs1 server_t]# ./db2setup
Requirement not matched for DB2 database "Server" . Version: "10.5.0.10".

Summary of prerequisites that are not met on the current system:

   DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/libpam.so*".


DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6".


DBI1190I  db2setup is preparing the DB2 Setup wizard which will guide
      you through the program setup process. Please wait.

8. Validation

[root@pcs1 server_t]# /u01/IBM/db2/V10.5/bin/db2val
DBI1379I  The db2val command is running. This can take several minutes.

DBI1335I  Installation file validation for the DB2 copy installed at
      /u01/IBM/db2/V10.5 was successful.

DBI1343I  The db2val command completed successfully. For details, see
      the log file /tmp/db2val-220423_131019.log.


[root@pcs1 server_t]#

9. Verification

[db2inst1@pcs1 ~]$ id
uid=54323(db2inst1) gid=101(db2iadm1) groups=101(db2iadm1)
[db2inst1@pcs1 ~]$
[db2inst1@pcs1 ~]$ db2level
DB21085I  This instance or install (instance name, where applicable:
"db2inst1") uses "64" bits and DB2 code release "SQL1005A" with level
identifier "060B010E".
Informational tokens are "DB2 v10.5.0.10", "s180615", "IP24053", and Fix Pack
"10".
Product is installed at "/u01/IBM/db2/V10.5".

[db2inst1@pcs1 ~]$
[db2inst1@pcs1 ~]$ db2ls

Install Path                       Level   Fix Pack   Special Install Number   Install Date                  Installer UID
---------------------------------------------------------------------------------------------------------------------
/u01/IBM/db2/V10.5              10.5.0.10       10                            Sat Apr 23 12:57:17 2022 +08             0
[db2inst1@pcs1 ~]$
[db2inst1@pcs1 ~]$ ps -ef | grep db2
root      2899     1  0 12:58 ?        00:00:00 db2wdog 0 [db2inst1]
db2inst1  2901  2899  0 12:58 ?        00:00:02 db2sysc 0 <---
root      2907  2899  0 12:58 ?        00:00:00 db2ckpwd 0
root      2908  2899  0 12:58 ?        00:00:00 db2ckpwd 0
root      2909  2899  0 12:58 ?        00:00:00 db2ckpwd 0
db2inst1  2911  2899  0 12:58 ?        00:00:00 db2vend (PD Vendor Process - 1) 0
db2inst1  2920  2899  0 12:58 ?        00:00:01 db2acd 0 ,0,0,0,1,0,0,0,0000,1,0,995db8,14,1e014,2,0,1,41fc0,0x210000000,0x210000000,1600000,30003,2,c0013
root     19016  6539  0 13:13 pts/1    00:00:00 su - db2inst1
db2inst1 19017 19016  0 13:13 pts/1    00:00:00 -bash
db2inst1 20146 19017  0 13:17 pts/1    00:00:00 ps -ef
db2inst1 20147 19017  0 13:17 pts/1    00:00:00 grep --color=auto db2
root     27033     1  0 12:57 ?        00:00:00 /u01/IBM/db2/V10.5/bin/db2fmcd
[db2inst1@pcs1 ~]$

[db2inst1@pcs1 ~]$ db2ilist
db2inst1
[db2inst1@pcs1 ~]$
[db2inst1@pcs1 ~]$ db2 get instance

 The current database manager instance is:  db2inst1

[db2inst1@pcs1 ~]$

[db2inst1@pcs1 ~]$ db2licm -l
Product name:                     "DB2 Advanced Enterprise Server Edition"
License type:                     "Trial"
Expiry date:                      "07/21/2022"
Product identifier:               "db2aese"
Version information:              "10.5"

[db2inst1@pcs1 ~]$

[db2inst1@pcs1 ~]$ db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 10.5.10

You can issue database manager commands and SQL statements from the command
prompt. For example:
    db2 => connect to sample
    db2 => bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

db2 =>
db2 => quit
DB20000I  The QUIT command completed successfully.
[db2inst1@pcs1 ~]$
[db2inst1@pcs1 ~]$ db2 list db directory
SQL1031N  The database directory cannot be found on the indicated file system.
SQLSTATE=58031
[db2inst1@pcs1 ~]$

DB2 export and import

Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested individually; however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
























IBM DB2 Troubleshooting Guide

 Introduction to the DB2 Troubleshooting Guide

Troubleshooting issues in DB2 databases is a critical skill for database administrators and developers alike. Whether you’re dealing with performance bottlenecks, locking problems, or unexpected errors, having a structured approach to diagnose and resolve issues can make all the difference in maintaining database efficiency and stability.

DB2 Troubleshooting Guide

  1. Understanding the Problem

Before diving into specific issues, it is crucial to gather relevant information:

  • Symptoms: What is the exact problem? (e.g., performance issues, connection failures, query errors)
  • Logs: Check DB2 logs for errors or warnings.
  • Environment: Note the DB2 version, OS, hardware configuration, and any recent changes.
  1. Common Issues and Solutions A. Connection Problems
  • Error: SQL30081N A communication error has been detected
    • Possible Causes: Network issues, firewall settings, incorrect port number.
    • Troubleshooting Steps:
      1. Verify the network connectivity between the client and server using ping or traceroute.
      2. Ensure that the DB2 service is running on the server (db2start).
      3. Check firewall settings to ensure the DB2 port (default 50000) is open.
      4. Verify the database manager configuration (dbm cfg) for the correct port number.
  • Error: SQL1042C An unexpected system error occurred
    • Possible Causes: Insufficient system resources, corrupted DB2 files.
    • Troubleshooting Steps:
      1. Check system resources (CPU, memory) using tools like top or Task Manager.
      2. Review DB2 diagnostic logs (db2diag.log) for detailed error messages.
      3. Restart the DB2 instance (db2stop and db2start).
      4. If the problem persists, reinstall DB2 or restore the instance from a backup.
  1. Performance Issues
  • Symptom: Slow Query Performance
    • Possible Causes: Inefficient queries, lack of indexing, insufficient memory.
    • Troubleshooting Steps:
      1. Use the EXPLAIN command to analyze query execution plans.
      2. Optimize queries by rewriting them or using appropriate indexes.
      3. Increase the size of buffer pools using ALTER BUFFERPOOL.
      4. Check for lock contention using db2pd -locks.
  • Symptom: High CPU or Memory Usage
    • Possible Causes: Resource-intensive queries, insufficient hardware, memory leaks.
    • Troubleshooting Steps:
      1. Identify resource-heavy queries using db2top or db2pd -dynamic.
      2. Optimize or terminate long-running queries.
      3. Increase system memory or add CPUs if hardware is insufficient.
      4. Review and adjust DB2 configuration parameters (db2 get db cfg).
  1. Database Corruption
  • Error: SQL0299N Database or tablespace in a bad state
    • Possible Causes: Hardware failures, software bugs, abrupt system shutdowns.
    • Troubleshooting Steps:
      1. Check the integrity of the database using db2ckbkp.
      2. Attempt to repair using db2dart.
      3. Restore from the most recent backup if repairs are unsuccessful.
  1. Backup and Restore Issues
  • Error: SQL2008N The value for parameter is not valid
    • Possible Causes: Incorrect parameters, insufficient permissions.
    • Troubleshooting Steps:
      1. Verify the syntax and parameters of the BACKUP or RESTORE command.
      2. Ensure the user has the necessary permissions to perform backup or restore.
      3. Check disk space availability for backup files.
  1. Diagnostic Tools and Commands
  • db2diag: Primary diagnostic log for DB2.
  • db2pd: Provides a snapshot of the DB2 instance’s status.
  • db2top: Monitors real-time performance metrics.
  • db2look: Generates DDL and statistical information about the database.
  • db2support: Collects diagnostic information for IBM support.

Common Options for db2support

  • -d <database_name>: Specifies the database name.
  • -h: Includes historical data.
  • -c: Collects data from the database.
  • -s: Includes system information.
  • -m: Includes memory-related information.
  • -o <output_directory>: Specifies the output directory for the collected information.

db2diag: Primary diagnostic log for DB2.

  • Check Diagnostic Log Configuration:

db2 get dbm cfg | grep DIAGPATH

  • View the Last 100 Entries:

db2diag -n 100

  • View Entries from a Specific Date:

db2diag -g “timestamp >= ‘2024-06-01 00:00:00′”

  • View Error Entries for a Specific Database:

db2diag -g “db = MYDB and level = ERROR”

  • Export Entries to a File:

db2diag -g “db = MYDB and level = ERROR and timestamp >= ‘2024-06-01 00:00:00′” > /path/to/output_file.txt

Catching a lock timeout using the db2pdcfg -catch option

  1. Set the error catch setting.

You can use -911,68, -911, or locktimeout. In fact, if you know the lock type or lock name in advance, you can use the locktype or lockname sub options to filter out unwanted lock catches.

The count=1 option indicates that you want to capture data for a single lock timeout event.

db2pdcfg -catch locktimeout count=1

  1. Verify the Configuration:

db2pdcfg -catch

  1. Review the Captured Data

db2diag | grep “lock timeout”

 

db2support: Collects diagnostic information for IBM support.

  • To gather comprehensive diagnostic information for the database MYDB:

db2support /home/db2inst1/db2support_output -d MYDB -h -c -s -m -o /home/db2inst1/db2support_output

Note: Running db2support on a heavily loaded system may impact performance. It is advisable to run this during a maintenance window or during off-peak hours if possible.

  • To collect diagnostic information for the database for as specific date range

db2support /home/db2inst1/db2support_output -d MYDB -sf 2024-06-01-00.00.00 -st 2024-06-10-23.59.59 –c

  • -sf 2024-06-01-00.00.00: Specifies the start time (YYYY-MM-DD-HH.MM.SS format).
  • -st 2024-06-10-23.59.59: Specifies the stop time (YYYY-MM-DD-HH.MM.SS format).
  • -c: Collects data from the database.

db2pd: Provides a snapshot of the DB2 instance’s status.

To capture both the application details and the dynamic SQL details.

Capture Application Details: Run the following command to capture application details

db2pd -db MYDB -app

Capture Dynamic SQL Details: Run the following command to capture dynamic SQL details

db2pd -db MYDB -dyn

Combine Application and Dynamic SQL Details: Run the following command to get a combined view of applications and their dynamic SQL statements

db2pd -db MYDB -app –dyn

db2pd -db MYDB -app -dyn > db2pd_output.txt

To find locks in DB2

  • db2pd -db MYDB -locks > locks_output.txt
  • db2pd -db MYDB -locks -app -dyn
  • db2 “LIST APPLICATIONS SHOW DETAIL”
  • db2 “GET SNAPSHOT FOR LOCKS ON MYDB”
  • db2top: Monitors real-time performance metrics.

db2top: Monitors real-time performance metrics.

db2top is a real-time monitor for DB2 databases, providing a continuously updated view of database activity. It allows you to see detailed information about locks, applications, dynamic SQL statements, buffer pools, and more.

Open a terminal and run: db2top -d MYDB

The main screen provides an overview of the database, including the number of active connections, CPU usage, I/O statistics, and more.

Views and Shortcuts

Here are some useful views and their corresponding shortcuts:

  • Applications (a): Lists all active applications and their statuses.
  • Locks (l): Shows information about current locks in the database.
  • Dynamic SQL (d): Displays dynamic SQL statements being executed.
  • Buffer Pools (b): Provides buffer pool statistics.
  • Tablespaces (t): Shows tablespace usage and statistics.
  • Help (h): Displays a list of available commands and shortcuts.
  • Quit (q): Exits db2top.

 

  1. Preventive Measures
  • Regular Backups: Schedule regular backups and test restore procedures.
  • Performance Monitoring: Continuously monitor performance and resource utilization.
  • Update and Patching: Keep DB2 and the underlying OS updated with the latest patches.
  • Documentation: Maintain detailed documentation of the DB2 environment and configurations.