Collect SH

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 19

#!

/bin/bash

# sed -i 's/\x0D$//' script


# cat script | tr -d '\015' > script.txt

function absPath
{
if [[ -d "$1" ]]; then
cd "$1"
echo "$(pwd -P)"
else
cd "$(dirname "$1")"
echo "$(pwd -P)/$(basename "$1")"
fi
}

if [ $# -eq 4 ]
then
DBNAME=$1
SDIR=$(absPath "$2")
DPF=$3
APPDHL=$4
elif [ $# -eq 3 ]
then
DBNAME=$1
SDIR=$(absPath "$2")
DPF=$3
APPDHL=-1
elif [ $# -eq 2 ]
then
DBNAME=$1
SDIR=$(absPath "$2")
DPF="N"
APPDHL=-1
elif [ $# -eq 1 ]
then
DBNAME=$1
SDIR=$(absPath `pwd`)
DPF="N"
APPDHL=-1
else
echo "Usage:"
echo " collect.sh <db-name> [SDIR] [DPF] [APPHDL]"
echo "SDIR, DPF and APPHDL are optional, If not given then Data will be
dumped in current directory and Single Node and NO APPHDL is considered"
echo "In DPF, if you want to collect data from single node then say DPF = N"
echo "example:"
echo " collect.sh MYDB /scratch Y/N APPHDL"
exit
fi

####exec 1> >(tee -ia $SDIR/bash.log)


####exec 2> >(tee -ia $SDIR/bash.log >& 2)
####exec &> >(tee -i "$SDIR/output.log")

# Notice no leading $
####exec {FD}> $SDIR/bash.log

# If you want to append instead of wiping previous logs


#exec {FD}>> $2/bash.log

####export BASH_XTRACEFD="$FD"

#set -xv

function collect_data
{
DUMPDIR=$1
X1=`date '+%Y-%m-%d-%H.%M.%S'`
TS=$X1

mkdir -p $DUMPDIR
if [ $? -eq 0 ]; then
chmod 777 "$DUMPDIR"
else
echo "Unable to create directory: $DUMPDIR .. bailing out !!"
exit 0
fi

echo "`date`:Starting to run data collections on host `hostname` in DIR: $DUMPDIR


at $TS"

if [[ $DPF == "Y" ]]
then
rah="rah \"||"
quote="\""
memberall=" -member all "
HOSTS=$( cat $HOME/sqllib/db2nodes.cfg 2>/dev/null | awk '{ print
$2; }' | sort -u )
xquote=" \" "
PREFIX="ps -elf | grep -w "
POSTFIX=" | grep -v grep | awk '{print \\\$4} ' | sort | uniq | tr '\n'
' ' " # \\\$4 is needed to put \$4 in awk command in ssh.

else
rah=""
quote=""
memberall=" "
HOSTS=`hostname`
fi

if [ $APPDHL -gt "0" ]


then
db2pd $memberall -dump all apphdl=$APPDHL dumpdir=$DUMPDIR -rep 5 3 &
else
db2pd $memberall -stack all dumpdir=$DUMPDIR -rep 5 3 &
fi

OS="`uname`"
case $OS in
'Linux')
OS='Linux'
MEMORY='free'
VMSTAT='vmstat -w -t 1 30'
IOSTAT='iostat -xtzk 1 30'
PSTH='ps -elfT'
PSETO='ps -eTo
state,stat,pid,ppid,tid,time,wchan:30,policy,pri,psr,sgi_p,time,command'
TPROF='uname'
TOP='top -b -d 3 -n 2'
MATCHEXECID='x\x27'
PROCSTACK='pstack '
NETSTAT='netstat -an'
;;
'AIX')
OS='AIX'
MEMORY='svmon'
VMSTAT='vmstat -w -t 1 30'
IOSTAT='iostat -RDasl -T 1 30'
PSTH='ps -mo THREAD -elf'
PSETO='ps -mo THREAD -elf'
TPROF="tprof -skeul -r $DUMPDIR/TPROF.report.$TS -x sleep 60"
TOP=''
MATCHEXECID='x\047'
PROCSTACK='procstack '
NETSTAT='netstat -an'
;;
*)
MEMORY='uname'
VMSTAT='uname'
IOSTAT='uname'
PSTH='uname'
PSETO='uname'
TPROF='uname'
TOP='uname'
MATCHEXECID='x\047'
PROCSTACK='uname '
NETSTAT='uname'
;;
esac

echo "`date`: $OS $HOSTS"

eval $rah $VMSTAT $quote > $DUMPDIR/vmstat.$TS &


eval $rah $IOSTAT $quote > $DUMPDIR/iostat.$TS &
eval $rah $MEMORY $quote > $DUMPDIR/free.$TS
eval $rah ls -l /dev/mapper $quote > $DUMPDIR/Mapper
eval $rah ps -elf $quote > $DUMPDIR/ps_elf.$TS
eval $rah $TPROF $quote > $DUMPDIR/TPROF.$TS &
eval $rah $TOP $quote > $DUMPDIR/TOP.$TS &

for j in 1 2 3 4
do
eval $rah $PSTH $quote > $DUMPDIR/ps_thread.$j.$TS
eval $rah $PSETO $quote > $DUMPDIR/psETO.$j.$TS
if [[ $DPF == "Y" ]]
then
for host in `echo $HOSTS`
do
xssh="ssh $host \" "
( eval "$xssh $NETSTAT $xquote" ) >> $DUMPDIR/netstat.$host.
$DB2SYSC_PID.$j.$TS 2>&1
for DB2SYSC_PID in $( eval "$xssh $PREFIX db2vend $POSTFIX
$xquote" )
do
( eval "$xssh $PROCSTACK $DB2SYSC_PID $xquote" ) >>
$DUMPDIR/pstack.$host.$DB2SYSC_PID.$j.$TS 2>&1
done
done
else
i=1 ; while [[ $i -lt 3 ]] ; do for pid in `ps -elf | egrep "db2vend" |
grep -v grep | awk '{ print $4 }'`; do eval $PROCSTACK $pid > $DUMPDIR/procstack.
$pid.$j.$TS.`hostname`.`date '+%Y-%m-%d-%H.%M.%S'` ; eval $NETSTAT >
$DUMPDIR/netstat.$j.$TS.`date '+%Y-%m-%d-%H.%M.%S'`.txt ; done; echo $i ; sleep 5;
((i += 1)) ; done
fi
sleep 2
done

eval $rah db2 update monitor switches using BUFFERPOOL on LOCK on SORT on
STATEMENT on TIMESTAMP on TABLE on UOW on $quote

db2 connect to $DBNAME

db2 "call SYSPROC.SYSINSTALLOBJECTS( 'EXPLAIN', 'C' , '', CURRENT USER )"


db2 "call monreport.dbsummary(30)" > $DUMPDIR/monrpt_dbsummary.$TS &
db2 "call monreport.lockwait" > $DUMPDIR/mon_lockwait.$TS &
db2 "call monreport.connection(30)" > $DUMPDIR/mon_con.$TS &

db2pd $memberall -inst -dbptnmem -alldbs -memsets -mempools -file


$DUMPDIR/db2pdMem.$TS &
db2pd $memberall -edus -file $DUMPDIR/db2pdEdu.$TS -rep 5 3 &
db2pd $memberall -edus interval=5 top=10 -file $DUMPDIR/db2pdEduTOP.$TS &
db2pd $memberall -latches -file $DUMPDIR/db2pdLatches.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -wlocks -file $DUMPDIR/db2pdWlocks.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -locks showlocks -file $DUMPDIR/db2pdShowlocks.$TS -
rep 5 3 &
db2pd -db $DBNAME $memberall -bufferpool -file $DUMPDIR/db2pd_BP.$TS -rep 5 3 &

db2pd -db $DBNAME $memberall -cleaner -file $DUMPDIR/db2pd_cleaner.$TS -rep 5 3 &


db2pd -db $DBNAME $memberall -dirtypages summary -file $DUMPDIR/db2pd_dirtySumm.$TS
-rep 5 3 &

if [ $APPDHL -gt "0" ]


then
db2pd -db $DBNAME $memberall -apinfo $APPDHL metrics -file $DUMPDIR/db2pd.
$APPDHL.apinfo.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -applications $APPDHL -file
$DUMPDIR/db2pd_applications.$APPDHL.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -transactions app=$APPDHL -file
$DUMPDIR/db2pd_transactions.$APPDHL.$TS -rep 5 3 &
db2pd $memberall -age app=$APPDHL -file $DUMPDIR/db2pd_agents.$APPDHL.$TS -
rep 5 3 &
db2pd -db $DBNAME $memberall -active apphdl=$APPDHL -file
$DUMPDIR/db2pd_active.$APPDHL.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -sort apphdl=$APPDHL -file $DUMPDIR/db2pd.sort.
$APPDHL.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -locks app=$APPDHL > $DUMPDIR/db2pd.locks.
$APPDHL.$TS -rep 5 3 &
db2 GET SNAPSHOT FOR APPLICATION AGENTID $APPDHL GLOBAL > $DUMPDIR/appsnap.
$APPDHL.$TS
else
db2pd -db $DBNAME $memberall -apinfo metrics -file $DUMPDIR/db2pd.apinfo.$TS
-rep 5 3 &
db2pd -db $DBNAME $memberall -applications -file $DUMPDIR/db2pd_applications.
$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -transactions -file $DUMPDIR/db2pd_transactions.
$TS -rep 5 5 &
db2pd $memberall -age -file $DUMPDIR/db2pd_agents.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -active -file $DUMPDIR/db2pd_active.$TS -rep 5 3
&
db2pd -db $DBNAME $memberall -sort -file $DUMPDIR/db2pd.sort.$TS -rep 5 3 &
fi

db2pd -db $DBNAME $memberall -load stacks file=$DUMPDIR/db2pd.load.$TS -rep 5 3 &


db2pd -db $DBNAME $memberall -runstats file=$DUMPDIR/db2pd.runstats.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -reorgs index file=$DUMPDIR/db2pd.reorg_index.$TS -
rep 5 3 &
db2pd $memberall -util -file $DUMPDIR/db2pd.util.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -logs -file $DUMPDIR/db2pd.logs.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -extent -file $DUMPDIR/db2pd.extent.$TS -rep 5 3 &
db2pd -db $DBNAME $memberall -tcbstat index -file $DUMPDIR/db2pd.tcbstat.$TS -rep 5
3 &
db2pd $memberall -gfw -file $DUMPDIR/db2pd.gfw.$TS -rep 5 3 &

db2pd -db $DBNAME -memblocks all top $memberall > $DUMPDIR/db2pd.memblocks.all.$TS


&

db2pd -fmpexechistory n=512 genquery $memberall > $DUMPDIR/db2pd.fmphist.$TS &


db2pd -fmp $memberall -rep 5 3 > $DUMPDIR/db2pd.fmp.$TS &

eval $rah db2pd -db $DBNAME -alldbp -fmtlock hashlatch tranlatch


file=$DUMPDIR/db2pd.fmtlock.$TS $quote > $DUMPDIR/db2pd.fmtlock.console.$TS &
db2pd -db $DBNAME $memberall -tablespace -file $DUMPDIR/db2pd.tablespace.$TS &
db2pd -db $DBNAME $memberall -workload -file $DUMPDIR/db2pd.workload.$TS &
db2pd -db $DBNAME $memberall -dynamic -file $DUMPDIR/db2pd_dynamic.$TS &

echo "`date`: dumping MON FUNCTIONS"


db2 "select executable_id,num_executions, total_act_time, total_act_wait_time,
total_extended_latch_wait_time as latch_w_time, total_cpu_time, rows_read,
rows_returned,stmt_text from table(mon_get_pkg_cache_stmt(null,null,null,null))
order by total_extended_latch_wait_time desc fetch first 20 rows only" >
$DUMPDIR/mon_get_pkg_cache_stmt.latch.$TS
db2 "SELECT * FROM TABLE ( MON_GET_LATCH(CLOB('<latch_status>W</latch_status>'), -2
) ) ORDER BY LATCH_NAME, LATCH_STATUS" > $DUMPDIR/get_latch_wait.$TS
db2 "SELECT * FROM sysibmadm.mon_current_sql ORDER BY ELAPSED_TIME_SEC desc" >
$DUMPDIR/mon_get_sql.$TS
db2 "select EXECUTABLE_ID, t.* from table(MON_GET_ACTIVITY(NULL, -2)) as t order by
TOTAL_EXTENDED_LATCH_WAIT_TIME desc" >
$DUMPDIR/EXECUTABLE_ID.LATCH.mon_get_activity.$TS
db2 "select EXECUTABLE_ID, t.* from table(MON_GET_ACTIVITY(NULL, -2)) as t order by
TOTAL_ACT_WAIT_TIME desc" > $DUMPDIR/EXECUTABLE_ID.ACTIVITY.mon_get_activity.$TS
db2 "select
EXECUTABLE_ID,TOTAL_CPU_TIME/NUM_EXEC_WITH_METRICS,TOTAL_CPU_TIME,COORD_STMT_EXEC_T
IME/NUM_EXEC_WITH_METRICS,COORD_STMT_EXEC_TIME,NUM_EXEC_WITH_METRICS, STMT_TEXT
from table(MON_GET_PKG_CACHE_STMT(NULL,NULL,NULL,-2)) where NUM_EXEC_WITH_METRICS
<> 0 order by COORD_STMT_EXEC_TIME/NUM_EXEC_WITH_METRICS desc fetch first 20 rows
only" > $DUMPDIR/elap_top_package_cache.$TS
db2 "select EXECUTABLE_ID, substr(stmt_text,1,250) as stmt_text,
decimal(float(total_extended_latch_wait_time)/num_executions,10,5) as
avg_latch_time from table(mon_get_pkg_cache_stmt(null,null,null,null)) where
num_executions > 0 order by avg_latch_time desc fetch first 10 rows only" >
$DUMPDIR/mon_get_pkg_cache_stmt.Avglatch.$TS
db2 -v "with activity_handles(application_handle , STMT_TEXT) as (select
application_handle, STMT_TEXT from table(mon_get_activity(null,-2)) where
member=coord_partition_num and activity_type != 'DDL' ) select current timestamp as
current_time, l.member, substr(l.latch_name,1,40) latch_name, l.application_handle,
l.edu_id, l.latch_status, l.latch_wait_time , d.stmt_text from
table(mon_get_latch(null,-2)) l, activity_handles d where l.application_handle =
d.application_handle order by application_handle, member" > $DUMPDIR/STMT.latch.$TS

