Daily Archives: January 14, 2010

Needles in a Haystack

I recently posted snippets for finding and formatting DB2 event monitor files for a deadlock.  OK, so now what?  Once you get these often voluminous outputs, how do you quickly get to the bottom of it?  That question came up this evening.

Sometimes just grepping out the SQLs will reveal enough about what the offending application was doing to trigger a good aha moment.  That can be done simply with:

grep “Text” dl1.txt

Or, if in Windows without grep or cygwin:

find “Text” dl1.txt

Often, though, a little more context is needed.  If there are multiple deadlocks in the file, adding the Deadlock Event headers will separate them.  Adding the participant IDs will show who did what and how the SQLs are crossed.  And adding line numbers will provide places to jump to when opening the file in an editor to drill in further.  That command is quick and easy:

grep -n -e “Text” -e “Deadlock Event” -e “Participant no.” dl1.txt

And, of course, toss it to a file if needed for more convenient viewing:

grep -n -e “Text” -e “Deadlock Event” -e “Participant no.” dl1.txt > dl1-out.txt

Happy hunting!