insert操作卡死的处理过程

SQL> select sql_id from v$sql where sql_text like 'delete  from  std_contract%';

SQL_ID
-------------
9wx6s3p84v3xw

SQL> set long 9999
SQL> select sql_text from v$sql where sql_id ='9wx6s3p84v3xw';

SQL_TEXT
------------------------------------------------------------------------------
delete  from  std_contract subpartition (P0000021) t1  where  exists (select 1
 from T_POLINFO_WN_000002  t2 where t1.Cntr_Id=t2.CntrId )

SQL> 
SQL> 
SQL> 
SQL> !
$ ora plan 9wx6s3p84v3xw

Session altered.


PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  9wx6s3p84v3xw, child number 0
-------------------------------------
delete  from  std_contract subpartition (P0000021) t1  where  exists
(select 1 from T_POLINFO_WN_000002  t2 where t1.Cntr_Id=t2.CntrId )

Plan hash value: 668406912

-----------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name                | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------------------------
|   0 | DELETE STATEMENT              |                     |       |       |       |   295K(100)|          |       |       |
|   1 |  DELETE                       | STD_CONTRACT        |       |       |       |            |          |       |       |
|*  2 |   HASH JOIN RIGHT SEMI        |                     |    13M|  1727M|   538M|   295K  (1)| 00:59:02 |       |       |
|   3 |    TABLE ACCESS FULL          | T_POLINFO_WN_000002 |    13M|   380M|       | 85240   (1)| 00:17:03 |       |       |
|   4 |    PARTITION COMBINED ITERATOR|                     |    16M|  1577M|       | 95085   (2)| 00:19:02 |   KEY |   KEY |
|   5 |     TABLE ACCESS FULL         | STD_CONTRACT        |    16M|  1577M|       | 95085   (2)| 00:19:02 |     1 |     1 |
-----------------------------------------------------------------------------------------------------------------------------


SQL> select index_name from dba_indexes where table_name ='STD_CONTRACT';

INDEX_NAME
------------------------------
IDX_STD_CONTACT_APPLNO
IDX_STD_CONTACT_CNTRNO
IDX_STD_CONTACT_CNTRID
IDX_STD_CONTRACT_INFORCE
IDX_STD_SGID