{
printf '\n\n%s\n\n' "HEADER - Current CPU usage across members"
db2 -v "select current timestamp as curr_timestamp, min(member) as
member_min, max(member) member_max, substr(host_name,1,20) as host_name,
max(cpu_online) cpu_online, max(cpu_usage_total) cpu_usage_total,
max(decimal(cpu_load_short,6,1)) load_short, max(decimal(cpu_load_medium,6,1))
load_med, max(decimal(cpu_load_long,6,1)) load_long, min(memory_free)/1024 as
mem_free_gb from table(sysproc.env_get_system_resources()) group by host_name order
by member_min asc"
printf '\n\n%s\n\n' "HEADER - Current state of queries"
db2 -v "SELECT current timestamp as timestamp, ACTIVITY_STATE,
SUM(ADM_BYPASSED) AS BYPASSED, COUNT(*) FROM TABLE(MON_GET_ACTIVITY(NULL,-2)) AS T
WHERE T.MEMBER = T.COORD_MEMBER GROUP BY ACTIVITY_STATE"
printf '\n\n%s\n\n' "HEADER - Current state of queries per service class"
db2 -v "SELECT current timestamp as timestamp,
substr(PARENTSERVICECLASSNAME,1,25) AS SUPER, ACTIVITY_STATE, SUM(ADM_BYPASSED) AS
BYPASSED, COUNT(*) FROM TABLE(MON_GET_ACTIVITY(NULL,-2)) AS T,
SYSCAT.SERVICECLASSES AS Q WHERE SERVICECLASSID = SERVICE_CLASS_ID AND T.MEMBER =
T.COORD_MEMBER GROUP BY substr(PARENTSERVICECLASSNAME,1,25), ACTIVITY_STATE ORDER
BY SUPER DESC"
printf '\n\n%s\n\n' "HEADER - Agents queued up"
db2 -v "SELECT current timestamp as timestamp, SERVICE_SUPERCLASS_NAME,
EVENT_OBJECT, EVENT_OBJECT_NAME, COUNT(*) FROM TABLE(MON_GET_AGENT(NULL,NULL,NULL,-
2)) AS T WHERE EVENT_OBJECT = 'WLM_QUEUE' GROUP BY SERVICE_SUPERCLASS_NAME,
EVENT_OBJECT, EVENT_OBJECT_NAME"
printf '\n\n%s\n\n' "HEADER - Queries in executing or idle state"
db2 -v "select current timestamp as timestamp, application_handle,
substr(activity_state,1,12) as state, coord_partition_num as connecting_member,
member as current_member, planid, stmtid, substr( stmt_text, 1, 120 ) as stmt_text
from table( mon_get_activity(null,-2)) where ( activity_state = 'EXECUTING' or
activity_state = 'IDLE' ) and member = coord_partition_num with ur"
printf '\n\n%s\n\n' "HEADER - Queries on the queue"
db2 -v "select current timestamp as timestamp, application_handle,
coord_partition_num as connecting_member, estimated_sort_shrheap_top,
estimated_runtime, substr( stmt_text, 1, 120 ) as stmt_text from
table( mon_get_activity(null,-2)) where activity_state = 'QUEUED' and member =
coord_partition_num with ur"
printf '\n\n%s\n\n' "HEADER - Top 10 longest running queries"
db2 -v "select current timestamp as timestamp, application_handle,
entry_time, local_start_time, timestampdiff( 2, to_char( current timestamp -
local_start_time ) ) as elapsed_tm_secs, stmtid, planid, effective_query_degree,
substr(stmt_text,1,200) as stmt_text from table(mon_get_activity(null,-2)) where (
activity_state = 'EXECUTING' or activity_state = 'IDLE' ) and member =
coord_partition_num and timestampdiff( 2, to_char( current timestamp -
local_start_time ) ) > 0 order by elapsed_tm_secs desc fetch first 10 rows only
with ur"
printf '\n\n%s\n\n' "HEADER - Top 10 sort memory consuming queries"
db2 -v "select current timestamp as timestamp, application_handle,
sum( nvl( sort_shrheap_allocated, 0 ) * 4) as allocated_sortmem_kb,
max( sort_shrheap_top * 4 ) as peak_sortmem_used_kb from
table( mon_get_activity(null, -2 )) where ( activity_state = 'EXECUTING' or
activity_state = 'IDLE' ) and ( nvl( sort_shrheap_allocated, 0 ) > 0 or
nvl( sort_shrheap_top, 0 ) > 0 ) group by application_handle order by
allocated_sortmem_kb desc fetch first 10 rows only with ur"
printf '\n\n%s\n\n' "HEADER - Top 10 queries with longest wait within engine"
db2 -v "select current timestamp as timestamp, application_handle,
executable_id, decimal( avg( ( total_act_wait_time / total_act_time ) * 100 ),
5,2) as overall_wait_pct , decimal( avg( ( lock_wait_time / total_act_time ) *
100 ), 5,2 ) as pct_lck, decimal( avg( ( pool_read_time / total_act_time ) * 100 ),
5, 2) as pct_phys_rd, decimal( avg( ( ( direct_read_time+direct_write_time ) /
total_act_time ) * 100 ), 5,2 ) as pct_dir_io,
decimal( avg( ( (fcm_recv_wait_time+fcm_send_wait_time) / total_act_time ) *
100 ),5,2) as pct_fcm, decimal( avg( ( total_extended_latch_wait_time /
total_act_time ) * 100 ),5,2) as pct_ltch, decimal( avg( ( log_disk_wait_time /
total_act_time ) * 100 ), 5,2 ) as pct_log, decimal( avg( ( diaglog_write_wait_time
/ total_act_time ) * 100 ), 5, 2) as pct_diaglog from
table( mon_get_activity(null,-2)) where total_act_time > 0 group by
application_handle , planid, stmtid, executable_id order by overall_wait_pct desc
fetch first 10 rows only with ur"
printf '\n\n%s\n\n' "HEADER - Top 25 apphandles spilling sorts to disk"
db2 -v "with pagesize( MEMBER, TBSP_ID, tbsp_page_size) as ( select MEMBER,
TBSP_ID, tbsp_page_size from table(mon_get_tablespace(null,-2)) where
TBSP_CONTENT_TYPE IN ('SYSTEMP','USRTEMP') ) , numpages( apphandle, MEMBER,
tbsp_id, num_objects, spillMB ) as ( select substr(tabschema,1,45) , t.MEMBER ,
t.tbsp_id, int(count(*)) , sum( decimal( ( float( ( nvl( col_object_l_pages,0) +
nvl(data_object_l_pages,0) + nvl( index_object_l_pages,0)) * p.tbsp_page_size) /
float((1024*1024)) ), 15,2)) as spillMB from table(mon_get_table(null,null,-2)) as
t , pagesize p where t.tbsp_id = p.TBSP_ID AND t.MEMBER = p.MEMBER group by
substr(tabschema,1,45), t.MEMBER, t.tbsp_id ) select current timestamp as
curr_timestamp , apphandle , sum(num_objects) as num_objects , sum(spillMB) as
spillMB from numpages group by apphandle order by spillMB desc fetch first 25
rows only with ur"
printf '\n\n%s:\n\n' "HEADER - Sort memory usage per member"
db2 -v "with SORTMEM (SHEAPTHRESSHR, SHEAPMEMBER) AS (SELECT VALUE, MEMBER
FROM SYSIBMADM.DBCFG WHERE NAME = 'sheapthres_shr'),
actual_mem( tot_alloc_sortheap, sortmember ) as ( select
sum( sort_shrheap_allocated ), member from table(mon_get_activity(null,-2)) where (
activity_state = 'EXECUTING' or activity_state = 'IDLE' ) group by member ) select
current timestamp as timestamp, sortmember as member, tot_alloc_sortheap as
allocated_sort_heap, decimal( ( tot_alloc_sortheap / SHEAPTHRESSHR)*100,5,2) as
pct_sortmem_used, int( SHEAPTHRESSHR ) as cfg_shrheap_thresh from actual_mem,
SORTMEM where sortmember = SHEAPMEMBER order by member "
printf '\n\n%s:\n\n' "HEADER - Sort memory usage of bypassed and non-bypassed
queries per member"
db2 -v "with SORTMEM (SHEAPTHRESSHR, SHEAPMEMBER) AS (SELECT VALUE, MEMBER
FROM SYSIBMADM.DBCFG WHERE NAME = 'sheapthres_shr'), ADMBYPASS( appmember,
admbypassed, alloc_sortmem) as ( select member, adm_bypassed,
sum(sort_shrheap_allocated) from table( mon_get_activity(null,-2)) where
( activity_state = 'EXECUTING' or activity_state = 'IDLE' ) group by member,
adm_bypassed ) select current timestamp as curr_timestamp, appmember, alloc_sortmem
as allocated_sortmem, decimal( ( alloc_sortmem / SHEAPTHRESSHR) * 100, 5,2 ) as
pct_sortmem_used, admbypassed as adm_bypass, int(SHEAPTHRESSHR) as
cfg_shrheap_thresh from SORTMEM, ADMBYPASS where SHEAPMEMBER = appmember and
alloc_sortmem > 0 order by appmember, pct_sortmem_used desc"
printf '\n\n%s:\n\n' "HEADER - Sort memory usage per apphandle across ALL
members"
db2 -v "with SORTMEM (SHEAPTHRESSHR, SHEAPMEMBER) AS (SELECT VALUE, MEMBER
FROM SYSIBMADM.DBCFG WHERE NAME = 'sheapthres_shr'), ESTSORTMEM( estapphandle,
estappmember, estsortmem) as ( select application_handle, member,
max( estimated_sort_shrheap_top ) from table( mon_get_activity(null,-2)) where
( activity_state = 'EXECUTING' or activity_state = 'IDLE') group by
application_handle, member ), APPSORTMEM( apphandle, appmember, admbypassed,
alloc_sortmem) as ( select application_handle, member, adm_bypassed,
sum(sort_shrheap_allocated) from table( mon_get_activity(null,-2)) where
( activity_state = 'EXECUTING' or activity_state = 'IDLE' ) group by
application_handle, member, adm_bypassed ) select current timestamp as timestamp,
appmember, apphandle, admbypassed as adm_bypass, alloc_sortmem as
allocated_sortmem, estsortmem as est_sortmem, decimal( ( alloc_sortmem /
SHEAPTHRESSHR ) * 100, 5,2 ) as pct_sortmem_used, decimal( ( estsortmem /
SHEAPTHRESSHR )*100, 5, 2) as pct_est_sortmem, int(SHEAPTHRESSHR) as
cfg_shrheap_thresh from SORTMEM, APPSORTMEM, ESTSORTMEM where SHEAPMEMBER =
appmember and SHEAPMEMBER = estappmember and estapphandle = apphandle and
alloc_sortmem > 0 order by appmember, pct_sortmem_used desc"
printf '\n\n%s:\n\n' "HEADER - Memory consumption of currently running
queries"
db2 -v "with total_mem(cfg_mem) as (select max(bigint(value)) from
sysibmadm.dbcfg where name = 'sheapthres_shr' ), max_mem_part(member) as (select
member from table(mon_get_database(-2)) as t order by sort_shrheap_allocated desc
fetch first 1 rows only), mem_usage_on_member(application_handle, uow_id,
activity_id, sort_shrheap_allocated) as (select application_handle, uow_id,
activity_id, sort_shrheap_allocated from max_mem_part q,
table(mon_get_activity(null, q.member)) as t where activity_state = 'EXECUTING' or
activity_state = 'IDLE') select current timestamp as timestamp,
a.application_handle, a.uow_id, a.activity_id, a.local_start_time, timestampdiff(2,
(current_timestamp-a.local_start_time)) as total_runtime_seconds, timestampdiff(2,
(current_timestamp-a.local_start_time))-a.coord_stmt_exec_time/1000 as
total_wait_on_client_time_seconds, a.wlm_queue_time_total / 1000 as
time_queued_before_start_exec_seconds,b.application_name, b.session_auth_id,
b.client_ipaddr, a.activity_state, a.adm_bypassed, a.estimated_sort_shrheap_top
est_mem_usage, c.sort_shrheap_allocated as mem_usage_curr, d.cfg_mem,
dec((float(c.sort_shrheap_allocated)/float(d.cfg_mem))*100,5,2) as
query_pct_mem_used, substr(a.stmt_text, 1, 1024) as statement_text from
table(mon_get_activity(null,-2)) as a, table(mon_get_connection(null,-2)) as b,
mem_usage_on_member as c, total_mem as d where (a.application_handle =
b.application_handle) AND (a.member = b.member) AND (a.application_handle =
c.application_handle) AND (a.member=a.COORD_PARTITION_NUM) AND (a.uow_id =
c.uow_id) AND (a.activity_id = c.activity_id) order by query_pct_mem_used"
printf '\n\n%s\n\n' "HEADER - Estimated memory consumption of queued queries"
db2 -v "with total_mem(cfg_mem) as (select bigint(max(value)) from
sysibmadm.dbcfg where name = 'sheapthres_shr' ) select a.application_handle,
a.uow_id, a.activity_id, a.entry_time, timestampdiff(2, (current_timestamp -
a.entry_time)) as time_queued_seconds, b.application_name, b.session_auth_id,
b.client_ipaddr, a.activity_state, a.estimated_sort_shrheap_top est_mem_usage,
a.member, dec((float(a.estimated_sort_shrheap_top)/float(cfg_mem))*100,5,2) as
est_query_pct_mem_usage, substr(a.stmt_text, 1, 1024) as statement_text from
table(mon_get_activity(null,-2)) as a, table(mon_get_connection(null,-2)) as b,
total_mem c where (a.application_handle = b.application_handle) AND (a.member =
b.member) AND (a.activity_state = 'QUEUED') AND (a.member=a.COORD_PARTITION_NUM)
AND (dec((float(a.estimated_sort_shrheap_top)/float(cfg_mem))*100,5,2)) > 25 order
by est_mem_usage desc"
printf '\n\n%s\n\n' "HEADER - Information on agents working for each
apphandle"
db2 -v "with activity_data( member, application_handle, rows_read,
rows_returned, rows_modified, fcm_tq_recvs_total, fcm_tq_sends_total ) as ( select
member, application_handle, sum( rows_read), sum(rows_returned),
sum(rows_modified), sum(fcm_tq_recvs_total), sum(fcm_tq_sends_total) from
table( mon_get_activity( null, -2)) where ( activity_state = 'EXECUTING' or
activity_state = 'IDLE' ) group by member, application_handle) SELECT current
timestamp as timestamp, SUBSTR(CHAR(SCDETAILS.APPLICATION_HANDLE),1,7) AS
APPHANDLE, SUBSTR(CHAR(SCDETAILS.MEMBER),1,4) AS MEMB, SUBSTR(EVENT_STATE,1,10) AS
EVENT_STATE, SUBSTR(EVENT_TYPE,1,10) AS EVENT_TYPE, SUBSTR(EVENT_OBJECT,1,10) AS
EVENT_OBJECT, SUBSTR(EVENT_STATE,1,10) as EVENT_STATE,
SUBSTR(EVENT_OBJECT_NAME,1,30) as EVENT_OBJECT_NAME,
SUBSTR(EVENT_OBJECT_DETAILS,1,30) as EVENT_OBJECT_DETAILS,
SUBSTR(CHAR(SUBSECTION_NUMBER),1,4) AS SUBSECTN, TIMESTAMPDIFF(2,
CHAR( AGENT_STATE_LAST_UPDATE_TIME - REQUEST_START_TIME) ) as ELAPSED_SECS,
rows_read as rread, rows_returned as rret, rows_modified as rmod,
fcm_tq_recvs_total as tq_recv, fcm_tq_sends_total as tq_send FROM
TABLE(MON_GET_AGENT(CAST(NULL AS VARCHAR(128)), CAST(NULL AS VARCHAR(128)), NULL, -
2)) AS SCDETAILS, activity_data where SCDETAILS.member = activity_data.member and
SCDETAILS.application_handle = activity_data.application_handle ORDER BY
elapsed_secs desc, memb, subsectn"
printf '\n\n%s\n\n' "HEADER - Lock wait details"
db2 -v "select current timestamp as timestamp, hld_member as hld_m,
req_member as req_m, hld_application_handle,
req_application_handle,lock_wait_start_time, timestampdiff(2,to_char(current
timestamp - lock_wait_start_time)) as lockwait_time_secs,lock_name,
lock_current_mode,lock_mode_requested from table(mon_get_appl_lockwait(null,-2))
order by lockwait_time_secs desc with ur"
printf '\n\n%s\n\n' "HEADER - Activity metrics"
db2 -v "select current timestamp as current_time, coord_member, member,
application_handle, entry_time, local_start_time, substr(activity_state,1,16) as
state, substr(activity_type,1,12) as type, total_act_time, total_act_wait_time,
lock_wait_time, pool_read_time, pool_write_time, total_extended_latch_wait_time,
lock_wait_time, log_buffer_wait_time, log_disk_wait_time, diaglog_write_wait_time,
evmon_wait_time, prefetch_wait_time, ext_table_recv_wait_time,
ext_table_recvs_total, ext_table_read_volume, fcm_recv_wait_time,
fcm_send_wait_time, planid, stmtid, substr(stmt_text,1,100) as stmt_text from
table(mon_get_activity(null,-2)) where activity_type != 'DDL' order by
total_act_time desc, application_handle, member "
printf '\n\n%s\n\n' "HEADER - Connection idle times"
db2 -v "select current timestamp as timestamp, member, coord_member,
application_handle, substr(client_applname,1,20) as client_appname,
total_rqst_time, total_act_time, client_idle_wait_time, wlm_queue_time_total,
total_act_wait_time, case when total_rqst_time > 0 then
decimal(float(client_idle_wait_time) / total_rqst_time, 10, 2) else null end as
idle_rqst_ratio from table(mon_get_connection(null,-2)) where client_applname is
not null"
printf '\n\n%s\n\n' "HEADER - Agent states per apphandle"
db2 -v "with activity_handles(application_handle) as (select
application_handle from table(mon_get_activity(null,-2)) where
member=coord_partition_num and activity_type != 'DDL' ) select
a.request_start_time, a.agent_state_last_update_time, current timestamp as
current_time, a.application_handle, a.member, a.agent_tid,
substr(a.agent_type,1,11) as agenttype, substr(a.agent_state,1,10) as agentstate,
substr(a.request_type,1,12) as reqtype, substr(a.event_object,1,16) as
event_object, substr(a.event_state,1,16) as event_state,
substr(event_object_name,1,32) as event_object_name,
substr(event_object_details,1,32) as event_object_details, a.uow_id, a.activity_id
from table(mon_get_agent(null,null, null, -2)) a, activity_handles d where
a.application_handle = d.application_handle order by application_handle, member"
printf '\n\n%s\n\n' "HEADER - FCM Congestion details"
db2 -v "select current timestamp as timestamp, member, remote_member,
fcm_congested_sends, fcm_congestion_time, fcm_num_congestion_timeouts,
connection_status from table(mon_get_fcm_connection_list(-2)) order by member"
printf '\n\n%s\n\n' "HEADER - Latch activity per query"
db2 -v "with activity_handles(application_handle , STMT_TEXT) as (select
application_handle, STMT_TEXT from table(mon_get_activity(null,-2)) where
member=coord_partition_num and activity_type != 'DDL' ) select current timestamp as
current_time, l.member, substr(l.latch_name,1,40) latch_name, l.application_handle,
l.edu_id, l.latch_status, l.latch_wait_time , d.stmt_text from
table(mon_get_latch(null,-2)) l, activity_handles d where l.application_handle =
d.application_handle order by application_handle, member"
printf '\n\n%s\n\n' "HEADER - Wait times within DB engine"
db2 -v "select member, integer(sum(total_rqst_time)) as total_rqst_tm,
integer(sum(total_wait_time)) as total_wait_tm, decimal((sum(total_wait_time) /
float(sum(total_rqst_time))) * 100, 5, 2) as pct_rqst_wait,
decimal((sum(lock_wait_time) / float(sum(total_rqst_time))) * 100, 5, 2) as
pct_lock, decimal((sum(lock_wait_time_global) / float(sum(total_rqst_time))) * 100,
5, 2) as pct_glb_lock, decimal((sum(total_extended_latch_wait_time) /
float(sum(total_rqst_time))) * 100, 5, 2) as pct_ltch,
decimal((sum(log_disk_wait_time) / float(sum(total_rqst_time))) * 100, 5, 2) as
pct_lg_dsk, decimal((sum(reclaim_wait_time) / float(sum(total_rqst_time))) * 100,
5, 2) as pct_rclm, decimal((sum(cf_wait_time) / float(sum(total_rqst_time))) * 100,
5, 2) as pct_cf, decimal((sum(pool_read_time) / float(sum(total_rqst_time))) * 100,
5, 2) as pct_pool_r, decimal((sum(direct_read_time) / float(sum(total_rqst_time)))
* 100, 5, 2) as pct_dir_r, decimal((sum(direct_write_time) /
float(sum(total_rqst_time))) * 100, 5, 2) as pct_dir_w,
decimal((sum(fcm_recv_wait_time+fcm_send_wait_time) / float(sum(total_rqst_time)))
* 100, 5, 2) as pct_fcm, decimal((sum(tcpip_send_wait_time+tcpip_recv_wait_time) /
float(sum(total_rqst_time))) * 100, 5, 2) as pct_tcpip ,
decimal((sum(diaglog_write_wait_time) / float(sum(total_rqst_time))) * 100, 5, 2)
as pct_diag from table( mon_get_database(-2)) group by member order by member"
printf '\n\n%s\n\n' "HEADER - Overall Latch wait metrics ( the numbers are
cumulative )"
db2 -v "select current timestamp as timestamp,member,
cast(substr(latch_name,1,60) as varchar(60)) as latch_name,
total_extended_latch_wait_time as tot_ext_latch_wait_time_ms,
total_extended_latch_waits as tot_ext_latch_waits,
decimal( double(total_extended_latch_wait_time) / total_extended_latch_waits, 10, 2
) as time_per_latch_wait_ms from table( mon_get_extended_latch_wait(-2)) where
total_extended_latch_waits > 0 order by total_extended_latch_wait_time desc with
UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_BP_UTILIZATION"
db2 -v "select * from SYSIBMADM.MON_BP_UTILIZATION ORDER BY 1,2 with UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_TRANSACTION_LOG_UTILIZATION"
db2 -v "select * from SYSIBMADM.MON_TRANSACTION_LOG_UTILIZATION ORDER BY 1
DESC WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_WORKLOAD_SUMMARY"
db2 -v "select * from sysibmadm.MON_WORKLOAD_SUMMARY ORDER BY 1 WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_SERVICE_SUBCLASS_SUMMARY"
db2 -v "select * from sysibmadm.MON_SERVICE_SUBCLASS_SUMMARY ORDER BY 1
WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_DB_SUMMARY"
db2 -v "select * from sysibmadm.MON_DB_SUMMARY WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_CURRENT_UOW"
db2 -v "select * from sysibmadm.MON_CURRENT_UOW ORDER BY ELAPSED_TIME_SEC
DESC WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_CONNECTION_SUMMARY"
db2 -v "select * from sysibmadm.MON_CONNECTION_SUMMARY ORDER BY
RQST_WAIT_TIME_PERCENT DESC WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_TBSP_UTILIZATION"
db2 -v "select * from SYSIBMADM.MON_TBSP_UTILIZATION ORDER BY 1,2 WITH UR"
printf '\n\n%s\n\n' "HEADER - SYSIBMADM.MON_PKG_CACHE_SUMMARY"
db2 -v "select * from sysibmadm.MON_PKG_CACHE_SUMMARY ORDER BY
AVG_STMT_EXEC_TIME DESC FETCH FIRST 10 rows only WITH UR"
printf '%s\n\n' "HEADER - $(date): CPU TIME PER APPLICATION_HANDLE ACROSS ALL
MEMBERS"
db2 -v "SELECT t.APPLICATION_HANDLE,count(t.member) as
NUM_MEMBER,decimal(avg(t.TOTAL_CPU_TIME*1.00)/1000000, 12,2) as
AVG_TOTAL_CPU_TIME_SEC,decimal(avg(t.TOTAL_WAIT_TIME*1.00)/1000, 12,2) as
AVG_TOTAL_WAIT_TIME_SEC, decimal(avg(t.TOTAL_RQST_TIME*1.00)/1000, 12,2) as
AVG_TOTAL_RQST_TIME_SEC, decimal(avg(t.TOTAL_SECTION_TIME*1.00)/1000,12,2) as
AVG_TOTAL_SECTION_TIME_SEC, decimal(avg(t.TOTAL_SECTION_PROC_TIME*1.00)/1000, 12,2)
as AVG_TOTAL_SECTION_PROC_TIME_SEC FROM TABLE(MON_GET_CONNECTION(cast(NULL as
bigint), -2)) AS t GROUP BY t.APPLICATION_HANDLE"
printf '%s\n\n' "HEADER - $(date): Bufferpool METRICS across all members"
db2 -v "SELECT bp_name, sum( pool_data_l_reads + pool_temp_data_l_reads +
pool_index_l_reads + pool_temp_index_l_reads + pool_xda_l_reads +
pool_temp_xda_l_reads) as logical_reads, sum( pool_data_p_reads +
pool_temp_data_p_reads + pool_index_p_reads + pool_temp_index_p_reads +
pool_xda_p_reads + pool_temp_xda_p_reads) as physical_reads ,case when
sum( pool_data_l_reads + pool_temp_data_l_reads + pool_index_l_reads +
pool_temp_index_l_reads + pool_xda_l_reads + pool_temp_xda_l_reads) > 0 THEN
DEC((1-(FLOAT(sum( pool_data_p_reads + pool_temp_data_p_reads + pool_index_p_reads
+ pool_temp_index_p_reads + pool_xda_p_reads + pool_temp_xda_p_reads)) / FLOAT
(sum( pool_data_l_reads + pool_temp_data_l_reads + pool_index_l_reads +
pool_temp_index_l_reads + pool_xda_l_reads + pool_temp_xda_l_reads))))*100,5,2)
ELSE NULL END AS HITRATIO FROM TABLE(MON_GET_BUFFERPOOL('',-2)) AS METRICS group
by bp_name"
printf '%s\n\n' "HEADER - $(date): Tablespace METRICS across all members"
db2 -v "with tbsp_metrics as ( SELECT varchar(tbsp_name, 20) as tbsp_name,
tbsp_type, max (tbsp_page_size) as tbsp_page_size, count(member) as num_member,
sum( pool_data_l_reads + pool_temp_data_l_reads + pool_index_l_reads +
pool_temp_index_l_reads + pool_xda_l_reads + pool_temp_xda_l_reads) as
sum_logical_reads, sum( pool_data_p_reads + pool_temp_data_p_reads +
pool_index_p_reads + pool_temp_index_p_reads + pool_xda_p_reads +
pool_temp_xda_p_reads) as sum_physical_reads, sum( pool_data_p_reads +
pool_index_p_reads) as sum_data_index_p_reads, sum( pool_async_data_reads +
pool_async_index_reads) as sum_async_data_index_reads, sum(pool_data_writes) as
sum_pool_data_writes, sum(pool_async_data_writes) as sum_pool_async_data_writes
FROM TABLE(MON_GET_TABLESPACE('',-2)) AS t group by tbsp_name, tbsp_type )
select tbsp_name, tbsp_type, tbsp_page_size, num_member, sum_logical_reads,
sum_physical_reads, case when sum_logical_reads > 0 then decimal((1 -
float(sum_physical_reads)/float(sum_logical_reads)) * 100.0, 5,2) else null end as
bp_hit_ratio, sum_data_index_p_reads, sum_async_data_index_reads, case when
sum_data_index_p_reads > 0 then
decimal(float(sum_async_data_index_reads)*100/float(sum_data_index_p_reads),5,2)
else null end as async_data_index_read_ratio, sum_pool_data_writes,
sum_pool_async_data_writes, case when sum_pool_data_writes > 0 then
decimal(float(sum_pool_async_data_writes)*100/float(sum_pool_data_writes),5,2) else
null end as async_data_write_ratio from tbsp_metrics"
printf '%s\n\n' "HEADER - $(date): Memory USED Metrics across hosts"
db2 -v "with mon_mem as ( SELECT varchar(host_name, 20) AS host_name,
varchar(memory_set_type, 20) AS set_type, varchar(memory_pool_type,20) AS
pool_type, varchar(db_name, 20) AS db_name, memory_pool_used,
memory_pool_used_hwm FROM TABLE( MON_GET_MEMORY_POOL(NULL, CURRENT_SERVER, -
2)) ) select host_name, set_type, pool_type, db_name,
sum(memory_pool_used)/1000000 as memory_pool_used_MB,
sum(memory_pool_used_hwm)/1000000 as memory_pool_used_hwm_MB from mon_mem group
by grouping sets ((set_type, pool_type, db_name), (host_name))"
printf '%s\n\n' "HEADER - $(date): LOCK WAITS PER APPLICATION_HANDLE"
db2 -v "select APPLICATION_HANDLE, count(MEMBER) as NUM_MEMBER,
max(connection_start_time) as connection_start_time, sum(LOCK_ESCALS) as
LOCK_ESCALS, sum(LOCK_TIMEOUTS) as LOCK_TIMEOUTS,
integer(sum(LOCK_WAIT_TIME)/1000) as LOCK_WAIT_TIME_SEC, sum(LOCK_WAITS) as
LOCK_WAITS, sum(DEADLOCKS) as DEADLOCKS from TABLE(MON_GET_CONNECTION(cast(NULL
as bigint), -2)) AS t group by APPLICATION_HANDLE"
printf '%s\n\n' "HEADER - $(date): Blocked LockWaits"
db2 -v "select REQ_APPLICATION_HANDLE, REQ_MEMBER, HLD_APPLICATION_HANDLE,
HLD_MEMBER, LOCK_OBJECT_TYPE, LOCK_MODE, varchar(TABSCHEMA, 20) as TABSCHEMA,
varchar(TABNAME, 20) as TABNAME from SYSIBMADM.MON_LOCKWAITS"
printf '%s\n\n' "HEADER - $(date): db2 SORT-HASH JOINS per apphdl"
db2 -v "SELECT APPLICATION_HANDLE, count(*) as NUM_MEMBER, sum(TOTAL_SORTS)
as SUM_TOTAL_SORTS, sum(TOTAL_SECTION_SORTS) as SUM_TOTAL_SECTION_SORTS,
sum(SORT_OVERFLOWS) as SUM_SORT_OVERFLOWS, sum(POST_THRESHOLD_SORTS) as
SUM_POST_THRESHOLD_SORTS, decimal(avg(TOTAL_SECTION_PROC_TIME)/1000.0,8,2) as
AVG_TOTAL_SECTION_PROC_TIME_SEC,
decimal(avg(TOTAL_SECTION_SORT_PROC_TIME)/1000.0,8,2) as
AVG_TOTAL_SECTION_SORT_PROC_TIME_SEC, sum(TOTAL_HASH_JOINS) as
SUM_TOTAL_HASH_JOINS, sum(TOTAL_HASH_LOOPS) as SUM_TOTAL_HASH_LOOPS,
sum(HASH_JOIN_OVERFLOWS) as SUM_HASH_JOIN_OVERFLOWS, sum(ROWS_MODIFIED) as
SUM_ROWS_MODIFIED, sum(POOL_DATA_WRITES) as SUM_POOL_DATA_WRITES FROM
TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t GROUP BY
APPLICATION_HANDLE"
printf '%s\n\n' "HEADER - $(date): DataSKew per apphdl"
db2 -v "SELECT APPLICATION_HANDLE, count( MEMBER) as NUM_PARTITIONS,
avg(TOTAL_CPU_TIME/1000) as AVG_TOTAL_CPU_TIME_MS, max(TOTAL_CPU_TIME/1000) as
MAX_TOTAL_CPU_TIME_MS, decimal(case when max(TOTAL_CPU_TIME) > 0 then (1-
avg(TOTAL_CPU_TIME*1.0)*1.0/max(TOTAL_CPU_TIME)) else 0 end, 8,4) as
SKEW_TOTAL_CPU_TIME, decimal(case when avg(TOTAL_CPU_TIME) > 0 then
max(TOTAL_CPU_TIME)*1.0/avg(TOTAL_CPU_TIME) else 1 end, 8, 4) as SLOWDOWN_CPU_TIME,
avg(TOTAL_RQST_TIME) as AVG_TOTAL_RQST_TIME_MS, max(TOTAL_RQST_TIME) as
MAX_TOTAL_RQST_TIME_MS, decimal(case when max(TOTAL_RQST_TIME) > 0 then (1-
avg(TOTAL_RQST_TIME)*1.0/max(TOTAL_RQST_TIME)) else 0 end, 8, 4) as
SKEW_TOTAL_RQST_TIME, avg(ROWS_READ) as AVG_ROWS_READ, max(ROWS_READ) as
MAX_ROWS_READ, decimal( case when max(ROWS_READ) > 0 then (1-
avg(ROWS_READ)*1.0/max(ROWS_READ)) else 0 end, 8, 4) as SKEW_ROWS_READ,
avg(ROWS_MODIFIED) as AVG_ROWS_WRITTEN, max(ROWS_MODIFIED) as MAX_ROWS_WRITTEN,
decimal(case when max(ROWS_MODIFIED) > 0 then (1-
avg(ROWS_MODIFIED)*1.0/max(ROWS_MODIFIED)) else 0 end, 8, 4) as SKEW_ROWS_WRITTEN
FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t group by
APPLICATION_HANDLE"
printf '%s\n\n' "HEADER - $(date): FCM Traffic per apphdl"
db2 -v "SELECT APPLICATION_HANDLE, MEMBER, decimal(FCM_RECV_VOLUME*1.0
/(1024*1024), 12,3) as FCM_RECV_VOLUME_MB, FCM_RECVS_TOTAL,
decimal(FCM_SEND_VOLUME*1.0 /(1024*1024), 12,3) as FCM_SEND_VOLUME_MB,
FCM_SENDS_TOTAL,
decimal( (POOL_DATA_L_READS+POOL_INDEX_L_READS+POOL_TEMP_DATA_L_READS+POOL_TEMP_IND
EX_L_READS+POOL_TEMP_XDA_L_READS+POOL_XDA_L_READS)*16.0/1024, 12,3) as
L_READS_VOLUME_MB FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t
ORDER BY APPLICATION_HANDLE, MEMBER"
printf '%s\n\n' "HEADER - $(date): CURRENT SQL"
db2 -v "select APPLICATION_HANDLE, varchar(substr(APPLICATION_NAME, 1,
20),20) as APPLICATION_NAME, varchar(substr(SESSION_AUTH_ID, 1, 20),20) as
SESSION_AUTH_ID, varchar(substr(CLIENT_APPLNAME, 1, 20),20) as CLIENT_APPLNAME,
varchar(substr(STMT_TEXT, 1, 100), 100) as STMT_TEXT from
SYSIBMADM.MON_CURRENT_SQL"
printf '%s\n\n' "HEADER - $(date): CPU USAGE PER APPLICATION_HANDLE"
db2 -v "with connect_agg as ( SELECT t.APPLICATION_HANDLE, count(t.member)
as NUM_MEMBER, decimal(avg(t.TOTAL_CPU_TIME*1.00)/1000000, 12,2) as
AVG_TOTAL_CPU_TIME_SEC, decimal(avg(t.TOTAL_WAIT_TIME*1.00)/1000, 12,2) as
AVG_TOTAL_WAIT_TIME_SEC, decimal(avg(t.TOTAL_RQST_TIME*1.00)/1000, 12,2) as
AVG_TOTAL_RQST_TIME_SEC, decimal(avg(t.TOTAL_SECTION_TIME*1.00)/1000,12,2) as
AVG_TOTAL_SECTION_TIME_SEC, decimal(avg(t.TOTAL_SECTION_PROC_TIME*1.00)/1000,
12,2) as AVG_TOTAL_SECTION_PROC_TIME_SEC FROM TABLE(MON_GET_CONNECTION(cast(NULL
as bigint), -2)) AS t WHERE t.MEMBER > 0 GROUP BY t.APPLICATION_HANDLE ) select
c.APPLICATION_HANDLE, NUM_MEMBER, AVG_TOTAL_CPU_TIME_SEC, AVG_TOTAL_WAIT_TIME_SEC,
AVG_TOTAL_RQST_TIME_SEC, AVG_TOTAL_SECTION_TIME_SEC,
AVG_TOTAL_SECTION_PROC_TIME_SEC, decimal(t0.TOTAL_APP_RQST_TIME/1000.0, 12,2) as
TOTAL_APP_RQST_TIME_SEC, case when t0.TOTAL_APP_RQST_TIME > 0 then
decimal(AVG_TOTAL_CPU_TIME_SEC*100000/(t0.TOTAL_APP_RQST_TIME*2),12,2) end as
CPU_USAGE_PCT, varchar(substr(STMT_TEXT, 1, 100), 100) as STMT_TEXT FROM
connect_agg c inner join TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t0
on (c.APPLICATION_HANDLE = t0.APPLICATION_HANDLE) left outer join
SYSIBMADM.MON_CURRENT_SQL m on ( c.APPLICATION_HANDLE = m.APPLICATION_HANDLE )
where t0.MEMBER = t0.COORD_MEMBER"
printf '%s\n\n' "HEADER - $(date): TOP CPUTIME PER MEMBER PER EXECUTABLE_ID"
db2 -v "SELECT EXECUTABLE_ID, max(SECTION_TYPE) as SECTION_TYPE,
integer(avg(NUM_EXEC_WITH_METRICS)) as AVG_NUM_EXEC_WITH_METRICS,
decimal(sum(TOTAL_CPU_TIME)/(1000000.0*count(distinct member)),10,2) as
TOTAL_CPU_TIME_SEC_PER_MEMBER,
decimal(sum(TOTAL_CPU_TIME)/sum(NUM_EXEC_WITH_METRICS)/1000000.0, 10,2) as
AVG_CPU_TIME_SEC_PER_MEMBER, max(varchar( substr(STMT_TEXT, 1, 100), 100)) as
STMT_TEXT FROM TABLE(MON_GET_PKG_CACHE_STMT ( 'D', NULL, NULL, -2)) as T WHERE
T.NUM_EXEC_WITH_METRICS > 0 GROUP BY EXECUTABLE_ID ORDER BY
TOTAL_CPU_TIME_SEC_PER_MEMBER"
printf '%s\n\n' "HEADER - $(date): IO MONITORING per application_handle"
db2 "WITH READ_METRICS as ( SELECT APPLICATION_HANDLE, count(*) as
NUM_MEMBER, sum(ROWS_READ) as ROWS_READ, sum(POOL_DATA_L_READS) as
POOL_DATA_L_READS, sum(POOL_INDEX_L_READS) as POOL_INDEX_L_READS,
sum(POOL_TEMP_DATA_L_READS+POOL_TEMP_INDEX_L_READS) as POOL_TEMP_L_READS FROM
TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS m where member > 0 group
by application_handle ) select r.APPLICATION_HANDLE, NUM_MEMBER, r.ROWS_READ,
case when POOL_DATA_L_READS+POOL_TEMP_L_READS > 0 then
decimal(r.ROWS_READ*1.00/(POOL_DATA_L_READS+POOL_TEMP_L_READS), 8,2) end as
ROWS_READ_PER_POOL_L_READ, POOL_DATA_L_READS, POOL_INDEX_L_READS,
POOL_TEMP_L_READS, varchar(STMT_TEXT,100) as STMT_TEXT from READ_METRICS r left
outer join SYSIBMADM.MON_CURRENT_SQL s ON r.APPLICATION_HANDLE =
s.APPLICATION_HANDLE order by pool_data_l_reads desc"
printf '%s\n\n' "HEADER - $(date): Tablescans for queries"
db2 -v "with montable as ( SELECT varchar(tabschema,20) as tabschema,
varchar(tabname,20) as tabname, max(table_scans) as table_scans, sum(rows_read)
as table_rows_read FROM TABLE(MON_GET_TABLE('','',-2)) AS t WHERE tabschema not
in ('SYSCAT', 'SYSIBM', 'SYSIBMADM', 'SYSPUBLIC', 'SYSSTAT', 'SYSTOOLS' ) and
rows_read > 0 GROUP BY tabschema, tabname ) select tabschema, tabname,
max(table_scans) as table_scans, max(table_rows_read) as table_rows_read,
count(member) as NUM_MEMBER, max(NUM_EXEC_WITH_METRICS) as
STMT_NUM_EXECS_WITH_METRICS, decimal(sum(TOTAL_ACT_TIME)/1000.00,10,2) as
STMT_ACT_TIME_SEC, sum(ROWS_READ) as STMT_ROWS_READ,
sum(POOL_DATA_L_READS+POOL_INDEX_L_READS+
+POOL_TEMP_DATA_L_READS+POOL_TEMP_INDEX_L_READS) as STMT_POOL_L_READS,
sum(POOL_DATA_L_READS) as STMT_POOL_DATA_L_READS, sum(POOL_INDEX_L_READS) as
STMT_POOL_INDEX_L_READS, sum(POOL_TEMP_DATA_L_READS+POOL_TEMP_INDEX_L_READS) as
STMT_POOL_TEMP_L_READS, varchar(substr(s.stmt_text, 1,100),100) as stmt_text from
montable t, TABLE(MON_GET_PKG_CACHE_STMT('D', null, null, -2)) as s where
rows_read > 0 and lcase(s.stmt_text) like '%' || lcase(trim(t.tabschema)) || '%' ||
'.%' || lcase(trim(t.tabname)) || '%' group by t.tabschema, t.tabname,
varchar(substr(s.stmt_text, 1,100),100) order by stmt_rows_read "
printf '%s\n\n' "HEADER - $(date): SYSTEM RESOURCES INFO"
db2 -v "select current timestamp ts,* from table
(sysproc.env_get_system_resources())"
printf '\n\n%s\n\n' "HEADER - $(date): Top 20 active tables"
db2 -v "declare global temporary table session.temp_active_tables as
( select current timestamp as curr_tstamp, sum( OVERFLOW_ACCESSES ) as
OVERFLOW_ACCESSES, sum( ROWS_READ ) as ROWS_READ, sum( rows_inserted ) as
rows_inserted, sum( rows_updated ) as rows_updated, sum( rows_deleted ) as
rows_deleted, tabschema, tabname from table(mon_get_table(null,null,-2)) where
tab_type = 'USER_TABLE' group by tabschema, tabname ) with data on commit preserve
rows not logged"
db2 -v "commit"
printf '%s\n\n' "HEADER - $(date): sleeping 30 seconds"
sleep 30
db2 -v "with current_active_tables ( curr_tstamp , OVERFLOW_ACCESSES,
ROWS_READ , rows_inserted , rows_updated , rows_deleted , tabschema , tabname )
as ( select current timestamp as curr_timestamp , sum(OVERFLOW_ACCESSES) as
OVERFLOW_ACCESSES, sum( ROWS_READ ) as ROWS_READ , sum(rows_inserted) as
rows_inserted , sum( rows_updated ) as rows_updated , sum( rows_deleted ) as
rows_deleted , tabschema , tabname from table( mon_get_table(null,null,-2)) where
tab_type = 'USER_TABLE' group by tabschema, tabname with ur ) select
substr(to_char( current timestamp , 'YYYY-MM-DD-HH24.MI.SS' ),1,19) as curr_time ,
substr( a.tabschema,1,20) as schema , substr( a.tabname,1,45) as tabname , substr(
to_char( ( b.OVERFLOW_ACCESSES - a.OVERFLOW_ACCESSES ), '999,999,999,999' ), 1, 16
) as OVERFLOW_ACCESSES , substr( to_char( ( b.ROWS_READ - a.ROWS_READ ),
'999,999,999,999' ), 1, 16 ) as ROWS_READ , substr( to_char( ( b.rows_inserted -
a.rows_inserted ), '999,999,999,999' ), 1, 16 ) as rows_inserted ,
substr( to_char( ( b.rows_updated - a.rows_updated ), '999,999,999,999' ), 1, 16 )
as rows_updated , substr( to_char( ( b.rows_deleted - a.rows_deleted ),
'999,999,999,999' ), 1, 16 ) as rows_deleted ,
substr( to_char( int( ( b.OVERFLOW_ACCESSES - a.OVERFLOW_ACCESSES ) /
timestampdiff( 2, to_char( current timestamp - a.curr_tstamp )) ), '999,999,999' ),
1,11) as overflow_rows_p_sec, substr( to_char( int( ( b.ROWS_READ - a.ROWS_READ ) /
timestampdiff( 2, to_char( current timestamp - a.curr_tstamp )) ), '999,999,999' ),
1,11) as read_rows_p_sec , substr( to_char( int( ( b.rows_inserted -
a.rows_inserted ) / timestampdiff( 2, to_char( current timestamp - a.curr_tstamp ))
), '999,999,999' ), 1,11) as ins_rows_p_sec ,
substr( to_char( int( ( b.rows_updated - a.rows_updated ) / timestampdiff( 2,
to_char( current timestamp - a.curr_tstamp )) ), '999,999,999' ), 1,11) as
upd_rows_p_sec , substr( to_char( int( ( b.rows_deleted - a.rows_deleted ) /
timestampdiff( 2, to_char( current timestamp - a.curr_tstamp )) ), '999,999,999' ),
1,11) as del_rows_p_sec , (b.OVERFLOW_ACCESSES - a.OVERFLOW_ACCESSES)+
(b.ROWS_READ - a.ROWS_READ)+( b.rows_inserted- a.rows_inserted )+( b.rows_updated -
a.rows_updated )+( b.rows_deleted - a.rows_deleted ) as totalcnt from
session.temp_active_tables a, current_active_tables b where ( a.tabschema =
b.tabschema or ( a.tabschema IS NULL and b.tabschema is NULL )) and ( a.tabname =
b.tabname or ( a.tabname is NULL AND b.tabname is NULL)) and
( ( b.OVERFLOW_ACCESSES - a.OVERFLOW_ACCESSES ) > 0 OR ( b.ROWS_READ -
a.ROWS_READ ) > 0 OR ( b.rows_inserted - a.rows_inserted ) > 0 or ( b.rows_updated
- a.rows_updated ) > 0 or ( b.rows_deleted - a.rows_deleted ) > 0 ) union all
select substr(to_char( current timestamp , 'YYYY-MM-DD-HH24.MI.SS' ),1,19) as
curr_time , substr( b.tabschema,1,20) as schema , substr( b.tabname,1,45) as
tabname , substr( to_char( ( b.OVERFLOW_ACCESSES ), '999,999,999,999' ), 1, 16 )
as OVERFLOW_ACCESSES , substr( to_char( ( b.ROWS_READ ), '999,999,999,999' ), 1,
16 ) as ROWS_READ , substr( to_char( ( b.rows_inserted ), '999,999,999,999' ), 1,
16 ) as rows_inserted , substr( to_char( ( b.rows_updated ), '999,999,999,999' ),
1, 16 ) as rows_updated , substr( to_char( ( b.rows_deleted ),
'999,999,999,999' ), 1, 16 ) as rows_deleted , NULL as overflow_rows_p_sec, NULL
as read_rows_p_sec , NULL as ins_rows_p_sec , NULL as upd_rows_p_sec , NULL as
del_rows_p_sec ,
OVERFLOW_ACCESSES+b.ROWS_READ+b.rows_inserted+b.rows_updated+b.rows_deleted
as totalcnt from current_active_tables b where not exists ( select null from
session.temp_active_tables a where ( a.tabschema = b.tabschema or ( a.tabschema IS
NULL and b.tabschema is NULL )) and ( a.tabname = b.tabname or ( a.tabname is NULL
AND b.tabname is NULL)) and ( ( b.OVERFLOW_ACCESSES - a.OVERFLOW_ACCESSES ) > 0 OR
( b.ROWS_READ - a.ROWS_READ ) > 0 OR ( b.rows_inserted - a.rows_inserted ) > 0 or (
b.rows_updated - a.rows_updated ) > 0 or ( b.rows_deleted - a.rows_deleted ) >
0 ) ) order by totalcnt desc fetch first 20 rows only with ur"
} > $DUMPDIR/Batchqueries.$TS

