2. Locks Covered in this Section
Part I : Intro
Lock Name(type) and Mode
Finding waiter and blocker
Finding Object
Part II : User
TM – table modification
TX – Transaction locks
UL – user lock
Part III : Internal
CI – Cross Instance
HW – High Water
RO – Reusable Object
Copyright 2006 Kyle Hailey #.2
3. Part I : Intro
To Solve we need:
1.Waiter
2.Blocker
3.Lock Type
type
mode
1.Object blocking on
Missing : blocking SQL
Possibly with log miner
Copyright 2006 Kyle Hailey #.3
4. Solving – Data Sources
V$active_session_history
or
In “real time” can also use
v$lock
v$session (v$session_wait)
dba_blockers
dba_waiters
?/rdbms/admin/utllockt.sql
http://www.evdbt.com/enqwaits.sql
Copyright 2006 Kyle Hailey #.4
5. v$active_session_history
Fields in ASH for lock analysis and solution:
Waiter SQL Waiting
SESSION_ID
SQL_ID
SESSION_SERIAL#
Blocker
USER_ID
BLOCKING_SESSION
Object
BLOCKING_SESSION_STATUS
CURRENT_OBJ#
CURRENT_FILE# BLOCKING_SESSION_SERIAL#
CURRENT_BLOCK# Lock Type and Mode
Event = Type (name)
P1 = Type | Mode
Missing: SQL Blocking not reliably
possible, Maybe by dumping REDO
Copyright 2006 Kyle Hailey #.5
6. Lock Name and Mode
Select parameter1 from v$event_name where name=‘enqueue’;
Parameter1
----------
Name|mode
Select p1, p1raw from v$session where event like 'enq%';
P1 P1RAW
---------- --------
1415053318 54580006
Name: 5458 Mode: 0006
Hex Decimal ASCII
54 = 84 = “T” Lock = TX 6
58 = 88 = “X”
Copyright 2006 Kyle Hailey #.6
7. Type and Mode
SELECT
SELECT
chr(bitand(p1,-16777216)/16777215)||
chr(bitand(p1,-16777216)/16777215)||
chr(bitand(p1, 16711680)/65535) Type,
chr(bitand(p1, 16711680)/65535) Type,
mod(p1,16) lmode
mod(p1,16) lmode
from v$session_wait
from v$session_wait
where event=‘enqueue’;
where event=‘enqueue’;
TY
TY LMODE
LMODE
-- ----------
-- ----------
TX
TX 6
6
#.7
8. Lock Names (types)
9i
One Wait : “enqueue”
10g
208enqueue waits
Specific to each type of enqueue
enq: HW - contention Configuration
enq: SQ - contention Configuration
enq: SS - contention Configuration
enq: ST - contention Configuration
enq: TM - contention Application
enq: TW - contention Administrative
enq: TX - allocate ITL entry Configuration
enq: TX - index contention Concurrency
enq: TX - row lock contention Application
enq: TX – contention Application
Copyright 2006 Kyle Hailey #.8
9. 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
Copyright 2006 Kyle Hailey #.9
10. P1 = name | mode
P1 (parameter1) same for all locks
select distinct parameter1 from v$event_name PARAMETER1
where name like 'enq:%' name|mode
select
event,
mod(p1,16) as "mode"
from v$active_session_history
where event like 'enq:%‘;
EVENT mode
enq: TX - allocate ITL entry 4
enq: TX - row lock contention 6
enq: TX - row lock contention 4
Copyright 2006 Kyle Hailey #.10
11. OEM 10g
if P1 = 1415053318
then mode = 6
Then it is a data block
row lock
Copyright 2006 Kyle Hailey #.11
12. Querying ASH
select
substr(event,0,20) lock_name,
ash.session_id waiter,
mod(ash.p1,16) lmode,
ash.p2 p2,
ash.p3 p3,
o.object_name object,
o.object_type otype,
CURRENT_FILE# filen,
CURRENT_BLOCK# blockn,
ash.SQL_ID waiting_sql,
BLOCKING_SESSION blocker
--,ash.xid
from
v$active_session_history ash,
all_objects o
where
event like 'enq: %'
and o.object_id (+)= ash.CURRENT_OBJ#
/
Copyright 2006 Kyle Hailey #.12
13. Part II : User Locks
TX – Transaction Lock
Mode 6: Modifying same row
Mode 4: several reasons
TM – Table Modification
Mode 4: Unindexed Foreign Key
UL – User Lock
Copyright 2006 Kyle Hailey #.13
14. TX Lock
Session B
Undo
Wait for Tx Segment
update toto set
update toto set To commit Header
name = ‘ADAMS’
name = ‘ADAMS’
where id = 1;
where id = 1; Undo
Segment
Table Toto
Data Block
Data Block
Header
Header
Transaction 1
Session a
update toto set
update toto set
name = ‘SMITH’
name = ‘SMITH’
Row 1 where id = 1;
Delete from 1;
where id = toto where id
Delete from toto where id
Copyright 2006 Kyle Hailey = 2;
= 2;
Delete from toto where id
Delete from toto where #.14
id
15. Transaction Locks (TX)
TX = Transaction = Wait on UNDO
Mode 6 (exclusive)
modification of a row lock
Mode 4 (share)
Index block spilt
Unique Index Key enforcement
Foreign key enforcement
ITL space waits
Bitmap chunk conflicts
Alter tablespace … read only;
Free Lists slot waits
Possible with two phase commit
Copyright 2006 Kyle Hailey #.15
16. Transaction Locks (TX)
Mode 4, new Events:
1. enq: TX - allocate ITL entry
Wait on an ITL slot
1. enq: TX - index contention
Index block split
1. enq: TX - row lock contention
1. Mode 6 – classic row lock
2. Mode 4 - pk violation, fk violation, bitmap chunk wait
2. enq: TX – contention
Wait for a data file extension, Alter tbs read only
Copyright 2006 Kyle Hailey #.16
17. enq: TX - row lock contention
Mode 6, row in data block
User 1 User 2
SQL> delete from toto
where id = 1;
SQL> delete from toto
where id =1;
Table
ID Value
1 foo
Copyright 2006 Kyle Hailey #.17
18. enq: TX - row lock contention
if P1 = 1415053318
then mode = 6
Then it is a data block
row lock
Copyright 2006 Kyle Hailey #.18
19. TX – Mode 4
if P1 = 1415053316
then mode = 4
Not same data but conflicts
Copyright 2006 Kyle Hailey #.19
21. 1. enq: TX - row lock contention
Mode 4 , unique index
User 1 User 2
create table p(n number);
create unique index p_i on p(n);
insert into p values(2);
insert into p values(2);
PK Table
ID ID Value
2? 2?
Copyright 2006 Kyle Hailey #.21
22. 2. enq: TX - row lock contention
Mode 4, foreign key
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 (2);
insert into child values (2,88);
PK Parent Child
ID ID Value ID Name
2? 2? 2
Copyright 2006 Kyle Hailey #.22
23. 3. enq: TX - row lock contention
Mode 4
Bitmaps are compressed
Changes to the same bitmap cause locks
Value Start End Bitmap
Rowid Rowid
1 01010000111000011100001100
000.000.0000 000.000.000
2 01010000111000011100001100
000.000.0000 000.000.000
Copyright 2006 Kyle Hailey #.23
24. 3. enq: TX - row lock contention
Session 1
create table t1 ((
create table t1 Different rows but
n1
n1 number(4),
number(4), same key value
n2
n2 number(4));
number(4));
insert into t1
insert into t1
select 1, rownum
select 1, rownum
from all_objects
from all_objects
where rownum <= 400;
where rownum <= 400;
commit;
commit;
create bitmap index i1 on t1(n1);
create bitmap index i1 on t1(n1);
update t1 set n1 = 2
update t1 set n1 = 2
where n2 = 12;
where n2 = 12; Session 2
update t1 set n1 = 2
update t1 set n1 = 2
where n2 = 13;
where n2 = 13;
Copyright 2006 Kyle Hailey #.24
25. 3. enq: TX - row lock contention
Bitmaps are compressed
Changes to the same bitmap chunk cause
locks
Value Start End Bitmap
Rowid Rowid
1 01010000111000011100001100
200.0 204.7
1 01010000111000011100001100
205.0 210.3
2 01010000111000011100001100
200.0 205.6
block row
Copyright 2006 Kyle Hailey #.25
26. 3. enq: TX - row lock contention
Value Start End Bitmap
Rowid Rowid
1 01010000111000011100001100
200.0 204.7
2 01010000111000011100001100
205.0 210.3
3 01010000111000011100001100
200.0 205.6
Session 1 Session 2
Update id=12 Update id=13
set value 2 set value 2
Copyright 2006 Kyle Hailey #.26
30. enq: TX - allocate ITL entry
create table itl (
create table itl (
id number,
id number,
data varchar2(20)
data varchar2(20)
))
pctfree 0
pctfree 0
initrans 1
initrans 1
;;
insert into itl select rownum,'a' from all_objects
insert into itl select rownum,'a' from all_objects
where rownum < 2000;
where rownum < 2000;
commit;
commit;
session 1: update itl set data=data where id=1;
session 1: update itl set data=data where id=1;
session 2: update itl set data=data where id=2;
session 2: update itl set data=data where id=2;
session 3: update itl set data=data where id=3;
session 3: update itl set data=data where id=3;
session 4: update itl set data=data where id=4;
session 4: update itl set data=data where id=4;
session 5: update itl set data=data where id=5;
session 5: update itl set data=data where id=5;
Copyright 2006 Kyle Hailey #.30
31. enq: TX - contention
1. Altering tablespace read only with open transaction
Example
Session 1 – start transaction, don’t commit
Session 2 – alter tablespace read only
1. Data File Extension – waiter waiting for another session to extend
file
2. Index Block Split – waiter waiting for another session to split the
block
Copyright 2006 Kyle Hailey #.31
33. TX Further Investigation
Who is the blocker:
V$active_session_history :
BLOCKING_SESSION
BLOCKING_SESSION_STATUS
BLOCKING_SESSION_SERIAL#
No Guarentee of finding blocker SQL
Copyright 2006 Kyle Hailey #.33
35. 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;
Copyright 2006 Kyle Hailey #.35
36. enq: TM - contention
PK Parent Child
ID ID Value ID Name
1 1 1
X
2 X
2
Session 1 Insert into Child ID=1
Session 2 Delete from Parent where ID=2 :
Enqueue TM 4
Session 2 doesn’t know the value Session 1 inserted
Session 2 only knows there is an outstanding change
Copyright 2006 Kyle Hailey #.36
37. enq: TM – contention Solution
PK Parent Child
Index
ID ID Value ID ID Name
1 1
2
Foreign Key
Session 1: Insert into Child ID=1
Session 2: Delete from Parent ID=2
OK – can verify quickly in the child index
Copyright 2006 Kyle Hailey #.37
38. TM Further Investigation
select
event,
sql_id,
mod(p1,16) as "mode",
p2|| ' ' || o.name obj
from v$active_session_history ash,
obj$ o
where
event like 'enq: TM%'
and o.obj# (+)= ash.p2
order by sample_time;
EVENT SQL_ID mode OBJ
enq: TM - contention 8zw36yw3fq4yy 4 53372 CHILD
enq: TM - contention 8zw36yw3fq4yy 4 53372 CHILD
enq: TM - contention 8zw36yw3fq4yy 4 53372 CHILD
enq: TM - contention 8zw36yw3fq4yy 4 53372 CHILD
enq: TM - contention 8zw36yw3fq4yy 4 53372 CHILD
enq: TM - contention 8zw36yw3fq4yy 4 53372 CHILD
Copyright 2006 Kyle Hailey #.38
39. UL Locks
User-defined Locks
dbms_lock
Wait Event Parameter2 Parameter3
enq: UL - contention id 0
dbms_lock.allocate_unique(v_lockname, v_lockhandle);
dbms_lock.request(v_lockhandle, p_ltype);
dbms_lock.release(v_lockhandle);
Copyright 2006 Kyle Hailey #.39
40. Internal Locks
CI – Cross Instance
HW – High Water
KO – fast object checkpoint
RO – Reuse Object
SQ – Sequence Lock
ST – Space Transaction
Copyright 2006 Kyle Hailey #.40
41. enq: CI - contention
Cross Instance
not OPS lock.
invoke actions in background processes
checkpoints
log switches
instance is shut down
Copyright 2006 Kyle Hailey #.41
42. CI – Cross Instance
Id1 Meaning (parameter2)
Id1 Meaning (parameter2) Id2 Meaning (parameter3)
Id2 Meaning (parameter3)
00Flush buffers for reuse as new class
Flush buffers for reuse as new class 11Pass in Parameters
Pass in Parameters
11LGWR checkpointing and Hot Backup
LGWR checkpointing and Hot Backup 22Invoke the call in background process
Invoke the call in background process
22DBWR synchronization of SGA with control file
DBWR synchronization of SGA with control file 33Foreground has not returned yet
Foreground has not returned yet
33Log file add/drop/rename notification 44Used to allocate the CI call
Used to allocate the CI call
Log file add/drop/rename notification
44Write buffer for CR read 55Used to queue up interested clients
Used to queue up interested clients
Write buffer for CR read
55Test Call
Test Call
66Invalidate KCK cache in all instances
Invalidate KCK cache in all instances
77Alter rollback segment optimal
Alter rollback segment optimal
88Signal Query Servers/coordinator
Signal Query Servers/coordinator
99Create Remote Parallel Query Server
Create Remote Parallel Query Server
10 Set Global Partitions
10 Set Global Partitions
11 Stop Disk Writes
11 Stop Disk Writes
12 Drop Sort Segments
12 Drop Sort Segments
13 Release unused space from Sort Segments
13 Release unused space from Sort Segments
14 Instance Recovery for Parallel operation Group
14 Instance Recovery for Parallel operation Group
15 Validate parallel slave Lock Value
15 Validate parallel slave Lock Value
16 Check Transaction State Objects
16 Check Transaction State Objects
Copyright 2006 Kyle Hailey #.42
43. CI Locks
select
substr(sql_text,0,20) sql_text,
p2,p3,
CURRENT_OBJ# || ' ' || name obj
,CURRENT_FILE# file#
,CURRENT_BLOCK# block#
from v$active_session_history ash,
obj$ o,
v$sqltext sql
where
event like 'enq: CI%'
and o.obj# (+)= ash.current_obj#
and sql.sql_id (+)= ash.sql_id
order by sample_time;
SQL_TEXT P2 P3 OBJ FILE# BLOCK#
INSERT INTO TOTO1 VA 1 5 54225 TOTO1 6 682721
Copyright 2006 Kyle Hailey #.43
44. CI Locks
SQL_TEXT
SQL_TEXT P2 P3
P2 P3
---------------------------------------- --- --
---------------------------------------- --- --
alter table XXXXX drop partition YYYYY
alter table XXXXX drop partition YYYYY 1 5
1 5
P2 = 1 ""LGWR checkpointing and Hot Backup ""
P2 = 1 LGWR checkpointing and Hot Backup
P3 = 5. "Used to queue up interested clients""
P3 = 5. "Used to queue up interested clients
If p2=1 and p3=5, then contention on blocks being
checkpointed, try raising fast_start_mttr_target
alter system set fast_start_mttr_target=600 scope=both;
Copyright 2006 Kyle Hailey #.44
45. enq: HW - contention
Wait Event Parameter2 Parameter3
enq: HW - contention table space # block
Session 1 Header
Table
Session 2
Data
Session 3
High Water Mark
Empty
Copyright 2006 Kyle Hailey #.45
46. HW
Use Freelists
Cause a jump in High Water Mark by freelists *
_bump_highwater_mark_count
Hidden Parameter
_bump_highwater_mark_count
alter session set "_bump_highwater_mark_count"=100;
Not supported
ASSM
Automatic segment space management
Copyright 2006 Kyle Hailey #.46
47. HW 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: HW%'
and o.obj# (+)= ash.current_obj#
order by sample_time;
EVENT SQL_ID OBJ FILE# BLOCK#
enq: HW - contention 49ch3jfkncnsp 53410 T1_I1 13 29734
Copyright 2006 Kyle Hailey #.47
48. enq: KO - fast object checkpoint
Used when checking the cache for blocks from a
table for PQO direct read
Copyright 2006 Kyle Hailey #.48
49. enq: RO - fast object reuse
Drop or Truncate a table
Wait for DBWR to clean cache
Solution
Tune DBWR using smaller MTTR
Use GTT
Truncate/drop less often
#.49
52. Summary : Internal Locks
CI – Cross Instance
HW – High Water
Look at object and SQL
use ASSM, freelists, pre-allocate extents
KO – fast object checkpoint
PQO
RO – reusable object
Reduce cache, tune DBWR, use GTT
SQ – Sequence Lock
logon/logoff problem
ST - Space Transaction
only one per database
used for space allocations uet, fet
Find object
use LMT
Copyright 2006 Kyle Hailey #.52
Hinweis der Redaktion
Lock seems easy Compared to latches, buffer busy waits etc
bitand(p1, 65536) "Mode"
TX if P1 = 1415053316 then mode = 4 if P1 = 1415053318 then mode = 6
col event for a22 col block_type for a18 col objn for a18 col otype for a10 col fn for 99 col sid for 9999 col bsid for 9999 col lm for 99 col p3 for 99999 col blockn for 99999 select to_char(sample_time,'HH:MI') st, substr(event,0,20) event, ash.session_id sid, mod(ash.p1,16) lm, ash.p2, ash.p3, nvl(o.object_name,ash.current_obj#) objn, substr(o.object_type,0,10) otype, CURRENT_FILE# fn, CURRENT_BLOCK# blockn, ash.SQL_ID, BLOCKING_SESSION bsid --,ash.xid from v$active_session_history ash, all_objects o where event like 'enq: TX %' and o.object_id (+)= ash.CURRENT_OBJ# and sample_time > sysdate - &1/(60*24) Order by sample_time /
create table p(n number); create unique index p_i on p(n); insert into p values(3);
Subject: Bitmap Indexes and Deadlocks: Deadlocks on Insert Statements Doc ID: Note:171795.1 Type: TROUBLESHOOTING Last Revision Date: 18-MAY-2004 Status: PUBLISHED PURPOSE ------- The purpose of this article is to explain the occurrence of deadlocks when the only DML activity is insert statements against a table with a bitmap index SCOPE & APPLICATION ------------------- Database administrators and Application developers involved in application design. BITMAP INDEXES: THE HIDDEN DEADLOCK THREAT ------------------------------------------ The "Oracle8i Designing and Tuning for Performance" guide explains the limitations of bitmap indexes as this: Extract of documentation: "DML and DDL statements, such as UPDATE, DELETE, DROP TABLE, affect bitmap indexes the same way they do traditional indexes: the consistency model is the same. A compressed bitmap for a key value is made up of one or more bitmap segments, each of which is at most half a block in size (but may be smaller). The locking granularity is one such bitmap segment. This may affect performance in environments where many transactions make simultaneous updates. If numerous DML operations have caused increased index size and decreasing performance for queries, then you can use the ALTER INDEX ... REBUILD statement to compact the index and restore efficient performance. A B*-tree index entry contains a single rowid. Therefore, when the index entry is locked, a single row is locked. With bitmap indexes, an entry can potentially contain a range of rowids. When a bitmap index entry is locked, the entire range of rowids is locked. The number of rowids in this range affects concurrency. As the number of rowids increases in a bitmap segment, concurrency decreases. Locking issues affect DML operations, and may affect heavy OLTP environments. Locking issues do not, however, affect query performance. As with other types of indexes, updating bitmap indexes is a costly operation. Nonetheless, for bulk inserts and updates where many rows are inserted or many updates are made in a single statement, performance with bitmap indexes can be better than with regular B*-tree indexes." ************** What is not mentioned is the fact that the same architectural feature that locks a range of rowid's also means that its possible to get a deadlock within the bitmap when updating rows in the underlying table. This deadlock is not in the table itself, as one might suspect, but rather in the bitmap index blocks. This kind of deadlock is easily diagnosable by the deadlock trace file, which has an entry that looks like the example below: The following deadlock is not an ORACLE error. It is a deadlock due to user error in the design of an application or from issuing incorrect ad-hoc SQL. The following information may aid in determining the deadlock: Deadlock graph: ---------Blocker(s)-------- ---------Waiter(s)--------- Resource Name process session holds waits process session holds waits TX-00080027-0000d2a1 12 37 X 15 35 S TX-000a0016-0000d6d2 15 35 X 12 37 S session 37: DID 0001-000C-00000002 session 35: DID 0001-000F-00000002 session 35: DID 0001-000F-00000002 session 37: DID 0001-000C-00000002 Rows waited on: Session 35: no row Session 37: no row The piece of information that leads us to a bitmap deadlock is the "no row" value in the session information. If we had encountered a deadlock in the underlying table, the Session line would give us row information so that we could track down the exact point of failure. Without a row, it would seem that we are at a dead end. Even more mysterious is when we get this deadlock on inserts, where we are inserting only new rows and therefore it would seem impossible to get a deadlock. No one should be requesting a row that someone else holds locked. There are no solutions to this kind of problems, except not using bitmap indexes when having an application where you can't control when the DML are issued against the tables with bitmap indexes. Bitmaps are normally intended for datawarehouse applications that are loading data via batches and that users are only querying. The following testcase can be used to see the results of this type of problem. We will create a table called CAR_TYPE, which holds information about cars, including the car's color. We will build a bitmap index on the COLOR column. After doing so, we will populate the table with data. After the initial insert, we will open two sessions of the same user, and run simultaneous inserts into the CAR_TYPE table. TESTCASE: ===================================== ===================================== create table car_type ( make varchar2(20), model varchar2(20), color varchar2(20), VIN number(15) primary key, year number(4)); create bitmap index car_type_bm_idx on car_type(color); create sequence car_type_seq start with 35001 increment by 1 nocache nocycle; declare v_CarMake varchar2(20) := 'Audi'; v_CarModel varchar(20) := 'Quattro'; v_CarColor varchar(20) := 'Gold'; v_CarVin binary_integer :=1; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 5000; end loop; end; / commit; declare v_CarMake varchar2(20) := 'Toyota'; v_CarModel varchar(20) := 'Camry'; v_CarColor varchar(20) := 'Red'; v_CarVin binary_integer :=5001; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 10000; end loop; end; / commit; declare v_CarMake varchar2(20) := 'Audi'; v_CarModel varchar(20) := 'Quattro'; v_CarColor varchar(20) := 'Blue'; v_CarVin binary_integer :=10001; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 15000; end loop; end; / commit; declare v_CarMake varchar2(20) := 'Toyota'; v_CarModel varchar(20) := 'Camry'; v_CarColor varchar(20) := 'Silver'; v_CarVin binary_integer :=15001; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 20000; end loop; end; / commit; declare v_CarMake varchar2(20) := 'Audi'; v_CarModel varchar(20) := 'Quattro'; v_CarColor varchar(20) := 'Green'; v_CarVin binary_integer :=20001; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 25000; end loop; end; / commit; declare v_CarMake varchar2(20) := 'Audi'; v_CarModel varchar(20) := 'Quattro'; v_CarColor varchar(20) := 'Black'; v_CarVin binary_integer :=25001; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 30000; end loop; end; / commit; declare v_CarMake varchar2(20) := 'Toyota'; v_CarModel varchar(20) := 'Camry'; v_CarColor varchar(20) := 'White'; v_CarVin binary_integer :=30001; begin loop insert into car_type (make,model,color,VIN,year) values (v_CarMake, v_CarModel, v_CarColor, v_CarVin, '2002'); v_CarVin := v_CarVin + 1; exit when v_CarVin > 35000; end loop; end; / commit; =============================== =============================== After this initial creation, cut the following script into a .sql file, and then execute it simultaneously from two sessions: =============================== =============================== insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); commit; insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); commit; insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); commit; insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); commit; insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); commit; insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','White',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Red',car_type_seq.nextval,'2002'); insert into car_type values ( 'Toyota','Camry','Silver',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Black',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Gold',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Blue',car_type_seq.nextval,'2002'); insert into car_type values ( 'Audi','Quatro','Green',car_type_seq.nextval,'2002'); commit; ======================================== ======================================== The result will be occasional deadlock errors: insert into car_type values ( * ERROR at line 1: ORA-00060: deadlock detected while waiting for resource The trace file will show the tell-tale 'No Row' message: Rows waited on: Session 11: no row Session 10: no row RELATED DOCUMENTS ----------------- Oracle8i Designing and Tuning for Performance Release 2 (8.1.6) Part Number A76992-01 .
select to_char(sample_time,'HH:MI') st, substr(event,0,20) event, ash.session_id sid, mod(ash.p1,16) lm, ash.p2, ash.p3, nvl(o.object_name,ash.current_obj#) objn, substr(o.object_type,0,10) otype, CURRENT_FILE# fn, CURRENT_BLOCK# blockn, ash.SQL_ID, BLOCKING_SESSION bsid from v$active_session_history ash, all_objects o where event like 'enq: TX - %' and o.object_id (+)= ash.CURRENT_OBJ# --and sample_time > sysdate - 40/(60*24) Order by sample_time /
Used to invoke specific actions in background processes on a specific instance or all instances. Examples include checkpoint, log switch, shutting down, identifying or re-identifying datafiles, etc. All in all, there are a small number (10’s) of predefined cross-instance call types. Not an Oracle Parallel Server lock. The name of this lock is misleading because it doesn't deal with distributed transactions. Rather, the CI lock is used to invoke specific actions in background processes on a specific instance or all instances. Examples would include checkpoints, log switches, or when the instance is shut down.
col event for a20 col obj for a12 col p2 for 9999 col p3 for 999999 col file# for 99999 col block# for 999999 select substr(sql_text,0,20) sql_text, --event, --sql_id, --p1, p2,p3, CURRENT_OBJ# || ' ' || name obj ,CURRENT_FILE# file# ,CURRENT_BLOCK# block# from v$active_session_history ash, obj$ o, v$sqltext sql where event like 'enq: CI%' and o.obj# (+)= ash.current_obj# and sql.sql_id (+)= ash.sql_id order by sample_time;
col event for a20 col obj for a12 col p2 for 9999 col p3 for 999999 col file# for 99999 col block# for 999999 select substr(sql_text,0,20) sql_text, --event, --sql_id, --p1, p2,p3, CURRENT_OBJ# || ' ' || name obj ,CURRENT_FILE# file# ,CURRENT_BLOCK# block# from v$active_session_history ash, obj$ o, v$sqltext sql where event like 'enq: CI%' and o.obj# (+)= ash.current_obj# and sql.sql_id (+)= ash.sql_id order by sample_time;
enq: HW - contention 4 16777715
column parameter format a30 column value format a10 select a.ksppinm parameter, c.ksppstvl value from x$ksppi a, x$ksppcv b, x$ksppsv c where a.indx = b.indx and a.indx = c.indx and substr(ksppinm,1,11)='_bump_highw' order by a.ksppinm;