通过oradebug查看session的情况

    Oracle session identified by:
    {
                instance: 1 (cmds.cmds1)
                   os id: 14419572
              process id: 342, oracle@cmdsky01
              session id: 3619
        session serial #: 34985
    }
    is waiting for 'enq: TM - contention' with wait info:
    {
                      p1: 'name|mode'=0x544d0003
                      p2: 'object #'=0x1a10c
                      p3: 'table/partition'=0x0
            time in wait: 2714 min 58 sec
           timeout after: never
                 wait id: 2058617
                blocking: 0 sessions
             current sql: delete  from  std_contract subpartition (P0000021) t1  where  exists (select 1 from T_POLINFO_WN_000002  t
2 where t1.Cntr_Id=t2.CntrId )
             short stack: ksedsts()+240<-ksdxfstk()+44<-ksdxcb()+3432<-sspuser()+116<-__sighandler()<-thread_wait()+580<-sskgpwwait(
)+32<-skgpwwait()+200<-ksliwat()+10772<-kslwaitctx()+180<-kjusuc()+3600<-ksipgetctxi()+1884<-ksqcmi()+22104<-ksqgtlctx()+2884<-ktaia
m()+700<-ktagetg0()+776<-ktagetp_internal()+232<-ktagetg_internal()+116<-ktagdw()+152<-ktaadm()+152<-kksfbc()+1860<-opiexe()+2020<-o
pipls()+2028<-opiodr()+908<-rpidrus()+216<-skgmstack()+160<-rpidru()+132<-rpiswu2()+520<-rpidrv()+1060<-psddr0()+448<-psdnal()+472<-
pevm_EXIM()+240<-
            wait history:
              * time between current wait and wait #1: 0.001417 sec
              1.       event: 'row cache lock'
                 time waited: 0.000372 sec
                     wait id: 2058616         p1: 'cache id'=0x10
                                              p2: 'mode'=0x0
                                              p3: 'request'=0x3
              * time between wait #1 and #2: 0.002481 sec
              2.       event: 'library cache pin'
                 time waited: 0.000265 sec
                     wait id: 2058615         p1: 'handle address'=0x7000118a2602118
                                              p2: 'pin address'=0x7000118a4aeb478
                                              p3: '100*mode+namespace'=0x67138700010002

查看锁的情况

col OS_USER_NAME for a10
SELECT /*+ RULE */ ls.osuser os_user_name,
    ls.username user_name,
    decode(ls.type, 'RW', 'Row wait enqueue lock', 'TM', 'DML enqueue lock', 'TX', 'Transaction enqueue lock', 'UL', 'User supplied lock') lock_type,
    o.object_name OBJECT,
    decode(ls.lmode, 1, NULL, 2, 'Row Share', 3, 'Row Exclusive', 4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive', NULL) lock_mode,
    o.OWNER,
    ls.sid,
    ls.serial# serial_num,
    ls.id1,
    ls.id2
FROM sys.dba_objects o,
    (
        SELECT s.osuser,
            s.username,
            l.type,
            l.lmode,
            s.sid,
            s.serial#,
            l.id1,
            l.id2
        FROM v$session s,
            v$lock l
        WHERE s.sid = l.sid 
        ) ls
WHERE o.object_id = ls.id1
    AND o.OWNER ='CMDS'
ORDER BY o.OWNER,
    o.object_name;

检查没有索引的外键,排除这个原因

SELECT * FROM (
   SELECT c.table_name, cc.column_name, cc.position column_position
   FROM   user_constraints c, user_cons_columns cc
   WHERE  c.constraint_name = cc.constraint_name
   AND    c.constraint_type = 'R'
   MINUS
   SELECT i.table_name, ic.column_name, ic.column_position
   FROM   user_indexes i, user_ind_columns ic
   WHERE  i.index_name = ic.index_name
   )
ORDER BY table_name, column_position;


TABLE_NAME                     COLUMN_NAME          COLUMN_POSITION
------------------------------ -------------------- ---------------
DBFS$_MOUNTS                   S_NAME                             2
DBFS_SFS$_FS                   TABID                              1
DBFS_SFS$_FS                   VOLID                              2
HS$_CLASS_CAPS                 CAP_NUMBER                         1
HS$_CLASS_DD                   DD_TABLE_ID                        1
HS$_FDS_INST                   FDS_CLASS_ID                       1
HS$_INST_CAPS                  CAP_NUMBER                         1
HS$_INST_DD                    DD_TABLE_ID                        1
HS$_PARALLEL_HISTOGRAM_DATA    DBLINK                             1
HS$_PARALLEL_HISTOGRAM_DATA    REMOTE_TABLE_NAME                  2
HS$_PARALLEL_HISTOGRAM_DATA    REMOTE_SCHEMA_NAME                 3
HS$_PARALLEL_PARTITION_DATA    DBLINK                             1
HS$_PARALLEL_PARTITION_DATA    REMOTE_TABLE_NAME                  2
HS$_PARALLEL_PARTITION_DATA    REMOTE_SCHEMA_NAME                 3
HS$_PARALLEL_SAMPLE_DATA       DBLINK                             1
HS$_PARALLEL_SAMPLE_DATA       REMOTE_TABLE_NAME                  2
HS$_PARALLEL_SAMPLE_DATA       REMOTE_SCHEMA_NAME                 3
REGISTRY$                      PID                                2
REGISTRY$DEPENDENCIES          REQ_NAMESPACE                      1
REGISTRY$DEPENDENCIES          REQ_CID                            2
REGISTRY$PROGRESS              NAMESPACE                          1
REGISTRY$PROGRESS              CID                                2
WRM$_SNAPSHOT                  INSTANCE_NUMBER                    2
WRM$_SNAPSHOT                  STARTUP_TIME                       3

没有这个情况

杀掉这些session

select sql_id,state from v$session where sid=2873 and  SERIAL#=39007;   
select sql_id,state from v$session where sid=3619 and  SERIAL#=34985;   
select sql_id,state from v$session where sid=1699 and  SERIAL#= 59001;

alter system kill session '2873,39007';
alter system kill session '3619,34985';
alter system kill session '1699,59001';

原因

从应用了解到insert是带append提示的,因为这个提示,不走sga,所以必须保证数据不被修改,而同时表上面有delete操作,表的数据被删除,两个操作应该是delete在insert之前或差不多同时进行,导致产生了独占锁。
处理方法是杀掉session,然后先insert数据,然后跑delete,经过这样的处理之后,insert在非常短的时间内就完成了,delete量较大,跑了大概一晚上的时间。

转载于:https://www.cnblogs.com/wangrongxin/p/6224310.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值