ctr=1
cat $DUMPDIR/mon_get_pkg_cache_stmt.latch.$TS | awk '{print $1}' | grep "^x" | sort
| uniq | while read execid
do
db2 connect to $DBNAME
db2 "call explain_from_section( $execid, 'M', null, -1, '', ?,?,?,?,? )"
db2exfmt -d $DBNAME -1 -o $DUMPDIR/exfmt.mon_get_pkg_cache_stmt.latch.$( echo
$execid | tr -d "'" ).$ctr
((ctr=$ctr+1))
done
ctr=1
cat $DUMPDIR/elap_top_package_cache.$TS | awk '{print $1}' | grep "^x" | sort |
uniq | while read execid
do
db2 connect to $DBNAME
db2 "call explain_from_section( $execid, 'M', null, -1, '', ?,?,?,?,? )"
db2exfmt -d $DBNAME -1 -o $DUMPDIR/exfmt.elap_top_package_cache.$( echo $execid
| tr -d "'" ).$ctr
((ctr=$ctr+1))
done
ctr=1
cat $DUMPDIR/EXECUTABLE_ID.LATCH.mon_get_activity.$TS | awk '{print $1}' | grep
"^x" | sort | uniq | while read execid
do
db2 connect to $DBNAME
db2 "call explain_from_section( $execid, 'M', null, -1, '', ?,?,?,?,? )"
db2exfmt -d $DBNAME -1 -o $DUMPDIR/exfmt.LATCH.mon_get_activity.$( echo $execid
| tr -d "'" ).$ctr
((ctr=$ctr+1))
done
ctr=1
cat $DUMPDIR/EXECUTABLE_ID.ACTIVITY.mon_get_activity.$TS | awk '{print $1}' | grep
"^x" | sort | uniq | while read execid
do
db2 connect to $DBNAME
db2 "call explain_from_section( $execid, 'M', null, -1, '', ?,?,?,?,? )"
db2exfmt -d $DBNAME -1 -o $DUMPDIR/exfmt.ACTIVITY.mon_get_activity.$( echo
$execid | tr -d "'" ).$ctr
((ctr=$ctr+1))
done

