- 论坛徽章:
- 0
|
[原创]15.监控oracle是否有锁。
#mon_db_lock.sh
. .profile
cd /home/mxin/mon
if [ `date +%H%M` = "0800" ]; then
echo 0 > warn_count
fi
warn_count=`cat warn_count`
sqlplus "/as sysdba" <<EOF
set feed off;
set heading off;
spool /tmp/db_lock.out1;
@mon_db_lock.sql
spool off;
exit
EOF
sleep 13
sqlplus "/as sysdba" <<EOF
set feed off;
set heading off;
spool /tmp/db_lock.out2;
@mon_db_lock.sql
spool off;
exit
EOF
sleep 27
sqlplus "/as sysdba" <<EOF
set feed off;
set heading off;
spool /tmp/db_lock.out3;
@mon_db_lock.sql
spool off;
exit
EOF
cat /tmp/db_lock.out1|grep -v SQL|grep [0-9] >/tmp/mon_db_lock.out1
cat /tmp/db_lock.out2|grep -v SQL|grep [0-9] >/tmp/mon_db_lock.out2
cat /tmp/db_lock.out3|grep -v SQL|grep [0-9] >/tmp/mon_db_lock.out3
cat /tmp/mon_db_lock.out1|grep -v SQL|grep [0-9]|awk '{print "grep \""$0"\" /tmp/mon_db_lock.out2"}'|sh >/tmp/db_lock1
if [ `cat /tmp/db_lock1|wc -l` -gt 0 ] ; then
cat /tmp/mon_db_lock.out2|grep -v SQL|grep [0-9]|awk '{print "grep \""$0"\" /tmp/mon_db_lock.out3"}'|sh >/tmp/db_lock2
if [ `cat /tmp/db_lock2|wc -l` -gt 0 ] ; then
cat /tmp/mon_db_lock.out3|grep -v SQL|grep [0-9]|awk '{print "grep \""$0"\" /tmp/mon_db_lock.out.old"}'|sh >/tmp/db_lock3
if [ `cat /tmp/db_lock3|wc -l` -gt 0 ] ; then
cat /tmp/db_lock3|awk '{print "wall db lock-------\" "$0 "\"!!" }'|sh
let warn_count=$warn_count+1
fi
fi
fi
cp /tmp/mon_db_lock.out3 /tmp/mon_db_lock.out.old
if [ $warn_count -gt 4 ] ; then
beep.sh
echo 0 > warn_count
fi
#mon_db_lock.sql
set linesize 256
col object_name format a18
col object_id format 99999999
col Locked_Mode format a15
col SERIAL# format 9999999
col session_id format 999999
col oracle_username format a15
col os_user_name format a15
col process format 9999999
SELECT substr(b.object_name,1,1 object_name,a.object_id,
decode( a.locked_mode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive',
a.locked_mode) Locked_Mode, /* X */
session_id, SERIAL#,oracle_username, os_user_name, a.process
FROM v$LOCKED_OBJECT a, dba_OBJECTS b,v$session c
WHERE a.object_id = b.object_id and a.session_id=c.sid
/ |
|