程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 如何通過trace診斷ORA-00060DeadlockType?

如何通過trace診斷ORA-00060DeadlockType?

編輯:Oracle教程

今天是2014-03-12,在進行數據庫性能調優過程中,突然翻到了之前一封郵件,信息如下:

從日志中看,發現存在行級排他鎖存在爭用以致產生了死鎖。

問題描述:

*** 2013-12-02 17:03:10.148 DEADLOCK DETECTED ( ORA-00060 ) [Transaction Deadlock] 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-000b002b-002be2d3 61 958 X 141 876 X TX-0009001c-000d5ffa 141 876 X 61 958 X session 958: DID 0001-003D-00001BC1 session 876: DID 0001-008D-0000B424 session 876: DID 0001-008D-0000B424 session 958: DID 0001-003D-00001BC1 Rows waited on: Session 876: obj - rowid = 0000DE75 - AAAN51AArAAAA6mAAO (dictionary objn - 56949, file - 43, block - 3750, slot - 14) Session 958: obj - rowid = 00014F07 - AAAU8HABXAAA7BqAAI (dictionary objn - 85767, file - 87, block - 241770, slot - 8) Information on the OTHER waiting sessions: Session 876: sid: 876 ser: 38057 audsid: 7879846 user: 47/EPMFRAMEWORK flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x8) pid: 141 O/S info: user: orarep, term: UNKNOWN, ospid: 11195 image: oracle@pmsdb2 O/S info: user: webpms2, term: unknown, ospid: 1234, machine: pmsrep1 program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 Current SQL Statement: UPDATE AP_COLL_INFO_T T SET T.PROCINST_ID = NULL, T.IF_PROJECT_INHERITED = '0' WHERE T.INVEST_SNO = :1 End of information on OTHER waiting sessions. Current SQL statement for this session: UPDATE AP_PROJECT_INFO_EDITION_T T SET T.IF_INHERITED='1' WHERE T.AP_PRJ_SNO=:1 在上面可以獲得很多可以幫助診斷問題的信息,該信息顯示由於應用邏輯錯誤,導致了死鎖的產生。 另外還可以通過相關sql獲得一些簡要信息: eg:
2、分解rowid獲得產生死鎖等待的對象信息如下:
SQL> select a.owner,
  2         a.object_name,
  3         a.object_type,
  4         a.last_ddl_time,
  5         a.created,
  6         a.status,
  7         b.object,
  8         b.fno,
  9         b.rownu,
10         b.block
11    from (select dbms_rowid.rowid_object('AAAU8HABXAAA7BqAAI') object,
12                 dbms_rowid.rowid_relative_fno('AAAU8HABXAAA7BqAAI') fno,
13                 dbms_rowid.rowid_row_number('AAAU8HABXAAA7BqAAI') rowNU,
14                 dbms_rowid.rowid_block_number('AAAU8HABXAAA7BqAAI') block
15            from dual) b,
16         dba_objects a
17   where a.object_id = b.object;
OWNER                          OBJECT_NAME                                                                      OBJECT_TYPE         LAST_DDL_TIME CREATED     STATUS      OBJECT        FNO      ROWNU      BLOCK
------------------------------ -------------------------------------------------------------------------------- ------------------- ------------- ----------- ------- ---------- ---------- ---------- ----------
EPMFRAMEWORK                   AP_PROJECT_INFO_EDITION_T                                                        TABLE               2013-11-27 11 2012-06-05  VALID        85767         87          8     241770
SQL> 
SQL> select a.owner,
  2         a.object_name,
  3         a.object_type,
  4         a.last_ddl_time,
  5         a.created,
  6         a.status,
  7         b.object,
  8         b.fno,
  9         b.rownu,
10         b.block
11    from (select dbms_rowid.rowid_object('AAAN51AArAAAA6mAAO') object,
12                 dbms_rowid.rowid_relative_fno('AAAN51AArAAAA6mAAO') fno,
13                 dbms_rowid.rowid_row_number('AAAN51AArAAAA6mAAO') rowNU,
14                 dbms_rowid.rowid_block_number('AAAN51AArAAAA6mAAO') block
15            from dual) b,
16         dba_objects a
17   where a.object_id = b.object;
OWNER                          OBJECT_NAME                                                                      OBJECT_TYPE         LAST_DDL_TIME CREATED     STATUS      OBJECT        FNO      ROWNU      BLOCK
------------------------------ -------------------------------------------------------------------------------- ------------------- ------------- ----------- ------- ---------- ---------- ---------- ----------
EPMFRAMEWORK                   AP_COLL_INFO_T                                                                   TABLE               2012-04-01 21 2011-10-05  VALID        56949         43         14       3750
SQL> 
3、導致此問題的sql語句為:
SQL> SELECT B.SQL_ID,SQL_FULLTEXT,B.EVENT,B.SAMPLE_TIME,B.SESSION_ID FROM V$sqL A INNER JOIN (
  2  select session_id, session_serial#, sql_id, event, SAMPLE_TIME
  3    from dba_hist_active_sess_history
  4   where event = 'enq: TX - row lock contention'
  5     and sample_time >
  6         to_date('2013-12-02 17:02:00', 'YYYY-MM-DD HH24:MI:SS') ) B
  7         ON A.SQL_ID=B.SQL_ID;
SQL_ID        SQL_FULLTEXT                                                                                                   EVENT                                                            SAMPLE_TIME                                                                      SESSION_ID
------------- -------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------- -------------------------------------------------------------------------------- ----------
9bwcgrn96cx62 INSERT INTO rt_actinst_data(instance_id,name,type,data,merge_type,rdata_app)VALUES(:1,:2,:3,:4,:5,:6)          enq: TX - row lock contention                                    02-12月-13 05.03.21.158 下午                                                            959
9bwcgrn96cx62 INSERT INTO rt_actinst_data(instance_id,name,type,data,merge_type,rdata_app)VALUES(:1,:2,:3,:4,:5,:6)          enq: TX - row lock contention                                    02-12月-13 05.03.11.158 下午                                                            959
1npq5jnavnc0k UPDATE AP_PROJECT_INFO_EDITION_T T SET T.IF_INHERITED='1' WHERE  T.AP_PRJ_SNO=:1                               enq: TX - row lock contention                                    02-12月-13 05.03.01.153 下午                                                            958
9bwcgrn96cx62 INSERT INTO rt_actinst_data(instance_id,name,type,data,merge_type,rdata_app)VALUES(:1,:2,:3,:4,:5,:6)          enq: TX - row lock contention                                    02-12月-13 05.03.01.153 下午                                                            959
1npq5jnavnc0k UPDATE AP_PROJECT_INFO_EDITION_T T SET T.IF_INHERITED='1' WHERE  T.AP_PRJ_SNO=:1                               enq: TX - row lock contention                                    02-12月-13 05.02.51.148 下午                                                            958
1npq5jnavnc0k UPDATE AP_PROJECT_INFO_EDITION_T T SET T.IF_INHERITED='1' WHERE  T.AP_PRJ_SNO=:1                               enq: TX - row lock contention                                    02-12月-13 05.02.41.148 下午                                                            958
1npq5jnavnc0k UPDATE AP_PROJECT_INFO_EDITION_T T SET T.IF_INHERITED='1' WHERE  T.AP_PRJ_SNO=:1                               enq: TX - row lock contention                                    02-12月-13 05.02.31.148 下午                                                            958
7 rows selected
SQL> 

我要說的是在trace中可以獲得一個deadlock graph: 看個例子: \ 那麼本次鎖的最後組合為:tx x x; 最後總結一下(一見明了): \ 參考(1507093.1

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved