在生产环境维护中,如果碰到较长时间的锁等待,很可能会造成各种可能的问题。我们可以使用如下的脚本来实时监控锁的情况。
sqlplus -S $DB_CONN_STR@$SH_DB_SID
set linesize 160
set pages 100
set feedback off
set verify off
set echo on
col object_name format a25
col osuser format a10
col machine format a12
col program format a20
--col object_type format a10
col state format a10
col status format a10
col oracle_username format a12
col sid_serial format a12
col sec_wait format 99999999
col lock_type format a5
col mode_held format a10
set linesize 200
prompt Current Locks
prompt --------------
select ses.sid||','||ses.serial# sid_serial,loc.oracle_username,object_name,
--object_type,
ses.LOGON_TIME,ses.SECONDS_IN_WAIT sec_wait,ses.osuser,ses.machine,ses.program,ses.state,ses.status,
decode(d.type,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distrib Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
d.type) lock_type,
decode(d.lmode,
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', /* X */
to_char(d.lmode)) mode_held
from v\$locked_object loc,v\$session ses,dba_objects obj,v\$lock d
where loc.object_id=obj.object_id
and loc.session_id=ses.sid
and obj.object_id=d.id1
and ses.sid=d.sid
order by oracle_username,seconds_in_wait desc
;
set head off
SELECT 'There are also '||count(*)||' transaction locks'
FROM v\$transaction_enqueue
;
prompt
prompt Blocking Session Details
select BLOCKING_SESSION ||' IS BLOCKING '||sid||','||serial# from v\$session where blocking_session is not null;
exit
EOF
脚本运行的结果如下:
Current Locks
-------------
SID_SERIAL ORACLE_USERN OBJECT_NAME LOGON_TIM SEC_WAIT OSUSER MACHINE PROGRAM STATE STATUS LOCK_ MODE_HELD
------------ ------------ ------------------------- --------- --------- ---------- ------------ -------------------- ---------- ---------- ----- ----------
5480,2261 PRODUSER TMP_CONTROL 04-DEC-14 419010 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5480,2261 PRODUSER TMP_CONTROL 04-DEC-14 419010 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
4086,35783 PRODUSER TMP_CONTROL 08-DEC-14 44446 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
4086,35783 PRODUSER TMP_CONTROL 08-DEC-14 44446 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
7190,24855 PRODUSER TMP_CONTROL 09-DEC-14 8601 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
7190,24855 PRODUSER TMP_CONTROL 09-DEC-14 8601 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
8322,17323 PRODUSER BILL_SUMMARY 09-DEC-14 1597 lwrk01 fromClient2 sqlplus@ccbdbpr1 (TNS V1-V3) WAITING ACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE TO Row-X (SX)
5179,65435 PRODUSER TEMP_DAEMON_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE TO Row-X (SX)
相关文章
- 11-20《怎样实现通过shell脚本将用户踢出系统》
- 11-20postgres之通过 python和shell脚本迁移数据
- 11-20shell脚本查看网络配置
- 11-20分享一个shell脚本:通过Jumper机器来创建Jumper和target机器账号
- 11-20【Azure Developer】Azure REST API: 如何通过 API查看 Recovery Services Vaults(恢复保管库)的备份策略信息? 如备份中是否含有虚拟机的Dis
- 11-20一个shell脚本实现应用启动|停止|重启|查看状态
- 11-20? 原创: 铲子哥 搜狗测试 今天 shell编程的时候,往往不会把所有功能都写在一个脚本中,这样不太好维护,需要多个脚本文件协同工作。那么问题来了,在一个脚本中怎么调用其他的脚本呢?有三种方式,分别是fork、source和exec。 1. fork 即通过sh 脚本名进行执行脚本的方式。下面通过一个简单的例子来讲解下它的特性。 创建father.sh,内容如下: #!/bin/bas
- 11-20常用脚本--查看当前锁信息
- 11-20Esxi6.7 + Lsi 9260 8i阵列卡,通过MegaCli工具查看硬盘健状态及阵列卡信息
- 11-20使用shell脚本监控少量服务器并发送微信告警信息