forked from jeanron100/dbm_lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showlock.sh
129 lines (122 loc) · 4.33 KB
/
showlock.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
sqlplus -S $DB_CONN_STR@$SH_DB_SID <<EOF
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 l1.sid, ' IS BLOCKING ', l2.sid
--from v\$lock l1, v\$lock l2
-- where l1.block =1 and l2.request > 0
-- and l1.id1=l2.id1
-- and l1.id2=l2.id2
--/
select BLOCKING_SESSION ||' IS BLOCKING '||sid||','||serial# from v\$session where blocking_session is not null;
exit
EOF
#set head off
#prompt
#prompt Waiting Sessions
#prompt -----------------
#SELECT lh.sid Locked_Sid,
# lw.sid Waiter_Sid,
#decode ( lh.type, 'MR', 'Media_recovery',
# 'RT', 'Redo_thread',
# 'UN', 'User_name',
# 'TX', 'Transaction',
# 'TM', 'Dml',
# 'UL', 'PLSQL User_lock',
# 'DX', 'Distrted_Transaxion',
# 'CF', 'Control_file',
# 'IS', 'Instance_state',
# 'FS', 'File_set',
# 'IR', 'Instance_recovery',
# 'ST', 'Diskspace Transaction',
# 'IV', 'Libcache_invalidation',
# 'LS', 'LogStaartORswitch',
# 'RW', 'Row_wait',
# 'SQ', 'Sequence_no',
# 'TE', 'Extend_table',
# 'TT', 'Temp_table',
# 'TO', 'Temporary Objects',
# 'Nothing-' ) Waiter_Lock_Type,
# decode ( lw.request, 0, 'None',
# 1, 'NoLock',
# 2, 'Row-Share',
# 3, 'Row-Exclusive',
# 4, 'Share-Table',
# 5, 'Share-Row-Exclusive',
# 6, 'Exclusive',
# 'Nothing-' ) Waiter_Mode_Req,
# sysdate Lock_Time
#FROM v\$lock lw, v\$lock lh
#WHERE lh.id1=lw.id1
# AND lh.id2=lw.id2
# AND lh.request=0
# AND lw.lmode=0
# AND (lh.id1,lh.id2) in (
# SELECT id1,id2 FROM v\$lock WHERE request=0
# INTERSECT
# SELECT id1,id2 FROM v\$lock WHERE lmode=0 )
#;