if [ $APPDHL -gt "0" ]


then
echo "`date`: Executing db2trc apphdl $APPDHL"
db2trc on -t -apphdl $APPDHL $memberall
sleep 10
db2trc dmp trc1.ROW.$TS -sdir $DUMPDIR $memberall
sleep 10
db2trc dmp trc2.ROW.$TS -sdir $DUMPDIR $memberall
sleep 10
db2trc dmp trc3.ROW.$TS -sdir $DUMPDIR $memberall
db2trc off $memberall
echo "`date`: Executing db2trc CDE apphdl $APPDHL"
db2trc on -t -Madd CDE_PERF_TRACE -apphdl $APPDHL $memberall
sleep 10
db2trc dmp trc1.CDE.$TS -sdir $DUMPDIR $memberall
sleep 10
db2trc dmp trc2.CDE.$TS -sdir $DUMPDIR $memberall
sleep 10
db2trc dmp trc3.CDE.$TS -sdir $DUMPDIR $memberall
db2trc off $memberall
else
echo "`date`: Executing perfcount"
eval $rah db2trc on -perfcount -t -edu $quote
sleep 10
eval $rah db2trc dmp trc1.perfcount.$TS -sdir $DUMPDIR $quote
sleep 10
eval $rah db2trc dmp trc2.perfcount.$TS -sdir $DUMPDIR $quote
eval $rah db2trc off $quote

