ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 直接路径插入持有表上的排他锁

直接路径插入持有表上的排他锁

原创 Linux操作系统 作者:redhouser 时间:2013-02-18 16:00:54 0 删除 编辑

在直接路径插入时,会持有表上的排他锁;表上的排他锁,会严重影响系统并发操作。
持有排他锁验证如下。


1,测试数据准备
[oracle@bocnet95 udump]$ sqlplus mh/mh

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 18 14:47:25 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create table p(x int);

Table created.

insert into p values(1);
insert into p values(2);
insert into p values(3);
commit;


SQL> SQL>
1 row created.

SQL>
1 row created.

SQL>
1 row created.

SQL>
Commit complete.


2,正常方式插入:insert into p values(4)
==>持有mode=3的TM锁

SQL>
SQL> select distinct sid from v$mystat;

       SID
----------
       791

SQL>
SQL> alter session set events '10704 trace name context forever,level 12';

Session altered.

SQL>
SQL> insert into p values(4);

1 row created.

SQL> commit;

alter session set events '10704 trace name context off';

Commit complete.

SQL> SQL>
Session altered.


--在commit前,查询该会话持有的锁:
SQL> select * from v$lock where sid=&mysid;
Enter value for mysid: 791
old   1: select * from v$lock where sid=&mysid
new   1: select * from v$lock where sid=791

ADDR     KADDR           SID TY        ID1        ID2      LMODE    REQUEST
-------- -------- ---------- -- ---------- ---------- ---------- ----------
3D6730C4 3D6730DC        791 TM     155081          0          3          0
3D7B0540 3D7B065C        791 TX     917525      21508          6          0

SQL> select object_name from dba_objects where object_id=155081;

OBJECT_NAME
--------------------------------------------------------------------------------
P

SQL> select  to_char(155081,'xxxxxxxx') from dual;

