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:
- Single diagnostic log file (db2diag.log): DEFAULT behaviour. This is single diagnostic file that grows indefinitely.
- 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*****
#This script archives DB2 diag log to /home/db2inst1/ravi/diaglog directory
if [ -f /mnt/db2inst1/sqllib/db2profile ]; then
db2diag -A /home/db2inst1/ravi/diaglog > /dev/null
db2diag: Moving “/home/db2inst1/sqllib/db2dump/db2diag.log”
Note: The below paragraph about “-A” option was extracted from below link:
-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”