echo "`date`: Executing sqlbfix"


db2trc on -t -Madd sqlbfix $memberall
sleep 5
db2trc dmp trc1.sqlbfix.$TS -sdir $DUMPDIR $memberall
sleep 5
db2trc dmp trc2.sqlbfix.$TS -sdir $DUMPDIR $memberall
db2trc off $memberall
fi

echo "`date`: Executing db2mon 60"


~/sqllib/samples/perf/db2mon.sh $DBNAME 60 >> $DUMPDIR/db2mon_report.$TS

cat $DUMPDIR/db2mon_report.$TS | sed '/INF#EXPLN/,/record(s) selected./!d;//d' |


awk -v MATCHEXECID="$MATCHEXECID" ' { if ( $1 ~ /^[0-9]+$/ &&
tolower(substr($2,1,2)) == MATCHEXECID ) { print $1, $2} }' >
$DUMPDIR/db2mon_report.$TS.execids1
cat $DUMPDIR/db2mon_report.$TS | egrep "^COORD_MEMBER|^EXECUTABLE_ID" | awk
'{print $NF}' | sed 'N;s/\n/ /g' | awk -v MATCHEXECID="$MATCHEXECID" '{ if ( $1
~ /^[0-9]+$/ && tolower(substr($2,1,2)) == MATCHEXECID ) { print $1, $2} }' >
$DUMPDIR/db2mon_report.$TS.execids2

