Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#.2
Locks
Locks
Network
IO
9i Investigation
Lock = TX 6
Copyright 2006 Kyle Hailey
#.10
Statspack 10g
5 Timed Events Avg %Total
~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time
----------------------------- ------ -------- ------ ------
enq: TX - row lock contention 42 126 3000 96.5
CPU time 4 2.8
db file sequential read 165 1 4 .4
control file sequential read 214 0 1 .1
log file switch completion 2 0 40 .1
V$active_session_history
Succeeds
Who is waiting Who is the blocker
SESSION_ID BLOCKING_SESSION
SESSION_SERIAL# BLOCKING_SESSION_STATUS
USER_ID
BLOCKING_SESSION_SERIAL#
On what object
What is the Blocker SQL
CURRENT_OBJ#
CURRENT_FILE#
not reliably possible
Maybe by dumping REDO
CURRENT_BLOCK#
if P1 = 1415053318
then mode = 6
Then it is a data block
row lock
Copyright 2006 Kyle Hailey
10g: find the lock mode #.17
PARAMETER1
----------
name|mode
select distinct event, p1, to_char(p1,'XXXXXXXX') p1raw
from v$active_session_history where event like 'enq:%‘;
EVENT P1 P1RAW
------------------------------ ---------- ---------
enq: TX - row lock contention 1415053316 54580004
enq: TX - row lock contention 1415053318 54580006
enq: TX - allocateCopyright
ITL 2006entry
Kyle Hailey 1415053316 54580004
P1 = name | mode #.18
EVENT P1 mode
----------------------------- ---------- ----
enq: TX - allocate ITL entry 1415053316 4
enq: TX - row lock contention 1415053318 6
enq: TX - row lock Copyright
contention 1415053316
2006 Kyle Hailey 4
#.19
Lock Modes
# Type Name
--- ------- ---------------------------
1 Null Null
2 SS Sub share
3 SX Sub exclusive
4 S Share
5 SSX Share/sub exclusive
6 X Exclusive
User 1 User 2
if P1 = 1415053318
then mode = 6
Then it is a data block
row lock
TX Mode 6
Table
ID Value Session 1: delete where id = 1;
no commit
1 foo
Session 2: delete where id = 1 ;
Enqueue TX 6
TX – Mode 4
if P1 = 1415053316
then mode = 4
Not same data but conflicts
User 1 User 2
create table p(n number);
create unique index p_i
on p(n);
insert into p values(3);
insert into p values(3);
--hang
User 8 User 10
create table parent (
id number primary key);
create table child (
id number references parent,
name varchar2(20));
insert into parent values (2);
Foreign Key
2 01010000111000011100001100
000.000.0000 000.000.000
block row
Copyright 2006 Kyle Hailey
#.36
Session 1 Session 2
Update id=800
Update id=3
set value 2
set value 2
Copyright 2006 Kyle Hailey
#.37
FK (10.2.0.3)
ST EVENT SID LM P2 P3 OBJ OTYPE FN BLOCKN SQL_ID BSID
----- ---------------------- --- --- ------ ---- ----- ----- --- ------ --
10:41 enq: TX - row lock c 144 4 179681 7074 CHILD TABLE 1 60954 ahm7c9rupbz9r 1
10:41 enq: TX - row lock c 144 4 179681 7074 CHILD TABLE 1 60954 ahm7c9rupbz9r 1
10:41 enq: TX - row lock c 144 4 179681 7074 CHILD TABLE 1 60954 ahm7c9rupbz9r 1
bitmap
ST EVENT SID LM P2 P3 OBJ OTYPE FN BLOCKN SQL_ID BSID
----- ---------------------- --- --- ------ ---- ----- ----- --- ------ --
10:41 enq: TX - row lock c 143 4 966081 4598 I1 INDEX 0 0 azav296xxqcjx 144
10:41 enq: TX - row lock c 143 4 966081 4598 I1 INDEX 0 0 azav296xxqcjx 144
10:41 enq: TX - row lock c 143 4 966081 4598 I1 INDEX 0 0 azav296xxqcjx 144
10:41 enq: TX - row lock c 143 4 966081 4598 I1 INDEX 0 0 azav296xxqcjx 144
Transaction 1 Info
DataBlock
Data Block
Transaction 2 Info
Header
Header
ITL
Data
DataBlock
Data Block
Header
Header
Transaction 1 Transaction 3
Transaction 2
Row 3
Row 2
Data
Row 1
enq: TX - contention
Example
Session 1 – start transaction, don’t commit
Session 2 – alter tablespace read only
Example
Data File Extension – waiter waitng for another session to extend file
Index Block Split – waiter waiting for another session to split the block
Others ?
Free Lists
Non-ASSM
Sessions freeing block
If no txs free lists available (min 16, grow up depending on block size) , pick one and wait
TX 4
2PC – two phase commit
First does a prepare the commit
Any read or write access in the intervening time waits TX 4
Copyright 2006 Kyle Hailey
#.42
TX Further Investigation
select event, sql_id,
CURRENT_OBJ# || ' ' || name obj
,CURRENT_FILE# file#
,CURRENT_BLOCK# block#
from v$active_session_history ash,
obj$ o
where
event like 'enq: TX%'
and o.obj# (+)= ash.current_obj#
order by sample_time
TX Further Investigation
Who is the blocker:
V$active_session_history :
BLOCKING_SESSION
BLOCKING_SESSION_STATUS
BLOCKING_SESSION_SERIAL#
enq: TM - contention
TX locks have a corresponding TM lock
TM locks the structure from change
Parameter1 = object id
LOCK Parmeter1 Parmeter2(ID1) Parameter3(ID2)
------- --------- ------------- ---------------
enq: TM name|mode object # table/partition
enq: TM - contention
Exclusive Row Level Lock
User 1 User 2
create table parent (
id number primary key);
create table child (
id number references parent,
name varchar2(20));
insert into parent values (1);
insert into parent values (2);
commit;
insert into child values (1,2);
delete from parent where id=2;
enq: TM - contention
PK Parent Child
ID ID Value ID Name
1 1 1
X
2 X
2
Foreign Key
UL Locks
User-defined Locks
dbms_lock
dbms_lock.allocate_unique(v_lockname, v_lockhandle);
dbms_lock.request(v_lockhandle, p_ltype);
dbms_lock.release(v_lockhandle);
CI – Cross Instance
CU – Cursor Bind
HW – High Water
RO – Reuse Object
ST – Space Transaction
enq: CI - contention
Cross Instance
not OPS lock.
invoke actions in background processes
checkpoints
log switches
instance is shut down
CI – Cross Instance
Id1 Meaning (parameter2) Id2 Meaning (parameter3)
0 Flush buffers for reuse as new class 1 Pass in Parameters
1 LGWR checkpointing and Hot Backup 2 Invoke the call in background process
2 DBWR synchronization of SGA with control file 3 Foreground has not returned yet
3 Log file add/drop/rename notification 4 Used to allocate the CI call
4 Write buffer for CR read 5 Used to queue up interested clients
5 Test Call
6 Invalidate KCK cache in all instances
7 Alter rollback segment optimal
8 Signal Query Servers/coordinator
9 Create Remote Parallel Query Server
10 Set Global Partitions
11 Stop Disk Writes
12 Drop Sort Segments
13 Release unused space from Sort Segments
14 Instance Recovery for Parallel operation Group
15 Validate parallel slave Lock Value
16 Check Transaction State Objects
SQL_TEXT P2 P3
---------------------------------------- --- --
alter table XXXXX drop partition YYYYY 1 5
ID1 = 2 " LGWR checkpointing and Hot Backup "
enq: CU - contention
cursor bind
From Jonathan Lewis:
Protects the variable definitions while the
cursor is being optimized.
8i one CU per bind
9i one CU per cursor
Session 1 Header
Table
Session 2
Data
Session 3
HW
Use Freelists
Cause multiple jumps in High Water Mark
Pre-Allocate Extents
Alter table XXXX allocate extent;
Hidden Parameter
_bump_highwater_mark_count
alter session set "_bump_highwater_mark_count"=100;
Not supported
ASSM
Automatic segment space management
Partition Object
select
event,
sql_id,
CURRENT_OBJ# || ' ' || name obj
,CURRENT_FILE# file#
,CURRENT_BLOCK# block#
from v$active_session_history ash,
obj$ o
where
event like 'enq: HW%'
and o.obj# (+)= ash.current_obj#
order by sample_time;
enq: ST - contention
Space Transaction management lock
Space Transaction Lock
Allocating/deallocating extents
Dictionary Managed Tablespaces
Id1, Id2 Combinations:
Always 0, Always 0.
Solution
Got to Locally Managed Tablespaces
@?/rdbms/admin/utllockt
WAITING_SESSION LOCK_TYPE MODE_REQUESTED MODE_HELD LOCK_ID1 LOCK_ID2
--------------- ----------- -------------- --------- --------- --------
144 None
139 Transaction Share Exclusive 131113 7507