|
| 1 | +#!/bin/ksh |
| 2 | +# |
| 3 | +# locksql.sh |
| 4 | +# |
| 5 | +# Gets details of locking and waiting sessions |
| 6 | +# - Locked objects |
| 7 | +# - SQLs being run |
| 8 | +# |
| 9 | +# NOTE: Holding session's sql cannot be listed somehow from v$sql_text |
| 10 | +# |
| 11 | + |
| 12 | +# Set environment here |
| 13 | +export ORACLE_SID= |
| 14 | +export ORACLE_BASE= |
| 15 | +export ORACLE_HOME= |
| 16 | +export LD_LIBRARY_PATH= |
| 17 | +export PATH= |
| 18 | +export LIBPATH= |
| 19 | + |
| 20 | +scriptpath=$0 |
| 21 | +script=`basename $scriptpath` |
| 22 | +scriptdir=`dirname $scriptpath` |
| 23 | +cd $scriptdir |
| 24 | +scriptdir=`pwd` |
| 25 | +installdir=`dirname $scriptdir` |
| 26 | + |
| 27 | +logdir=${scriptdir} |
| 28 | +logfile=${logdir}/${script}.log |
| 29 | +tmpfile1=${logdir}/${script}.tmp1 |
| 30 | +tmpfile2=${logdir}/${script}.tmp2 |
| 31 | + |
| 32 | + |
| 33 | +exec >> $logfile 2>> $logfile |
| 34 | + |
| 35 | +echo |
| 36 | +echo ===================================== |
| 37 | +echo INFO - Locks at `date` |
| 38 | + |
| 39 | + |
| 40 | +sqlplus -s / as sysdba <<EOF |
| 41 | +
|
| 42 | +set pages 1000 |
| 43 | +set lines 200 |
| 44 | +
|
| 45 | +prompt |
| 46 | +prompt Listing from dba_waiters |
| 47 | +prompt ======================== |
| 48 | +select * from dba_waiters; |
| 49 | +
|
| 50 | +prompt |
| 51 | +prompt Locked objects by Holding Session |
| 52 | +prompt ================================= |
| 53 | +select * |
| 54 | +from gv\$locked_object a, |
| 55 | + dba_waiters b |
| 56 | +where a.session_id = b.holding_session; |
| 57 | +
|
| 58 | +
|
| 59 | +prompt |
| 60 | +prompt Locked objects by Waiting Session |
| 61 | +prompt ================================= |
| 62 | +select * |
| 63 | +from gv\$locked_object a, |
| 64 | + dba_waiters b |
| 65 | +where a.session_id = b.waiting_session; |
| 66 | +
|
| 67 | +
|
| 68 | +prompt |
| 69 | +prompt Holding session |
| 70 | +prompt =================== |
| 71 | +
|
| 72 | +select b.inst_id, b.sid, b.username, b.machine, b.osuser, b.module, b.sql_id, b.sql_hash_value, c.sql_text |
| 73 | +from dba_waiters a, gv\$session b, gv\$sql c |
| 74 | +where a.holding_session = b.sid |
| 75 | +and b.sql_id = c.sql_id |
| 76 | +and b.sql_hash_value = c.hash_value; |
| 77 | +--and b.sql_child_number = c.child_number; |
| 78 | +
|
| 79 | +prompt |
| 80 | +prompt Waiting session |
| 81 | +prompt =================== |
| 82 | +
|
| 83 | +select b.inst_id, b.sid, b.username, b.machine, b.osuser, b.module, b.sql_id, b.sql_hash_value, c.sql_text |
| 84 | +from dba_waiters a, gv\$session b, gv\$sql c |
| 85 | +where a.waiting_session = b.sid |
| 86 | +and b.sql_id = c.sql_id |
| 87 | +and b.sql_hash_value = c.hash_value; |
| 88 | +--and b.sql_child_number = c.child_number; |
| 89 | +
|
| 90 | +
|
| 91 | +EOF |
0 commit comments