ctr=1
cat $DUMPDIR/db2mon_report.$TS.execids1 $DUMPDIR/db2mon_report.$TS.execids2 | sort
| uniq | while read rec
do
coord=$( echo $rec | awk '{ print $1; }' )
executable_id=$( echo $rec | awk '{ print $2 }' )
fmtexecid=$( echo $executable_id | tr -d "'" )

if ls $DUMPDIR/exfmt."db2mon_report.$TS".*."$fmtexecid" 1> /dev/null 2>&1 ;


then

echo "`date`: Skipping exfmt: in $DUMPDIR/exfmt."db2mon_report.


$TS".*."$fmtexecid" for filename: db2mon_report.$TS"
else

db2 connect to $DBNAME


db2 "call explain_from_section( $executable_id, 'M', NULL, $coord,
NULL, ?, ?, ?, ?, ? ) " >> $DUMPDIR/explain_section.db2mon_report.$TS.$ctr.
$fmtexecid
db2 terminate
check_success=$( cat $DUMPDIR/explain_section.db2mon_report.$TS.$ctr.
$fmtexecid | grep -i "Parameter Value" | awk '{ print $NF; }' | grep "20.*-" >
/dev/null; echo $? )

if [ $check_success -eq 0 ]; then

param_values=$( cat $DUMPDIR/explain_section.db2mon_report.$TS.


$ctr.$fmtexecid | grep -i "Parameter Value" | awk '{ print $NF; }' )
param1=$( echo $param_values | awk '{ print $1; }' )
param3=$( echo $param_values | awk '{ print $3; }' )
param4=$( echo $param_values | awk '{ print $4; }' )
param5=$( echo $param_values | awk '{ print $5; }' )

