Perl Script xmpTerm.pl to list or terminate DB2 connections
xmpTerm.pl provides following functions …
- lists all databases (local and remote) at current DB2 instance
- lists all connections at the DB2 instance, or only those connected to a specified database
- terminates all connections, or only those connected to a specified database, or a specific thread id
Options supported:
- -l: (deflt. option) display all threads
- -d {dbname|*}: display threads on distinct or all databases
- -t {id|*}: terminate distinct thread id or all threads (on database or instance)
- -a LOCKS: display locks
#!/usr/local/bin/perl -w
################################################################################
# xmpTerm.pl - Display or Terminate DB2 Application Threads
# Called by - Command Level or DBA scripts
# Calls - xmpPerl.pm - xmp DBA Perl Package
# Getopt - Argument Administration
# Env - Access to environment variables
# English - aliases for perl variables and identifiers
# Optionen - xmpTerm.pl -d db|* Display threads on distinct database
# -l (deflt.) Display all threads
# -t id|* Terminate all or distinct Thread(s)
# -a action [LOCKS]
#-------------------------------------------------------------------------------
# Autor - GR /05.01.00 - V1.0 first version
# Changes - GR /23.08.00 - V1.1 terminate * now results in DEACTIVATE DB
# GR /11.09.00 - V1.2 tiny amendment
# GR /26.01.01 - V1.3 try to terminate threads only of local databases,
# changes in comments
# GR /17.07.01 - V1.4 adapted to DB2 V7.1, new xmpPerl.pm
# GR /11.12.01 - V1.5 Logging bei -t
# GR /13.01.03 - V2.0 Retry while deactivating databases, no "die"
# (rc=1) when system w/o databases (SQL1031N)
# GR /29.01.03 - V2.1 Correction on loops/retries for deactivation
# GR /29.01.03 - V3.0 Provide more information
# GR /30.07.03 - V3.1 Provide more information after FORCE looped 3 times
# GR /12.08.03 - V4.0 New option -a LOCKS
# GR /13.01.04 - V4.1 adapted to DB2 V8.1, new xmpPerl.pm
# GR /18.06.04 - V4.2 Show long table and tablespace names
# GR /28.12.06 - V4.3 Amendments for DB2 Version 9
# GR /14.07.11 - V4.4 Amendments for DB2 Version 9.7
# (Infomation: db2 list applications show detail does not provide
# the correct operating system process id (pid).)
# GR /21.09.11 - V4.4.1 Show also system components
#-------------------------------------------------------------------------------
# Comments - PERL5LIB environment variable must point to perlauf perl modules!
# - Check correctness for every software (db2, perl) release change!
# - Do not use * ! Use '*' instead to qualifiy -d database name or -t
# thread id.
################################################################################
################################################################################
# Modules
################################################################################
use strict;
use Getopt::Std;
use vars qw($opt_d $opt_l $opt_t $opt_a);
use xmpPerl;
use Env;
use English;
################################################################################
# Declare/Init
################################################################################
my $VER = "4.4.1";
my $work = ""; # for TS List
my @work; # for TS List
my $work2 = ""; # for Container List
my @work2; # for Container List
my $var;
my $val;
my $f_found; # Flag: found
my $loop = 0; # retry counter V2.1
my $db = 0; # no. of Databases
my %dbname = (); # Databases
my %dbtype = (); # Entry Type
my $t = 0; # no. of Threads
my %t_authid = (); my $f1=""; # Auth ID
my %t_applname = (); my $f2=""; # Application Name
my %t_id = (); my $f3=""; # Thread ID
my %t_applid = (); my $f4; # Application ID
my %t_seq = (); my $f5; # Sequence
my %t_agentno = (); my $f6; # Number of Agents
my %t_node = (); my $f7; # Coordinator Node
my %t_pid = (); my $f8; # Coordinator PID
my %t_status = (); my $f9; # Status
my %t_statchgtm = (); my $fa; # Status Change Time
my %t_dbname = (); my $fb; # Database Name
my %t_path = (); my $fc; # DB Path
my $DB2Version = xmpPerl::getDB2Version; # akt. DB2 Version
my $OS = ucfirst $^O; # operating system
my %t_pcpu = (); my $x1; # CPU usage percentage
my %t_pmem = (); my $x2; # Memory usage percentage
my %t_args = (); my $x3; # Command and arguments
my %t_time = (); my $x4; # execution time
my %t_etime = (); my $x5; # start time
my %t_stat = (); my $x6; # process status
my %t_L_nolocks = (); # Number of locks
my %t_L_objtype = (); my $l1; # Lock Object Type
my %t_L_ts = (); my $l2; # Tablespace
my %t_L_table = (); my $l3; # Schema and Name
my %t_L_mode = (); my $l4; # Lock Mode
my %t_L_status = (); my $l5; # Lock Status
my %t_L_escal = (); my $l6; # Lock Escalation
my %t_L_objid = (); my $l7; # Lock Object ID
################################################################################
# Ausgabe-Formate
################################################################################
format KOPF =
--------------------------------------------------------------------------------
------------------------ LIST OF DB2 THREADS -----------------------------------
DBNAME--------------------------------------------------------------------------
.
#@<<<<<<<*ID.....: @<<<<<<< Path..: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#$fb, $f3, $fc,
# PID ...: @<<<<<<< Node..: @>>>> Seq-No: @>>> Agents: @<<<<<<<<
# $f8, $f7, $f5, $f6,
# Auth-ID: @<<<<<<< Applic: @<<<<<<<<<<<<<<<<<<< Status: @<<<<<<<<<<<<<<<
# $f1, $f2, $f9,
# Appl-ID: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Status Change: @<<<<<<<<<<<<<<<
# $f4, $fa,
# CPU%...: @<<<<<<< Mem% .: @<<<< Cmd ..: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# $x1, $x2, $x3
# Time ..: @<<<<<<< Start : @<<<<<<<<<<<<< Status: @<<<<<
# $x4, $x5, $x6
format ZEILE =
@<<<<<<<*ID.....: @<<<<<<< Path....: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$fb, $f3, $fc,
Auth-ID: @<<<<<<< Appl-ID.: @<<<<<<<<<<<<<<<<<<<<<<<<< Node..: @<<<<<<<
$f1, $f4, $f7,
Agents.: @<<<<<<< Applicat: @<<<<<<<<<<<<<<<<<<<<<<<<< Seq-No: @<<<<<<<
$f6, $f2, $f5,
Status.: @<<<<<<<<<<<<<<<<< Change: @<<<<<<<<<<<<<<<<< Active: A or S
$f9, $fa,
PID....: @<<<<<<< Command.: @<<<<<<<<<<<<<<<<<<<<<<<<< Status: @<<<<<<<
$f8, $x3, $x6,
CPU %..: @<<<<<<< Memory %: @<<<< Elapsed: @<<<<<<<< Time..: @<<<<<<<
$x1, $x2, $x5, $x4
.
format LOCKSKOPF =
-------- List of Locks for current Agent ------------------------------
.
# *Lock...: @<<<<<<< Table...: @<<<<<<<<<<<<<<<<<<<<<<<<< TSpace: @<<<<<<<
# $l1, $l3, $l2,
# Obj-ID. @<<<<<<< Status..: @<<<<<< Escalat: @<<<<<<< Mode..: @<<<<<<<
# $l7, $l4, $l6, $l5
format LOCKSZEILE =
*Lock...: @<<<<<<< Obj-ID..: @<<<<<<<<<<<<<<< Mode....: @<<<<<<<<<<<<<<<
$l1, $l7, $l5,
Table..: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TSpace..: @<<<<<<<<<<<<<<<
$l3, $l2,
Status.: @<<<<<< Escalat'n: @<<<<<<
$l4, $l6
.
################################################################################
# Argumente/Options prüfen
################################################################################
getopts("d:lt:a:");
if (( defined $ARGV[0] ) and # needs help? V2.1
(( $ARGV[0] eq "?") or
( $ARGV[0] eq "-h"))) {
SaySyntax();
}
if (! defined $opt_d ) { # Datenbank
$opt_d = "*";
}
if ((! defined $opt_l ) and # List Option
(! defined $opt_t ) ) { # Term Option
$opt_l = ""; # List Option ist Default
}
if ((defined $opt_t ) and # Terminate requested
($opt_t ne "*") and # kein * drin
($opt_t !~ /[1234567890]/) ) { # nicht numerisch
print "$0 - specify -t '*'|nn (all threads or specific thread)\n";
SaySyntax();
}
if (defined $opt_a ) { # ACTION option V4.0
if ( ($opt_a !~ /[LlOoCcKkSs]/) # not LOCKS
or (length($opt_a) != 5) ) { # not 5 bytes V4.3
print "$0 - specify option -a LOCKS\n"; # V4.0
SaySyntax(); # V4.0
} # V4.0
else {$opt_a = uc $opt_a;} # uppercase option V4.0
} # V4.0
$opt_d = uc $opt_d; # uppercase database
################################################################################
# Check DB2 existence, write information on DB2
################################################################################
xmpPerl::chkDB2();
xmpPerl::prtHeaderDB2("$0 - List/Terminate DB2 Threads - Version $VER");
print "Database ....................: $opt_d\n";
if (defined $opt_t) {
print "Terminate Threads ...........: $opt_t\n";
}
################################################################################
# Check DB2 Instance Database Directory V1.6
################################################################################
$work = xmpPerl::doCmdOut("db2 list db directory");
@work = split("\n",$work);
if ($work =~ "SQL1031N") {
print ">>> DB2 Instance has no database directory (e.g. like DB2 Admin Server). RC=0\n";
print "***Ende***\n";
exit 0;
}
################################################################################
# DB2 List Database Directory wg. Name
################################################################################
#$work = xmpPerl::doCmdOut("db2 list db directory | grep -i 'database alias' | sort");
$work = xmpPerl::doCmdOut("db2 list db directory | egrep -i 'database alias|entry type'");
undef $/;
@work = split("\n",$work);
#print "$#work lines returned from DB2 List db dir Command.\n";
if ( ($work =~ "not found")
or ($work =~ "nicht gefunden") ) {
die ">>> DB2 Commands (z.B. list db dir) nicht ausführbar!\n".
">>> Meldung: $work\n".
">>> ABEND ";
}
print "Databases im Directory ......: ";
foreach $work (@work) {
($var,$val) = split(" = ",$work);
if ($var =~ "alias") {
$db++;
$dbname{$db} = xmpPerl::trim($val); # Datenbank in Stack legen
# print $dbname{$db}." ";
}
if ($var =~ "entry type") {
$dbtype{$db} = lc xmpPerl::trim($val); # DB Type in Stack legen
print $dbname{$db}."(".$dbtype{$db}.") ";
}
}
print "\n";
if ($db == 0) {
print ">>> This DB2 instance does not contain databases! RC=0\n".
print "***End***\n";
exit 0;
}
################################################################################
# Wenn Database-Name als Argument angegeben, Namen prüfen
################################################################################
if ($opt_d ne "*") {
$work = $db;
$f_found = 0;
for ($db = 1; $db <= $work; $db++) {
if ($dbname{$db} eq $opt_d) {
$f_found = 1;
}
}
if ($f_found==0) {
die ">>> Database $opt_d does not exist at current DB2 instance!\n".
">>> ABEND ";
}
}
################################################################################
# Display Threads
################################################################################
if (defined $opt_l) {
GetThreads();
print "Current Threads at Instance : $t\n";
ReportThreads();
}
################################################################################
# Terminate Threads
################################################################################
if (defined $opt_t) {
############################################################################
# Write informational message to log file
############################################################################
xmpPerl::LogLine("DBA I ".$0." $< $opt_d $opt_t");
############################################################################
# Current Threads
############################################################################
GetThreads();
############################################################################
# Alle Threads abarbeiten
############################################################################
$work = $t;
for ($t = 1; $t <= $work; $t++) {
########################################################################
# Bestimmter Thread oder alle Threads in allen DB's oder bestimmter DB
########################################################################
#print "XXX ".$t_id{$t}." ".$t_dbname{$t}." XXXX\n";
if ( ( ($opt_t eq "*")
or ($t_id{$t} == $opt_t) )
and ( ($opt_d eq "*")
or ($t_dbname{$t} eq $opt_d ) ) ) {
ForceThread($t_id{$t});
}
}
############################################################################
# Wenn alle Threads forced (alle überhaupt oder einer DB)
############################################################################
if ($opt_t eq "*") {
DeactivateDatabase();
}
############################################################################
# Buffer Flush
############################################################################
$work = xmpPerl::doCmdOut("db2 terminate");
#print "AAAAA $work\n";
}
################################################################################
# Display Threads erneut nach Terminate Threads
################################################################################
if ((defined $opt_l) and
(defined $opt_t) ) {
GetThreads();
ReportThreads();
}
print "***Ende***\n";
exit 0;
################################################################################
########################################################## Sub Routines ########
# SaySyntax ####################################################################
sub SaySyntax {
die "Usage: [perl] $0 -d [db|'*'] [-l] [-t id|*] [-a {LOCKS}]\n".
" -d db|'*' database name\n".
" -l display thread(s) (default option)\n".
" -t id|'*' terminate thread(s)\n".
" -a LOCKS display lock information\n".
"abends";
}
################################################################################
# Alle oder nur best. DB-Threads ermitteln und Daten intern speichern
################################################################################
sub GetThreads {
my $work;
my $work2;
my $startpos = 9; # Dflt. Start
$t = 0;
############################################################################
# Starting position in DB2 command output is version-dependent!
############################################################################
if ($DB2Version =~ "5") {$startpos=9} # Version 6 17.07.2001
if ($DB2Version =~ "6") {$startpos=9} # Version 6 17.07.2001
if ($DB2Version =~ "7") {$startpos=31} # Version 7 17.07.2001
if ($DB2Version =~ "8") {$startpos=31} # Version 8 13.01.2004
if ($DB2Version =~ "9") {$startpos=31} # Version 9 28.12.2006
if ($DB2Version =~ "9.7") {$startpos=129} # Version 9.7 14.07.2011
############################################################################
# DB2 List Applications show detail
############################################################################
$work = xmpPerl::doCmdOut("db2 list applications show detail");
undef $/;
@work = split("\n",$work);
#print "$#work lines returned from DB2 List Applications Command.\n";
if ($#work == 0) {return}
$f_found = 0;
foreach $work (@work) {
#($f1,$f2,$f3,$f4,$f5,$f6,$f7,$f7,$f9,$fa,$fb,$fc) = split(" ",$work);
if (length($work) > 0) {
####################################################################
# Diese folgenden Bedingungen sind Versions-abhängig!
####################################################################
$f1 = substr($work,0,8); # Authid
$f2 = substr($work,$startpos,20); # Appl. Name
$f3 = substr($work,$startpos+21,10); # Appl. Handle
$f4 = substr($work,$startpos+32,30); # Appl. ID
$f5 = substr($work,$startpos+63,4); # Seq. No
$f6 = substr($work,$startpos+68,10); # No Agents.
if ($DB2Version =~ "9") { # 28.12.2006
$f4 = substr($work,$startpos+32,62); # Appl. ID
$f5 = substr($work,$startpos+95,5); # Seq. No
$f6 = substr($work,$startpos+101,10); # No Agents.
$f7 = substr($work,$startpos+112,16); # Coord. Node
$f8 = substr($work,$startpos+129,15); # Coord PID/Thread
if (length($work) >= $startpos+145) {
$f9 = substr($work,$startpos+145,30)} # Status
else { $f9 = "n/a" }
if (length($work) >= $startpos+176) {
$fa = substr($work,$startpos+176,26)} # Status Change
else { $fa = "n/a" }
if (length($work) >= $startpos+203) {
$fb = substr($work,$startpos+203,8)} # DBNAME
else { $fb = "n/a" }
if (length($work) >= $startpos+212) {
$fc = substr($work,$startpos+212)} # DB Path
else { $fc = "n/a" }
}
elsif ($DB2Version =~ "8") { # 13.01.2004
$f7 = substr($work,$startpos+79,16); # Coord. Node
$f8 = substr($work,$startpos+92,15); # Coord PID/Thread
if (length($work) >= $startpos+112) {
$f9 = substr($work,$startpos+112,30)} # Status
else { $f9 = "n/a" }
if (length($work) >= $startpos+143) {
$fa = substr($work,$startpos+143,26)} # Status Change
else { $fa = "n/a" }
if (length($work) >= $startpos+170) {
$fb = substr($work,$startpos+170,8)} # DBNAME
else { $fb = "n/a" }
if (length($work) >= $startpos+179) {
$fc = substr($work,$startpos+179)} # DB Path
else { $fc = "n/a" }
}
else {
$f7 = substr($work,$startpos+79,12); # Coord. Node
$f8 = substr($work,$startpos+92,15); # Coord PID/Thread
if (length($work) >= $startpos+108) {
$f9 = substr($work,$startpos+108,30)} # Status
else { $f9 = "n/a" }
if (length($work) >= $startpos+139) {
$fa = substr($work,$startpos+139,26)} # Status Change
else { $fa = "n/a" }
if (length($work) >= $startpos+166) {
$fb = substr($work,$startpos+166,8)} # DBNAME
else { $fb = "n/a" }
if (length($work) >= $startpos+175) {
$fc = substr($work,$startpos+175)} # DB Path
else { $fc = "n/a" }
}
}
#print length($work)."$f1 $f2 $f3\n";
#print "$f7 # $f8 # $f9 # $fa # $fb # $fc #\n";
########################################################################
# Wenn Ausgabedaten lokalisiert werden konnten
########################################################################
# && ($f5 ne "00001") ) { # no systems components V4.4.1
if ($f_found) {
#print "eingetragen\n";
$t++;
$t_authid{$t} = $f1; # Auth ID
$t_applname{$t} = $f2; # Application Name
$t_id{$t} = xmpPerl::trim($f3); # Thread ID
$t_applid{$t} = $f4; # Application ID
$t_seq{$t} = $f5; # Sequence
$t_agentno{$t} = $f6; # Number of Agents
$t_node{$t} = $f7; # Coordinator Node
$t_pid{$t} = xmpPerl::trim($f8); # Coordinator PID
$t_status{$t} = $f9; # Status
$t_statchgtm{$t}= $fa; # Status Change Time
$t_dbname{$t} = xmpPerl::trim($fb); # Database Name
$t_path{$t} = $fc; # DB Path
####################################################################
# retrieve operating system information
####################################################################
$t_pcpu{$t} = getPSval($t_pid{$t},'pcpu');
$t_pmem{$t} = getPSval($t_pid{$t},'pmem');
$t_args{$t} = getPSval($t_pid{$t},'comm');
$work2 = getPSval($t_pid{$t},'args');
if ($t_args{$t} ne $work2) {$t_args{$t} .= " ".$work2;}
$t_time{$t} = getPSval($t_pid{$t},'time');
$t_etime{$t} = getPSval($t_pid{$t},'etime');
$t_stat{$t} = "";
if ($OS eq "Aix") { $t_stat{$t}=getPSval($t_pid{$t},'stat'); }
if ($OS eq "Solaris") { $t_stat{$t}=getPSval($t_pid{$t},'s'); }
####################################################################
# retrieve lock information if requested V4.0
####################################################################
if ( (defined $opt_a)
&& ($opt_a eq "LOCKS") ) {
getLocks($t_id{$t});
}
}
########################################################################
# Jetzt gehts mit echten Daten los
########################################################################
if ($f1 eq "--------") {
$f_found = 1;
}
}
}
################################################################################
# Write formated list of threads
################################################################################
sub ReportThreads {
my $work;
my $work2;
$FORMAT_NAME = "ZEILE"; # $~
$FORMAT_TOP_NAME = "KOPF"; # $^
$FORMAT_FORMFEED = ""; # $^L
$FORMAT_LINES_PER_PAGE = ($t*8)+3; # $=, plus Lines für Kopf
$FORMAT_LINES_LEFT = 0; # vorhergeh. Format
$work = $t;
for ($t = 1; $t<=$work ; $t++) {
$FORMAT_NAME = "ZEILE"; # $~
$FORMAT_TOP_NAME = "KOPF"; # $^
$f1 = $t_authid{$t}; # Auth ID
$f2 = $t_applname{$t}; # Application Name
$f3 = $t_id{$t}; # Thread ID
$f4 = $t_applid{$t}; # Application ID
$f5 = $t_seq{$t}; # Sequence
$f6 = $t_agentno{$t}; # Number of Agents
$f7 = $t_node{$t}; # Coordinator Node
$f8 = $t_pid{$t}; # Coordinator PID
$f9 = $t_status{$t}; # Status
$fa = $t_statchgtm{$t}; # Status Change Time
$fb = xmpPerl::trim($t_dbname{$t}); # Database Name
$fc = $t_path{$t}; # DB Path
$x1 = $t_pcpu{$t}; # % CPU
$x2 = $t_pmem{$t}; # % Memory
$x3 = $t_args{$t}; # command/args
$x4 = $t_time{$t}; # execution time
$x5 = $t_etime{$t}; # started time
$x6 = $t_stat{$t}; # process status
if ( ($opt_d eq "*")
or ($opt_d eq $fb) ) {
write;
####################################################################
# report lock information if requested V4.0
####################################################################
if ( (defined $opt_a)
&& ($opt_a eq "LOCKS") ) {
ReportLocks($t_id{$t});
}
}
}
}
################################################################################
# Write formated list of locks V4.0
################################################################################
sub ReportLocks {
my $id = $_[0];
my $work;
my $work2;
my $i = 0;
my $t = 0;
#print ">>> locks to report:".$t_L_nolocks{$id}."\n";
if ($t_L_nolocks{$id}==0) {return;} # nothing in table
$FORMAT_NAME = "LOCKSZEILE"; # $~
$FORMAT_TOP_NAME = "LOCKSKOPF"; # $^
$FORMAT_FORMFEED = ""; # $^L
#$FORMAT_LINES_PER_PAGE = ($t_L_nolocks{$id}*2)+2; # $=, plus Lines für Kopf
$FORMAT_LINES_LEFT = 0; # vorhergeh. Format
$work = ($id*1000) + $t_L_nolocks{$id}; # max range value
for ($t = (($id*1000)+1); $t<=$work ; $t++) {
#print ">>> reporting entry $t\n";
$l1 = $t_L_objtype{$t}; # Lock Object Type
$l2 = $t_L_ts{$t}; # Tablespace
$l3 = $t_L_table{$t}; # Schema and Name
$l4 = $t_L_mode{$t}; # Lock Mode
$l5 = $t_L_status{$t}; # Lock Status
$l6 = $t_L_escal{$t}; # Lock Escalation
$l7 = $t_L_objid{$t}; # Lock Object ID
#print ">>> TO WRITE: $l1 $l2 $l3 $l4 $l5 $l6 $l7 \n";
write
}
}
################################################################################
# Eine oder alle Datenbanken deaktivieren
################################################################################
sub DeactivateDatabase {
my $work;
my $work2;
############################################################################
# Distinct database or all?
############################################################################
if ($opt_d ne "*") {
$work = xmpPerl::doCmdOut("db2 deactivate db $opt_d");
#print "YYYYYY $work\n";
print "Database deactivated ........: ";
if (($work =~ 'DB20000I') or
($work =~ 'SQL1496W') or
($work =~ 'DB21024I') ) {
print "$opt_d successful\n";
$loop = 0;
}
else {
####################################################################
# Deactivation failed V2.0
####################################################################
$loop++;
print "$opt_d unsuccessful ($loop. pass)\n";
print "$work\n";
GetThreads(); # V3.1
print "Current Threads at Instance : $t\n"; # V3.1
ReportThreads(); # V3.1
####################################################################
# Try 3 times V2.0
####################################################################
if ($loop <=2) {
DeactivateDatabase();
}
}
}
else {
########################################################################
# All databases in DB drectory
########################################################################
$work = $db;
for ($db = 1; $db <= $work; $db++) {
####################################################################
# Local database?
####################################################################
if ($dbtype{$db} eq "indirect") {
$work2 = xmpPerl::doCmdOut("db2 deactivate db $dbname{$db}");
#print "ZZZZZZZ $work\n";
print "Database deactivated ........: ";
if (($work2 =~ 'DB20000I') or
($work2 =~ 'SQL1496W') or
($work2 =~ 'DB21024I') ) {
print "$dbname{$db} successful\n";
$loop = 0;
}
else {
############################################################
# Deactivation failed V2.0
############################################################
$loop++;
print "$dbname{$db} unsuccessful ($loop. pass)\n";
print "$work2\n";
GetThreads(); # V3.1
print "Current Threads at Instance : $t\n"; # V3.1
ReportThreads(); # V3.1
############################################################
# Try 3 times V2.0
############################################################
if ($loop <=2) {
DeactivateDatabase();
}
}
}
else {
print "Database not deactivated ....: ".$dbname{$db}." is not local\n";
}
}
}
}
################################################################################
# Force Distinct Thread
################################################################################
sub ForceThread {
my $work;
my $work2;
$work2 = "db2 force application '(' ".$_[0]." ')'";
#print "FFFFFFF $work2\n";
$work = xmpPerl::doCmdOut($work2);
#print "GGGGGG $work\n";
print "Thread ID=".$_[0]." terminated ....: ";
if (($work =~ 'DB20000I') or
($work =~ 'DB21024I') ) {
print "successful\n";
}
else {
print "unsuccessful\n";
print "$work\n";
}
}
################################################################################
# getPSval: provides operating system information for specific PID
################################################################################
sub getPSval {
my $pid = $_[0];
my $req = $_[1];
my $val = "";
my $awk = " ";
############################################################################
# awk: print 2nd word if 1st word contains process id
############################################################################
$awk = "awk '\$1 ~ /$pid/ {print \$2}'";
############################################################################
# ps: print process id and any other option for just one specific pid
############################################################################
$val = xmpPerl::doCmdOut("ps -efo 'pid $req' | grep $pid | $awk");
$val = xmpPerl::trim($val);
return $val;
}
################################################################################
# getLocks: Start SNAPSHOT for lock information V4.0
################################################################################
sub getLocks {
my $id = $_[0];
my $work;
my @work;
my $f_found = 0;
my $t;
############################################################################
# DB2 SNAPSHOT
############################################################################
$work = xmpPerl::doCmdOut("db2 get snapshot for locks for application agentid $id");
undef $/;
@work = split("\n",$work);
#print "$#work lines returned from DB2 SNAPSHOT Command.\n";
############################################################################
# DB2 SNAPSHOT w/o result
############################################################################
if ($#work == 1) {
return;
}
$t_L_nolocks{$id}= 0;
$t = $id * 1000; # beginn range
$t_L_objtype{$id} = "";
$t_L_ts{$id} = "";
$t_L_table{$id} = "";
$t_L_mode{$id} = "";
$t_L_status{$id}= "";
$t_L_escal{$id} = "";
############################################################################
# Process DB2 SNAPSHOT output
############################################################################
nextline: foreach $work (@work) {
########################################################################
# Split line, remove leading and trailing blanks
########################################################################
($var,$val) = split("=",$work);
if (! defined $var) {$var = "";}
if (! defined $val) {$val = "";}
if (length($var) > 60) {
($var,$val) = split(":",$work);
if (! defined $var) {$var = "";}
if (! defined $val) {$val = "";}
}
if ( ($var eq "") and ($val eq "") ) {next nextline};
if ( $work =~ "SQL1611W") {next nextline}; # no data
$var = uc xmpPerl::trim($var);
$val = xmpPerl::trim($val);
#print "$var=$val\n";
########################################################################
# Try to detect and extract specific information
########################################################################
if ( $var =~ "LOCKS HELD") {
$t_L_nolocks{$id} = $val;
next nextline;
}
if ( $var =~ "OBJECT NAME") {
$t++;
$t_L_objid{$t} = $val;
#print ">>> Extracted: $t \n";
next nextline;
}
if ( $var =~ "OBJECT TYPE") {
$t_L_objtype{$t} = $val;
next nextline;
}
if ( $var =~ "TABLESPACE") {
$t_L_ts{$t} = $val;
next nextline;
}
if ( $var =~ "TABLE SCHEMA") {
$t_L_table{$t} = xmpPerl::trim($val);
next nextline;
}
if ( $var =~ "TABLE NAME") {
$t_L_table{$t} = $t_L_table{$t}.".".xmpPerl::trim($val);
next nextline;
}
if ( $var =~ "MODE") {
$t_L_mode{$t} = $val;
next nextline;
}
if ( $var =~ "STATUS") {
$t_L_status{$t} = $val;
next nextline;
}
if ( $var =~ "ESCALATION") {
$t_L_escal{$t} = $val;
next nextline;
}
}
#print ">>>AT END OF EXTRACTION: $t\n";
}
 Any suggestions – don’t hesitate to contact me!


Comments
Comments are closed.