#!/usr/bin/ksh #set -xv # This scripts contains also: #--------------------------------------------------------------------------------- #-- Script: latch_spins.sql, latch_sleeps.sql #-- Purpose: shows latch spin statistics #-- Copyright: (c) 1998 Ixora Pty Ltd #-- Author: Steve Adams, adapted to smenu by B. Polarski # ---------------------------------------------------------------------- # # B. Polarski : I added SQL extracted from the excellent Oracle wait interface # from Shee, Deshpande, Gopalakrishanan - Oracle Press function help { cat < # show lat difference between seconds lat -a # latch statistics including latches without misses lat -n # latch name and number, eventually for only one lat -m # latch misses from v\$latch_misses lat -sp # latch spining lat -o # Show latch location lat -cbc # List Cache buffer chain latches sorted by sleeps count lat -bh # Show objects and touch count covered by latch raw addr lat -mis # show location of latch misses (use lat -n to exact get name) lat -c # children latch count and stats lat -e # children latch sleeping lat -i # children latch sleeping impact lat -p # Show number of latch sub pool lat -l # lock held on library cache objects (v\$access) lat -t # report current latch activity lat -w # Report Latch sleeps EOF exit } # ---------------------------------------------------------------------- ACTION=DEFAULT TITTLE="Show Latch statistics" WHERE=" where a.misses <> 0 " if [ -z "$1" ];then help fi while [ -n "$1" ] do case "$1" in -a ) unset WHERE ;; -c ) ACTION=CHILDREN ; TITTLE="Report latch types with child counts and distribution" ;; -e ) ACTION=SLEEP ; TITTLE="Report children latch sleeping";; -i ) ACTION=IMPACT ; TITTLE="Latch sleeps impact";; -l ) ACTION=LIB ; TITTLE="lock held on library cache objects" ; FSID=$2; shift;; -s ) ACTION=DEFAULT ;; -m ) ACTION=MISS ; TITTLE="latch misses from v\\\$latch_misses";; -n ) ACTION=NAME if [ -n "$2" ] ;then WHERE="where latch# = '$2'" shift else WHERE= fi TITTLE="Report latch name and id" ;; -o ) ACTION=LOCATION ; TITTLE="latch location";; -cbc ) ACTION=CBC ; TITTLE="List Cache buffer chain latches sorted by sleeps count";; -bh ) ACTION=BH ; TITTLE="List object and touch count protected by latch $2" ; LATCH_RAW_NR=$2 ; shift ;; -mis ) ACTION=MIS ; TITTLE="show location of latch misses" ; shift; LATCH_NAME=$@ ; break;; -p ) ACTION=SUBPOOL ; TITTLE="Show number of sub pool in shared_pool" ; S_USER=SYS ;; -sp ) ACTION=SPIN ; TITTLE="Report spin gets";; -d ) ACTION=DIFF ; SLEEP_TIME=$2 ;shift;; -t ) ACTION=ACTIVITY ; TITTLE="report current latch activity" ;; -w ) ACTION=LATW ; TITTLE="Report Latch sleeps" ;; -h ) help ;; * ) echo "Unknown parameters $1" ; echo ; help ;; esac shift done . $SBIN/scripts/passwd.env . ${GET_PASSWD} $S_USER $ORACLE_SID if [ "x-$CONNECT_STRING" = "x-" ];then echo "could no get a the password of $S_USER" exit 0 fi # ............................................................................................... # ------------------------------ # report current latch activity # ------------------------------ if [ "$ACTION" = "LATW" ];then SQL=" column spec format a124 heading 'Message' column evt format a124 heading 'Message' column name format a24 heading 'Latch Name' column event format a40 heading 'Event name' column waits_holding_latch format 99999999 heading 'Wait | holding latch' column sleeps format 99999999 heading 'Number|Sleeps' column sw format 999999 heading 'Seconds| Waiting' column sid format 9999 heading 'Sid' set lines 190 SELECT w.sid , w.event,n.name, w.p3 Sleeps, w.seconds_in_wait sw , p1, p1raw, p2, p2raw $DETAIL_L $DETAIL_E FROM V\$SESSION_WAIT w, V\$LATCHNAME n WHERE w.event not in ('rdbms ipc message') and w.p2 = n.latch# and latch# not in (1) order by w.sid ; " # ------------------------------ # report current latch activity # ------------------------------ elif [ "$ACTION" = "ACTIVITY" ];then SQL=" set linesize 150 column name format a24 heading 'Latch type' column event format a60 heading 'Event name' column waits_holding_latch format 99999999 heading 'Wait | holding latch' column sleeps format 99999999 heading 'Number|Sleeps' column sw format 999999 heading 'Seconds| Waiting' column sid format 9999 heading 'Sid' select b.sid, event, name, sleeps , sw , address from v\$open_cursor a, ( SELECT w.sid, w.event,n.name, SUM(w.p3) Sleeps, SUM(w.seconds_in_wait) sw FROM V\$SESSION_WAIT w, V\$LATCHNAME n WHERE w.p2 = n.latch# and latch# not in (1) GROUP BY w.sid, n.name, w.event ) b where b.sid = a.sid / " # ------------------------------ # Show diff latch # ------------------------------ elif [ "$ACTION" = "DIFF" ];then sqlplus -s "$CONNECT_STRING" < 0; " # ------------------------------ # Latch sleeping # ------------------------------ elif [ "$ACTION" = "IMPACT" ];then SQL="select l.name, l.sleeps * l.sleeps / (l.misses - l.spin_gets) impact, lpad(to_char(100 * l.sleeps / l.gets, '990.00') || '%', 10) sleep_rate, l.waits_holding_latch, l.level# from v\$latch l where l.sleeps > 0 order by 2 desc; " # ------------------------------ # Latch Spining # ------------------------------ elif [ "$ACTION" = "SPIN" ];then SQL="select l.name, l.spin_gets, l.misses - l.spin_gets sleep_gets, lpad(to_char(100 * l.spin_gets / l.misses, '990.00') || '%', 13) hit_rate from v\$latch l where l.misses > 0 order by l.misses - l.spin_gets desc ; prompt select 'ALL LATCHES' name, sum(l.spin_gets) spin_gets, sum(l.misses - l.spin_gets) sleep_gets, lpad( to_char(100 * sum(l.spin_gets) / sum(l.misses), '990.00') || '%', 13) hit_rate from v\$latch l where l.misses > 0 ; " # ------------------------------ # Latch by name and id # ------------------------------ elif [ "$ACTION" = "CHILDREN" ];then SQL="SELECT a.name, count(a.latch#) total, sum(b.gets) sg, sum(b.misses) sm, sum(b.sleeps) ss FROM v\$latch a, v\$latch_children b WHERE b.latch# = a.latch# group by a.name, a.latch# ORDER BY 1 asc ,5 desc;" # ------------------------------ # Latch by name and id # ------------------------------ elif [ "$ACTION" = "NAME" ];then SQL="column name format a45 select latch#,name from v\$latchname $WHERE; " # ------------------------------ # Default # ------------------------------ elif [ "$ACTION" = "DEFAULT" ];then SQL=" select a.name fname, a.immediate_gets,a.immediate_misses, a.gets gets, a.misses misses ,a.misses*100/decode(a.gets,0,1,a.gets) miss,sleeps ,to_char(a.spin_gets*100/decode(a.misses,0,1,a.misses),'990.9') cspins ,to_char(a.sleep1*100/decode(a.misses,0,1,a.misses),'990.9') csleep1 ,to_char(a.sleep2*100/decode(a.misses,0,1,a.misses),'990.9') csleep2 ,to_char(a.sleep3*100/decode(a.misses,0,1,a.misses),'990.9') csleep3 from v\$latch a $WHERE order by 4 desc; " fi # ............................................................................................... sqlplus -s "$CONNECT_STRING" <