db2exfmt -d $DBNAME -e $param1 -w $param3 -n $param4 -s $param5 -


t -# 0 > $DUMPDIR/exfmt.db2mon_report.$TS.$ctr.$fmtexecid
echo "Collected explain ( db2mon_report.$TS ) Execid:
$executable_id , File: $DUMPDIR/exfmt.db2mon_report.$TS.$ctr.$fmtexecid "
fi
fi
((ctr=$ctr+1))
done

QH1="select executable_id, STMTID, PLANID, max_coord_stmt_exec_time, STMT_TEXT ,


XMLPARSE(DOCUMENT max_coord_stmt_exec_time_args) max_coord_stmt_exec_time_args FROM
TABLE(MON_GET_PKG_CACHE_STMT(NULL,NULL,NULL,-2)) where
max_coord_stmt_exec_time_args IS NOT NULL AND STMTID in ( "
QH2=$( cat $DUMPDIR/db2mon_report.$TS | sed '/INF#EXPLN/,/record(s) selected./!
d;//d' | awk ' { if ( $1 ~ /^[0-9]+$/ && tolower(substr($2,1,2)) == "x\x27" )
{ print $4","} }' | sort | uniq | tr '\n' ' ' )
QH3=" 0) "
FQ="$QH1 $QH2 $QH3"
db2 connect to $DBNAME
db2 -v "$FQ" > $DUMPDIR/values.db2mon_report.$TS.out
db2 terminate
}

