DB2 LUW: archive db2diag.log file (Script)

What is db2diag.log?

db2diag.log is the primary log intended for use by database and system administrators for troubleshooting purposes.

Note: For Oracle folks, this diag log is equivalent to alert log.

2 types of db2diag.log:

db2diag.log is available in 2 forms:

  1. Single diagnostic log file (db2diag.log): DEFAULT behaviour. This is single diagnostic file that grows indefinitely.
  2. Rotating diagnostic log files (db2diag.N.log): New log will be created after it reaches a pre set size (using diagsize DB configuration parameter). If I set, diagsize as 100MB, a new log file will be created (db2diag.1.log, db2diag.2.log, etc) for every 100 MB size.

Most of the environments use Option:(1). i.e., Single diagnostic log file only.

But, the challenge with this single diagnostic log file is it’s growing size. Once, the size becomes huge, it will be very hard to handle/vi this file.

So, its required to periodically archive this single diagnostic file. To solve this problem, there is a tool named “db2diag” is available from IBM DB2.

All we got to do is: schedule a script like below for every 24 hours once to archive db2diag.log to a safe location.

*****The below script is tested on AIX platform*****

#!/bin/sh
#This script archives DB2 diag log to /home/db2inst1/ravi/diaglog directory
#Author: Ravi
#Date: XX/XXX/XXXX

if [ -f /mnt/db2inst1/sqllib/db2profile ]; then
. /mnt/db2inst1/sqllib/db2profile
fi
db2diag -A /home/db2inst1/ravi/diaglog > /dev/null

****
Output:
db2diag: Moving “/home/db2inst1/sqllib/db2dump/db2diag.log”
to “/home/db2inst1/ravi/diaglog/db2diag.log_2014-06-02-03.09.49”

****

Note: The below paragraph about “-A” option was extracted from below link:

https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0011728.html

-A | -archive dirName
Archives both single and rotating diagnostic log files. When this option is specified, all other options are ignored. If one or more file names are specified, each file is processed individually. A timestamp, in the format YYYY-MM-DD-hh.mm.ss, is appended to the file name.

You can specify the name of the file and directory where it is to be archived. If the directory is not specified, the file is archived in the directory where the file is located and the directory name is extracted from the file name.

If you specify a directory but no file name, the current directory is searched for the db2diag log file. If found, the file will be archived in the specified directory. If the file is not found, the directories specified by the diagpath and alt_diagpath configuration parameters are searched for the db2diag log file. If found, it is archived in the directory specified.

If you do not specify a file or a directory, the current directory is searched for the db2diag log file. If found, it is archived in the current directory. If the file is not found, the directories specified by the diagpath and alt_diagpath configuration parameters are searched for the db2diag log file. If found, it is archived in the directory specified by the diagpath or alt_diagpath configuration parameter.

Starting with Version 9.7, Fixpack 4, the db2diag –archive option is available with IBM® Data Server Driver Package and IBM Data Server for ODBC and CLI. This option enables you to archive the diagnostic log file on an instance-less client. For example:

$ db2diag -A
db2diag: Moving “/home/usr1/clidriver/db2dump/db2diag.log”
to “/home/usr1/clidriver/db2dump/db2diag.log_2010-09-14-01.16.26”

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: