프린트 하기

OS환경 : Oracle Linux6.8(64bit)


DB 환경 : Oracle Database 11.2.0.4


방법 : Enq: UL - Contention, PL/SQL lock Timer


DBMS_LOCK 패키지를 사용하면 사용자가 임의의 가상적인 자원에 대해 락 설정 가능

DML에 의해 발생하는 락의 경우 반드시 물리적인 자원(테이블/트랜잭션/세그먼트 등)

을 필요로 하지만, DBMS_LOCK 패키지를 사용할 경우에는 이런 제한이 없다.

DBMS_LOCK 패키지를 이용해 획득하는 락을 UL(User-defined Lock)락이라 부른다.

UL락을 장시간 보유함으로써 동시성 문제를 일으키고 있다면 세션을 강제로

종료시키는 것 외에는 대안이 없다. DBMS_LOCK.REQUEST 함수 사용시 가능하면

RELEASE_ON_COMMIT 옵셥을 사용해서 불필요하게 락을 보유하지 않도록 하는 것이 좋다.

이 옵션을 사용하면 커밋이나 롤백이 발생하면 해당 트랜잭션이 보유하던

UL락을 자동으로 해제 한다.


이벤트 발생 테스트

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
#세션1
declare
v_no number;
begin
v_no := dbms_lock.request(1);
end;
/
 
#세션2
declare
v_no number;
begin
v_no := dbms_lock.request(1);
end;
/
=> 행 발생
 
세션3
select a.sid, a.type, a.id1, a.id2, a.lmode, a.request, b.object_name
from v$lock a, dba_objects b
where a.sid in (50,27)
and a.id1 = b.object_id(+)
order by a.sid;
 
       SID TY         ID1    ID2     LMODE      REQUEST OBJECT_NAME
---------- -- ---------- ---------- ---------- ---------- ------------------------------
    27 AE         100      0         4        0 ORA$BASE
    27 UL           1      0         6        0 (null)
    50 UL           1      0         0        6 (null)
    50 AE         100      0         4        0 ORA$BASE
    
exec dbms_lock.sleep(1);
 
select event, total_waits, time_waited
from v$session_event
where sid = (select sid from v$mystat where rownum = 1)
order by 3 desc;
 
EVENT                                 TOTAL_WAITS TIME_WAITED
---------------------------------------------------------------- ----------- -----------
SQL*Net message from client                          56      350854
PL/SQL lock timer                               1         100
PX Deq: Parse Reply                               4          40
events in waitclass Other                          74          11
os thread startup                               1           7
PX Deq: Execute Reply                               4           6
library cache lock                              37           4
row cache lock                                  52           4
library cache pin                              37           3
PX Deq: Join ACK                               4           1
db file sequential read                           12           1
Disk file operations I/O                           1           0
SQL*Net break/reset to client                          15           0
SQL*Net message to client                          57           0
gc cr grant congested                               1           0
latch: shared pool                               1           0
gc cr grant 2-way                               2           0


참조 : http://wiki.gurubee.net/display/CORE/enq+UL+-+contention%2C+PLSQL+lock+Timer