TM=`date '+%Y-%m-%d-%H.%M.%S'`
HDIR=$SDIR/"db2Dump_$TM"
mkdir -p $HDIR
if [ $? -eq 0 ]; then
chmod 777 "$HDIR"
else
echo "Unable to create directory: $HDIR .. bailing out !!"
exit 0
fi

{
echo "`date` Starting:" "$0" "$@"

for TIMES in 1 2 3
do
TM=`date '+%Y-%m-%d-%H.%M.%S'`
echo "`date`: LOOP $TIMES at $TM dumping in $HDIR/$TM"
collect_data $HDIR/$TM
sleep 5
done

echo "`date`: Formatting db2traces"


if [ $APPDHL -gt "0" ]
then
for files in `ls $HDIR/*/trc*.CDE.*`
do
echo "`date`: Formatting file: $files "
fname=$(basename "$files")
fdirname=$(dirname $(absPath "$files"))
db2trc fmt $files $fdirname/fmt.$fname
done
for files in `ls $HDIR/*/trc*.ROW.*`
do
echo "`date`: Formatting file: $files "
fname=$(basename "$files")
fdirname=$(dirname $(absPath "$files"))
db2trc fmt $files $fdirname/fmt.$fname
db2trc flw -t $files $fdirname/flw.$fname
db2trc flw -t -data $files $fdirname/data.flw.$fname
db2trc flw -t -rds $files $fdirname/rds.flw.$fname
db2trc perfrep -rds -g -sort timeelapsed $files
$fdirname/perfrep.$fname
done
else
for files in `ls $HDIR/*/trc*.perfcount.*`
do
echo "`date`: Formatting file: $files "
fname=$(basename "$files")
fdirname=$(dirname $(absPath "$files"))
db2trc perffmt $files $fdirname/perffmt.$fname
done
for files in `ls $HDIR/*/trc*.sqlbfix.*`
do
echo "`date`: Formatting file: $files "
fname=$(basename "$files")
fdirname=$(dirname $(absPath "$files"))
db2trc fmt $files $fdirname/fmt.$fname
db2trc flw -t $files $fdirname/flw.$fname
db2trc flw -t -data $files $fdirname/data.flw.$fname
db2trc perfrep -rds -g -sort timeelapsed $files
$fdirname/perfrep.$fname
done
fi

db2 connect to $DBNAME


db2 +c -v "call REORGCHK_TB_STATS('T','ALL')" >
$HDIR/REORGCHK_TB_STATS.`hostname`.out
db2 +c -v "select table_schema, table_name,DATAPARTITIONNAME,card,overflow,
f1, f2, f3, reorg from SESSION.TB_STATS where REORG LIKE '%*%'" >
$HDIR/NeedTSReorg.`hostname`.out
db2 +c -v "CALL SYSPROC.REORGCHK_IX_STATS('T', 'ALL')" >
$HDIR/REORGCHK_IX_STATS.`hostname`.out
db2 +c -v "SELECT
TABLE_SCHEMA,TABLE_NAME,INDEX_SCHEMA,INDEX_NAME,DATAPARTITIONNAME,INDCARD,F4,F5,F6,
F7,F8,REORG FROM SESSION.IX_STATS WHERE REORG LIKE '%*%'" >
$HDIR/NeedTXReorg.`hostname`.out
db2 -v "select
TABSCHEMA,TABNAME,CREATE_TIME,ALTER_TIME,INVALIDATE_TIME,STATS_TIME,COLCOUNT,TABLEI
D,TBSPACEID,CARD,NPAGES,MPAGES,FPAGES,OVERFLOW,LASTUSED,TABLEORG from syscat.tables
WHERE TABSCHEMA NOT LIKE 'SYS%' AND TYPE = 'T' order by
STATS_TIME,TABSCHEMA,TABNAME " > $HDIR/syscat_tables.`hostname`.out

echo "`date` Ending:" "$0" "$@"

} 2>&1 | tee -ia -- "$HDIR/bash.log"

####mv $SDIR/bash.log $HDIR


####mv $SDIR/output.log $HDIR

You might also like