Lock Monitor Script ( WAS file:///C|/WINDOWS/DSP_STAL.TXT)
Posted in 1995
Topics: SQL Development & Query Writing, Stored Procedures & SPL, Server Administration, Platform-Specific Issues
Sorry for the earlier posting. The 'Mail Document' option did not
work as i expected it to.
Anyway, here is the script.(Please remove the > character at the beginning
of each line).
In case of any bugs/suggestions for improvmenets, please e-mail me
at rsundara@auhp30.amd.com.
Thanks
Raj
> #!/bin/ksh
> #========================================================================#
> #Display Stalled Process Information
>
> # 0. Runs on HP-UX and Informix-Online 5.x
>
> # 1. Environment Variables:
>
> # DATAAREA: Set this variable to point to the directory where
> # the data files will be created.
>
> # 2. Input File: partnum.dat (in $DATAAREA)
>
> # 3. Input File Format: table_name, partition_number (hex_value)
> # sorted on ascending partition_number.
>
> # 4. Creating the input file:
>
> # Redirect the output of the following query to a file (partnum.int)
> # select tabname, hex(partnum) p from systables order by p;
>
> # The dbaccess output has a 0x prefix for the hex partition_number.
> # Remove the 0x prefix from all partition numbers and save the file
> # as partnum.dat.
>
> # Whenever you add/drop a table from the database, regenerate this file.
>
> # 5. Output File: lockstatus.dat (in $DATAAREA)
>
> # 6. Output File Format:
> # Name of User waiting on a lock, address of lock, Name of lock owner,
> # Name of Table on which lock is held, rowid of the row on which the lock is
> # held , lock type. (Rowid and lock address are in hex).
>
> # 7. Displaying the stalled process info
>
> # I use a C program to read the lock status file and format the output
> # ("%s %s %s %s %s %s", username, lockaddr, owner, tabname, rowid, locktype)
>
>
> #=========================================================================#
> clean_up_tmp()
>
> rm -f $DATAAREA/waitproc.* 1>/dev/null 2>&1
> rm -f $DATAAREA/lck.* 1>/dev/null 2>&1
> rm -f $DATAAREA/lockinfo.* 1>/dev/null 2>&1
> rm -f $DATAAREA/lockstatus.* 1 >/dev/null 2 >&1
>
>
> get_lock_info()
>
> #==============================================================
> #userproc(useraddress, userid)
> #Get current list of users from tbstat -u
> #Sort on Useraddress
> #===============================================================
> tbstat -u|awk '
> $1=="Users" { flg_users=1;next}
> $1=="address" && flg_users== 1 { flg_users=2; next}
> $2=="active," {flg_users=0}
> flg_users==2 { print $1, " ", $4}' | sort -o $DATAAREA/userproc.dat -k 1,1
>
> #==============================================================
> #waitproc(userid, *lockaddress*)
> #Extract the list of stalled processes
> #==============================================================
> tbstat -u | awk '
> substr($2,1,1) == "L" {print $4," ",$6}' | sort -o $DATAAREA/waitproc.dat -k 2,2
>
> NUMWAIT=`cat $DATAAREA/waitproc.dat | wc -l` #Count of Stalled processes
> if [ $NUMWAIT -eq 0 ]
> then
> echo "No Stalled Processes"
> return
> fi
>
> #lck(lockaddress, owner, *partnum*, rowid, locktype)
> tbstat -k | awk '
> $1=="address" { flg_lckstart=1; next}
> $2=="active," { flg_lckstart=0}
> flg_lckstart==1 { print $1, " ", $3, " ", $6, " ", $7, " ", $5 } ' | sort -o $DATAAREA/lck.dat -k 3,3
>
> #lockinfo(*lockaddress*, owner, partnum, tablename, rowid, locktype)
> join -1 3 -2 2 -o 1.1 1.2 1.3 2.1 1.4 1.5 $DATAAREA/lck.dat $DATAAREA/partnum.dat | sort -o $DATAAREA/lockinfo.dat -k 1,1
>
> #lockstatus(userid, lockaddress, *owner*, tablename, rowid, locktype)
> join -1 2 -2 1 -o 1.1 2.1 2.2 2.4 2.5 2.6 $DATAAREA/waitproc.dat $DATAAREA/lockinfo.dat | sort -o $DATAAREA/lockstatus.int -k 3,3
>
> join -1 1 -2 3 -o 2.1 2.3 1.2 2.4 2.5 2.6 $DATAAREA/userproc.dat $DATAAREA/lockstatus.int > $DATAAREA/lockstatus.dat
>
>
> #start script here
>
> #===============================================================
> #Uncomment the IF section here if you wish to run the lock monitor
> #in a loop.
> #Set LOOPMODE to "Y" and INTVL to sleep time (in secs)
> #================================================================
> #if [ "$LOOPMODE" = "Y" ]
> #then
> # while true
> # do
> # clean_up_tmp
> # echo "Starting Lock monitor, Press CTRL-C to end"
> # RTIME=`date +%T`;export RTIME
> # get_lock_info
> # if [ $NUMWAIT -gt 0 ]> # then
> # $EXEAREA/dsp_stats.exe "STALL" "$DATAAREA/lockstatus.dat"
> # fi
> # sleep $INTVL
> # done
> #else
> clean_up_tmp
> get_lock_info
> if [ $NUMWAIT -gt 0 ]
> then
> #=======================================================================
> # Insert Code here to display the output file ;
> #========================================================================
> more $DATAAREA/lockstatus.dat #replace this with your display code.
> fi
> #fi