Posted by nick @ 4:46 pm on September 8th 2008

Top 5 SQL statements

Or may be top 10. Or 3. Whatever the number, we are often looking for the worst offenders kicking up the server’s CPU utilisation or I/O wait time to the skies. DB2 built-in snapshot functions are a great help. Run “select * from table (snapshot_dyn_sql('YOURDB', -1)) t order by rows_read desc fetch first 5 rows only” and you will get a list of the queries retrieving the most data. The only thing is, snapshot functions provide, well, snapshots of the DB2 monitor data and are not by themselves suitable for the collection of historical data. Monitor counters can be reset without your knowledge, for example when the database is deactivated or when the SQL statement expires from the package cache.

To ensure continuity of the data collected by snapshot functions we can quickly create a table where we will store historical snapshot information:

create table DYNSQLDATA as (select * from table (snapshot_dyn_sql('YOURDB', -1)) t) with no data

We will then insert output of the snapshot function into this table at regular intervals:

insert into DYNSQLDATA select t.* from table (snapshot_dyn_sql('YOURDB', -1)) t

Now we can easily determine which statements demand most resources and analyze their historical performance. (more…)

Posted by nick @ 9:54 am on January 23rd 2008

Automatic monitoring of the SSL certificate expiration date

This is not really about database administration, but one of the problems I often face is monitoring of the expiration of SSL certificates on my clients’ web servers. It usually takes some time to renew a certificate, and it helps to know in advance that I need to get the process started.Here’s a little script that checks the certificate on a given web server and sends a reminder if it is about to expire:

#!/bin/bash# checks the ssl certificate expiration date of a given host
# Usage: ./checksslcert.sh <hostname> [<port>]
# Port defaults to 443 if not specified
test -z "$1" && echo "Usage: $0 <hostname> [<port>]" && exit 0
tempstr=$(openssl s_client -connect $1:${2:-443} 2>/dev/null >$0.log)
test $? -gt 0 && echo "Error accessing SSL certificate on $1" && exit 1
exptime=$(date -d"${tempstr#*=}" +"%s")
expdays=$(((${exptime} - $(date +"%s"))/84400))
echo "SSL certificate on $1 expires in $expdays days"
test $expdays -lt 45 && echo "Do something!" | mailx -s "SSL certificate on $1 expires in $expdays days" admin@domain.com

Run it daily by cron and you will never miss the expiration date again. The script needs the GNU date utility and openssl to be installed. It has been tested under bash, but you can easily modify it to run under other shells.

Posted by nick @ 12:12 pm on January 22nd 2008

Downloading the logrotate script

I’ve been receiving comments recently from readers who have problems opening the logrotate archive. I did check (and re-check) the archive, and I’m absolutely positive that the URL is correct and the file is not corrupt and can be downloaded and opened. The only problem I can see is that when you use Internet Explorer (at least IE6 - did not try it with other version) to download the file, it gets renamed to “logrotatew.tar.tar” for some reason. Apparently, Explorer does not like the original “.tar.gz” extension.

If that happens to you make sure that you rename the downloaded file back to “logrotatew.tar.gz”; after that bsdtar, WinZip, gunzip, and other utilities will know how to deal with the file. As an example, here’s how to use bsdtar if you saved the file in c:\temp:

bsdtar -xvzf c:\temp\logrotatew.tar.gz

Posted by nick @ 3:44 pm on March 12th 2007

Poor man’s logrotate for Windows

Have you ever been bothered by the db2diag.log growing out of control? I have. While on Linux and Unix you have nice tools like logrotate and its analogs written in a number of script languages, no such luck if you run DB2 on Windows. There is no Windows port of logrotate, and your MSCE colleagues don’t always look favourably at you trying to install ActivePerl or Cygwin on a production server.

Having suffered enough from Notepad not being able to open a 300 megabyte db2diag.log, I have written a Windows command script to rotate the DB2 diagnostic log file. It uses only built-in Windows commands and therefore can run on any out of the box Windows 2000, Windows XP, or Windows 2003 system. By the way, it should work for any log files (with some limitations), not necessarily those generated by DB2.

(more…)

Posted by nick @ 10:38 am on February 19th 2007

Defining different TSM options for multiple DB2 instances

I had been struggling with an obscure problem recently. I needed to set up several DB2 instances on a Microsoft Cluster Server and configure them for TSM backup and log archiving. That would have been a relatively easy task if it were not for the fact that those instances belonged to different cluster resource groups. Each group had its own virtual IP address and host name, and could be brought online or moved to another cluster node independently. For this reason each resource group required a separate TSM node defined for it, which, in turn, called for a separate set of TSM configuration options.

(more…)

Posted by nick @ 9:31 pm on December 7th 2006

HTML documentation for a database schema

table Some time ago I was looking for a “quick and dirty” way of generating HTML documentation of one of my clients’ database schema. I didn’t need an ER diagram - just a list of tables to insert into a word document. At that time TOAD for DB2 did not exist, so I could not use it for my purpose.

Eventually, I ended up creating a simple solution for that simple problem, using a SQL script fetching information from the database catalog and an XSL template to transform its output into HTML, similar to this.
(more…)

Posted by nick @ 6:23 pm on December 4th 2006

Fixpak 14 for DB2 UDB v8 is out

It contains, among other things, a fix for the Daylight Savings Time (DST) change. USA and Canada will change the effective date of DST in March, 2007. By that time you should make sure the operating system supports the change and install the fixpak. This also concerns DB2 9, for which Fixpak 2 is available.

The complete list of fixes can be found here.