Triton Db2 Geek

Confessions of a DB2 geek

IBM Gold Consultant Program and IBM Premier business Partner

Nanu, Nanu, DB2 calling you!

January 30th, 2014 - by

By Klaas Brant

Do you remember the Mork and Mindy show? Mork made a connection with Orson using his famous sentence “Nanu, Nanu, come in Orson” in order to report what was going on. If this does not sound familiar it simply means you are not as old as I am! The reason I bring it up is because I thought it would be nice if DB2 would report automatically to you what has been going on in the last 24 hours. Interested? Then keep reading, this is how to do it.


DB2 keeps track of problems in the DB2DIAG log, depending on the setting DIAGLEVEL in the instance configuration. It is nice to have it at level 3 so you have enough information in case you have to investigate problems. If that is too much information then set it to 1 or 2. Be careful not to set it to 4 because you will be overloaded with messages. At level 4, you get every possible message, which is helpful for a short period of time when you are recreating a problem, but far too much for production.


You will probably want to use email for your error reporting. But mailing  the complete DB2DIAG log  is too much data. You probably won’t have the time to read all the details. So you need a way to get the messages out which really matter. This is where the DB2DIAG command comes in handy. It is an amazing command with a wealth of options (type db2diag -? for more info). Use the option -level “Severe, Error” to filter and give back only messages flagged as Error or Severe.  The command looks like this: db2diag -level “Severe, Error”. Just try it and see what it produces.


To have the result sent to you as an email you need to create a little shell script. In order to work correctly from a script you need to add an option to the db2diag command which is –readfile. You might also consider to add –H (look in the manual for options) to limit the timeframe to report. With use of the mail command you can send the results to your email address. The script looks like this:




subject=”DB2 calling home…”

/home/db2inst1/sqllib/bin/db2diag -readfile -level “Severe, Error” | mail -s “$subject” $recipients


As you can see the db2diag command has a full path.  That is so you can add the script to the crontab.  Anything running from the crontab only has the default path and not the DB2 path.


All you have  left to do is to add the script to the crontab.  How to do that differs in every Linux / UNIX implementation. Just ask somebody to assist you if you are unsure. If you want to further enhance the script, have a look at the –A of the db2diag command to archive your db2diag log.


That is all you need to do. Hopefully you won’t get too many messages! But it is always good to know when things are working properly. An ounce of prevention is worth a pound of cure.  Is it 100% guaranteed? No, there are many messages by DB2 which are not flagged as Error or Severe but still are informative or may need your attention.


This works for a Linux / UNIX implementation, but what if you have Windows? Well, that is more difficult.  Windows does not have a mail command and the equivalent of a crontab does exist,  but is much more difficult to configure. Let us know if you are interested in how this can be done and I might write another blog on it.



  • Chris Fierros says:

    Actually there is a MAIL program that comes with DB2 for LUW. I’ve been using it for well over a decade, since v8.1. It’s called ASNMAIL, you can find it in the \bin\ folder regardless of which flavor of DB2 for LUW you happen to be running it will be there.

    As for the Window’s Task Scheduler, it couldn’t be much easier to schedule DB2 maintenance and monitoring jobs. It’s called SCHTASKS and you can easily, schedule all of your DB2 jobs with one Windows shell script.

    • Klaas Brant says:

      Hi Chris,

      ASNMAIL is pretty basic and does not allow for attachments. There are free mail programs that do a better job I think. SCHTASK is indeed the easy solution to add something to the windows scheduler.


« »

Tag Archives