TO_CHAR(1
---------
    25dc9

--跟踪文件bocnet_ora_21135.trc
*** 2013-02-18 16:03:24.417
ksqgtl *** TM-00025dc9-00000000 mode=3 flags=0x401 timeout=21474836 ***
ksqgtl: xcb=0x0x3d7b0540, ktcdix=2147483647, topxcb=0x0x3d7b0540
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:03:24.418
ksqgtl *** TX-000e0015-00005404 mode=6 flags=0x401 timeout=0 ***
ksqgtl: xcb=0x0x3d7b0540, ktcdix=2147483647, topxcb=0x0x3d7b0540
 ktcipt(topxcb)=0x0
*** 2013-02-18 16:04:26.591
ksqrcl: TX,e0015,5404
ksqrcl: returns 0

*** 2013-02-18 16:04:26.591
ksqrcl: TM,25dc9,0
ksqrcl: returns 0


3,直接路径插入1:insert /*+ append */ into p values(5)
==>持有mode=3的TM锁

[oracle@bocnet95 udump]$ sqlplus mh/mh

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 18 16:11:10 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL>
SQL>
SQL> select distinct sid from v$mystat;

       SID
----------
       780

SQL>
SQL> alter session set events '10704 trace name context forever,level 12';

Session altered.

SQL>
SQL> insert /*+ append */ into p values(5);

1 row created.

SQL> commit;

Commit complete.

SQL>
SQL> alter session set events '10704 trace name context off';

Session altered.

SQL> exit


--在commit前,查询该会话持有的锁:
SQL> select * from v$lock where sid=&mysid;
Enter value for mysid: 780
old   1: select * from v$lock where sid=&mysid
new   1: select * from v$lock where sid=780

ADDR     KADDR           SID TY        ID1        ID2      LMODE    REQUEST
-------- -------- ---------- -- ---------- ---------- ---------- ----------
3D6730C4 3D6730DC        780 TM     155081          0          3          0
3DB6AB84 3DB6ACA0        780 TX     983058      23463          6          0


--跟踪文件bocnet_ora_384.trc
*** 2013-02-18 16:11:49.168
ksqgtl *** TM-00025dc9-00000000 mode=3 flags=0x401 timeout=21474836 ***
ksqgtl: xcb=0x0x3db6ab84, ktcdix=2147483647, topxcb=0x0x3db6ab84
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:11:49.169
ksqgtl *** TX-000f0012-00005ba7 mode=6 flags=0x401 timeout=0 ***
ksqgtl: xcb=0x0x3db6ab84, ktcdix=2147483647, topxcb=0x0x3db6ab84
 ktcipt(topxcb)=0x0
*** 2013-02-18 16:13:21.947
ksqrcl: TX,f0012,5ba7
ksqrcl: returns 0

*** 2013-02-18 16:13:21.947
ksqrcl: TM,25dc9,0
ksqrcl: returns 0


4,直接路径插入2:insert /*+ append */ into p select 6 from dual;
==>持有mode=6的TM锁

[oracle@bocnet95 udump]$ sqlplus mh/mh

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 18 16:16:10 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL>
SQL> select distinct sid from v$mystat;

       SID
----------
       859

SQL>
SQL> alter session set events '10704 trace name context forever,level 12';

Session altered.

SQL> insert /*+ append */ into p select 6 from dual;

1 row created.

SQL>
SQL> commit;


Commit complete.

SQL> SQL> alter session set events '10704 trace name context off';

Session altered.

SQL> exit

--在commit前,查询该会话持有的锁:
SQL> select * from v$lock where sid=&mysid;
Enter value for mysid: 859
old   1: select * from v$lock where sid=&mysid
new   1: select * from v$lock where sid=859

ADDR     KADDR           SID TY        ID1        ID2      LMODE    REQUEST
-------- -------- ---------- -- ---------- ---------- ---------- ----------
3D6730C4 3D6730DC        859 TM     155081          0          6          0
3D7925A8 3D7926C4        859 TX     327718      61581          6          0

--跟踪文件bocnet_ora_1077.trc
*** 2013-02-18 16:16:34.795
ksqgtl *** TM-00025dc9-00000000 mode=6 flags=0x401 timeout=21474836 ***
ksqgtl: xcb=0x0x3d7925a8, ktcdix=2147483647, topxcb=0x0x3d7925a8
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:16:34.795
ksqgtl *** TX-00050026-0000f08d mode=6 flags=0x401 timeout=0 ***
ksqgtl: xcb=0x0x3d7925a8, ktcdix=2147483647, topxcb=0x0x3d7925a8
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:16:34.800
ksqgtl *** HW-00000004-0100ffab mode=6 flags=0x411 timeout=21474836 ***
ksqgtl: xcb=0x0x3db2f6ac, ktcdix=2147483647, topxcb=0x0x3d7925a8
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:16:34.812
ksqgtl *** TM-0000003d-00000000 mode=3 flags=0x401 timeout=21474836 ***
ksqgtl: xcb=0x0x3db2f6ac, ktcdix=2147483647, topxcb=0x0x3d7925a8
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:16:34.833
ksqgtl *** TM-0000000e-00000000 mode=3 flags=0x401 timeout=21474836 ***
ksqgtl: xcb=0x0x3db2f6ac, ktcdix=2147483647, topxcb=0x0x3d7925a8
 ktcipt(topxcb)=0x0

*** 2013-02-18 16:16:34.834
ksqrcl: TM,e,0
ksqrcl: returns 0
*** 2013-02-18 16:16:34.834
ksqrcl: TM,3d,0
ksqrcl: returns 0
*** 2013-02-18 16:16:34.834
ksqrcl: HW,4,100ffab
ksqrcl: returns 0
*** 2013-02-18 16:17:10.264
ksqrcl: TM,25dc9,0
ksqrcl: returns 0


SQL> col owner for a10
SQL> col objectname for a10
SQL> col object_name for a10
SQL> col object-type for a10
SQL> r
  1  select owner, object_name, object_type
  2    from dba_objects
  3*  where object_id in (to_number('e', 'xxx'), to_number('3d', 'xxx'))

OWNER      OBJECT_NAM OBJECT_TYPE
---------- ---------- -------------------
SYS        SEG$       TABLE
SYS        TSQ$       TABLE

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/18922393/viewspace-754240/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-05-26

  • 博文量
    211
  • 访问量
    876668