溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫的等待事件TX-row lock contention怎么解決

發(fā)布時(shí)間:2021-12-22 09:23:33 來源:億速云 閱讀:288 作者:iii 欄目:關(guān)系型數(shù)據(jù)庫

本篇內(nèi)容主要講解“數(shù)據(jù)庫的等待事件TX-row lock contention怎么解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“數(shù)據(jù)庫的等待事件TX-row lock contention怎么解決”吧!

--創(chuàng)建外鍵參考表t3
SQL>  create table t3 (id number primary key,name varchar2(20),product_id number);

Table created.

--創(chuàng)建主表t2
SQL>  create table t2 (id number primary key,name varchar2(20));

Table created.

--給t3表加入外鍵約束
SQL> alter table t3 add constraint FK_PRODUCTSTAT_PRODUCTID foreign key (PRODUCT_id) references t2 (ID);

Table altered.

SQL>
SQL> insert into t2 values(1,'dh');

1 row created.

SQL>  insert into t2 values(2,'cc');

1 row created.

SQL> insert into t2 values(3,'cc');

1 row created.

SQL>  commit;

Commit complete.

SQL> select * from t2;

        ID NAME
---------- --------------------
         1 dh
         2 cc
         3 cc

SQL> select * from t3;

no rows selected

--注意區(qū)分:
session1:
SQL> insert into t2 values(4,'cc');

1 row created.

未提交。。。

session 2:
SQL> insert into t3 values(1,'tt',4);
                 
1 row created.

hang住,一直不動。。。

session 3:查詢:
SET LINES 200
col OWNER for a10
col R_OWNER for a10
col R_CONSTRAINT_NAME for a15
select a.table_name,
       a.owner,
       a.constraint_name,
       a.constraint_type,
       a.r_owner,
       a.r_constraint_name,
       b.table_name  
  from dba_constraints a, dba_constraints b
 where a.constraint_type = 'R'
   and a.r_constraint_name = b.constraint_name
   and a.r_owner = b.owner
   and b.table_name = 'T2'
   and b.owner='SYS';

TABLE_NAME                     OWNER      CONSTRAINT_NAME                C R_OWNER    R_CONSTRAINT_NA TABLE_NAME
------------------------------ ---------- ------------------------------ - ---------- --------------- ------------------------------
T3                             SYS        FK_PRODUCTSTAT_PRODUCTID       R SYS        SYS_C0012328    T2

SQL>  select sid,serial#,sql_id,program,username,event,blocking_session from v$session where blocking_session is not null;

       SID    SERIAL# SQL_ID        PROGRAM                                          USERNAME                       EVENT                                                  BLOCKING_SESSION
---------- ---------- ------------- ------------------------------------------------ ------------------------------ ---------------------------------------------------------------- ----------------
        53        427 1cgjmu64ztjch sqlplus@wang (TNS V1-V3)                         SYS                            enq: TX - row lock contention                        57
SQL> select sql_text from v$sql where sql_id='1cgjmu64ztjch';

SQL_TEXT
-------------------------------------------------------------
insert into t3 values(1,'tt',4)

SQL>
SQL> select sid,serial#,sql_id,program,username,event,blocking_session from v$session where sid=57;

SID    SERIAL# SQL_ID              PROGRAM                                             USERNAME          EVENT                        BLOCKING_SESSION
---------- ---------- ------------- ------------------------------------------------ ------------------------------
        57        575               sqlplus@wang (TNS V1-V3)                         SYS         SQL*Net message from client

SQL>    

現(xiàn)在將session1提交:
SQL> commit;

Commit complete.

SQL> 

--session2插入也完成:
SQL> insert into t3 values(1,'tt',4);
            
        
1 row created.

SQL>SQL> commit;

Commit complete.

到此,相信大家對“數(shù)據(jù)庫的等待事件TX-row lock contention怎么解決”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI