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
  2. 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
  • 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.

DB2 Troubleshooting Guide