Sei sulla pagina 1di 4

Types of Latches and Locks

--------------------------
Transaction locks, row-level locks
buffer locks
data dictionary locks
enques
library cache
Lock Modes
----------
Simple/compound Objects:
exclusive - session needs modify simple object
shared - session needs to view a simple object
null - if session caches info about object, null lock is placed
on it, will act as trigger if object is invalidated
Compound Objects Only:
sub-shared - shared subobject (same rows in a table)
Ex: cursor cur1 is select * from test where x=20
for update;
sub-exclusive - session needs exclusive lock on part of subobjec
t
shared sub-exclusive - session needs exclusive lock on part of subobjec
t
shared sub-exclusive - session needs exclusive lock on some rows, share
d lock on whole table
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------
dba_locks
dba_dml_locks
dba_ddl_locks
dba_blockers
dba_waiters
DML Locks:
----------
select session_id, owner, name, mode_held from dba_dml_locks;
Waiting session for a Lock:
---------------------------
select waiting_session, holding_session, lock_type, mode_held from dba_waiters;
--- select init_trans, max_trans from dba_tables where table_name='EMP' and owne
r='SCOTT';

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------
SELECT a.sid,
a.serial#,
b.username ,
opname OPERATION,
target OBJECT,
TRUNC(elapsed_seconds, 5) "ET (s)",
TO_CHAR(start_time, 'HH24:MI:SS') start_time,
ROUND((sofar/totalwork)*100, 2) "COMPLETE (%)"
FROM gv$session_longops a,
gv$session b
WHERE a.sid = b.sid AND
b.username not IN ('SYS', 'SYSTEM') AND
totalwork > 0
ORDER BY elapsed_seconds;

Hi Venkat,
Get the details of these information of SID: 469*470 (sid, serial#, logon_time,
blocker, blocked_object) and pass to Albert
Regards,
Zhang

----Lock Information---
set pagesize 85
col username format a10
col osuser format a15
col sid format 9999
col serial format 99999
col type format a2
col request format 9
col lmode format 9
col lmode_desc format a16
col type_desc format a30 wrap
SELECT /*+ FIRST_ROWS ORDERED */ username,
s.osuser osuser , s.sid sid , s.serial# serial, l.lmode lmode ,
decode(L.LMODE,1,'No Lock',
2,'Row Share',
3,'Row Exclusive',
4,'Share',
5,'Share Row Exclusive',
6,'Exclusive','NONE') lmode_desc, l.type type ,
decode(l.type,
'BL','Buffer hash table instance lock',
'CF',' Control file schema global enqueue lock',
'CI','Cross-instance function invocation instance lock',
'CS','Control file schema global enqueue lock',
'CU','Cursor bind lock',
'DF','Data file instance lock',
'DL','Direct loader parallel index create',
'DM','Mount/startup db primary/secondary instance lock',
'DR','Distributed recovery process lock',
'DX','Distributed transaction entry lock',
'FI','SGA open-file information lock',
'FS','File set lock',
'HW','Space management operations on a specific segment lock',
'IN','Instance number lock',
'IR','Instance recovery serialization global enqueue lock',
'IS','Instance state lock',
'IV','Library cache invalidation instance lock',
'JQ','Job queue lock',
'KK','Thread kick lock',
'MB','Master buffer hash table instance lock',
'MM','Mount definition gloabal enqueue lock',
'MR','Media recovery lock',
'PF','Password file lock',
'PI','Parallel operation lock',
'PR','Process startup lock',
'PS','Parallel operation lock',
'RE','USE_ROW_ENQUEUE enforcement lock',
'RT','Redo thread global enqueue lock',
'RW','Row wait enqueue lock',
'SC','System commit number instance lock',
'SH','System commit number high water mark enqueue lock',
'SM','SMON lock',
'SN','Sequence number instance lock',
'SQ','Sequence number enqueue lock',
'SS','Sort segment lock',
'ST','Space transaction enqueue lock',
'SV','Sequence number value lock',
'TA','Generic enqueue lock',
'TD','DDL enqueue lock',
'TE','Extend-segment enqueue lock',
'TM','DML enqueue lock',
'TT','Temporary table enqueue lock',
'TX','Transaction enqueue lock',
'UL','User supplied lock',
'UN','User name lock',
'US','Undo segment DDL lock',
'WL','Being-written redo log instance lock',
'WS','Write-atomic-log-switch global enqueue lock') type_desc ,
request , block
FROM v$lock l, v$session s
WHERE s.sid = l.sid
AND l.type <> 'MR'
AND s.type <> 'BACKGROUND'
ORDER BY username
/
USERNAME OSUSER SID SERIAL LMODE LMODE_DESC TY TYPE_DESC
REQUEST BLOCK
---------- --------------- ----- ------ ----- ---------------- -- --------------
---------------- ------- ----------
OPSPRD weblogic 469 38486 0 NONE TX Transaction en
queue lock 4 0
OPSPRD weblogic 470 43442 3 Row Exclusive TM DML enqueue lo
ck 0 2
OPSPRD weblogic 470 43442 6 Exclusive TX Transaction en
queue lock 0 1
OPSPRD weblogic 470 43442 3 Row Exclusive TM DML enqueue lo
ck 0 2
OPSPRD weblogic 469 38486 6 Exclusive TX Transaction en
queue lock 0 2
OPSPRD weblogic 469 38486 3 Row Exclusive TM DML enqueue lo
ck 0 2
6 rows selected.
What waits are occurring in your database?
------------------------------------------
set lines 300 pages 500
Select wait_class, sum(time_waited), sum(time_waited)/sum(total_waits)
Sum_Waits
From v$system_wait_class
Group by wait_class
Order by 3 desc;
Select a.event, a.total_waits, a.time_waited, a.average_wait
From v$system_event a, v$event_name b, v$system_wait_class c
Where a.event_id=b.event_id
And b.wait_class#=c.wait_class#
And c.wait_class in ('Application','Concurrency')
order by average_wait desc;
select a.sid, a.event, a.total_waits, a.time_waited, a.average_wait
from v$session_event a, v$session b
where time_waited > 0
and a.sid=b.sid
and b.username is not NULL
and a.event='enq: TX - row lock contention';
SELECT
wait_class,
NAME,
ROUND (time_secs, 2) time_secs,
ROUND (time_secs * 100 / SUM (time_secs) OVER (), 2) pct
FROM
(SELECT
n.wait_class,
e.event NAME,
e.time_waited / 100 time_secs
FROM
v$system_event e,
v$event_name n
WHERE
n.NAME = e.event AND n.wait_class <> 'Idle'
AND
time_waited > 0
UNION
SELECT
'CPU',
'server CPU',
SUM (VALUE / 1000000) time_secs
FROM
v$sys_time_model
WHERE
stat_name IN ('background cpu time', 'DB CPU'))
ORDER BY time_secs DESC;

Potrebbero piacerti anche