oracle 11.2.0.4 rac叢集等待事件enq: TM - contention

清風艾艾發表於2018-09-30

    近期,一金融客戶oracle 11.2.0.4 rac叢集delete不當導致等待事件enq: TM - contention嚴重引起大範圍會話堆積,記錄的相關分析工作如下。

1、登入叢集任意節點,檢視叢集全域性等待事件

SQL> select event,count(*) from gv$session where wait_class<>'Idle' group by event; 
EVENT                                         COUNT(*) 
---------------------------------------------------------------- ---------- 
enq: TM - contention                  24

2、檢視等待事件在兩個節點的分佈

節點1:

EVENT COUNT(*) 
---------------------------------------------------------------- ---------- 
SQL*Net message from client 79 
rdbms ipc message 64 
enq: TM - contention 22 
gcs remote message 10 
Space Manager: slave idle wait 5 
wait for unread message on broadcast channel 4 
DIAG idle wait 4 
class slave wait 3 
Streams AQ: waiting for time management or cleanup tasks 2 
Streams AQ: qmn coordinator idle wait 2 
PX Deq: Execution Msg 2 
VKTM Logical Idle Wait 2 
GCR sleep 2 
Streams AQ: qmn slave idle wait 2 
smon timer 2 
pmon timer 2 
ges remote message 2 
ASM background timer 2 
PING 2 
PX Deq: Execute Reply 1

節點2:

EVENT COUNT(*) 
---------------------------------------------------------------- ---------- 
SQL*Net message from client 49 
rdbms ipc message 32 
gcs remote message 5 
wait for unread message on broadcast channel 2 
class slave wait 2 
DIAG idle wait 2 
Space Manager: slave idle wait 2 
enq: TM - contention 2 
smon timer 1 
PING 1 
Streams AQ: qmn slave idle wait 1 
SQL*Net message to client 1 
GCR sleep 1 
ges remote message 1 
VKTM Logical Idle Wait 1 
Streams AQ: qmn coordinator idle wait 1 
ASM background timer 1 
pmon timer 1 
Streams AQ: waiting for time management or cleanup tasks 1

19 rows selected.

3、檢視引起enq: TM - contention等待事件的會話資訊

       SID USERNAME SQL_ID MODULE MACHINE PROGRAM 
---------- ---------- ------------- ---------- ---------------------------------------------------------------- ------------------------------------------------ 
363 MW_SYS 74j1zd36h4n96 localhost.localdomain 
387 MW_SYS 74j1zd36h4n96 localhost.localdomain 
602 MW_SYS 74j1zd36h4n96 localhost.localdomain 
626 MW_SYS 74j1zd36h4n96 localhost.localdomain 
674 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1106 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1441 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1730 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1946 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1969 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1993 MW_SYS 74j1zd36h4n96 localhost.localdomain 
1994 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2041 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2042 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2066 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2067 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2091 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2114 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2137 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2138 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2161 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2162 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2209 MW_SYS 74j1zd36h4n96 localhost.localdomain 
2233 MW_SYS 74j1zd36h4n96 localhost.localdomain 
24 rows selected.

4、檢視SQL語句74j1zd36h4n96文字資訊

SQL_FULLTEXT 
-------------------------------------------------------------------------------- 
delete from mw_sys.mwt_is_user m where m.user_id not in('0D3C0ACD-C95B-42DA-A5DE 
-70F019DAB52B','8697D72E-C77B-4C70-A434-ED7D488ADC36');

5、檢視SQL語句74j1zd36h4n96的執行計劃

PLAN_TABLE_OUTPUT 
--------------------------------------------------------------------------------------------------------------
SQL_ID 74j1zd36h4n96, child number 0 
------------------------------------- 
delete from mw_sys.mwt_is_user m where m.user_id not 
in('0D3C0ACD-C95B-42DA-A5DE-70F019DAB52B','8697D72E-C77B-4C70-A434-ED7D4 
88ADC36') 
Plan hash value: 3271715000 
---------------------------------------------------------------------------------- 
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | 
---------------------------------------------------------------------------------- 
| 0 | DELETE STATEMENT | | | | 210 (100)| | 
| 1 | DELETE | MWT_IS_USER | | | | | 
|* 2 | TABLE ACCESS FULL| MWT_IS_USER | 18739 | 951K| 210 (1)| 00:00:03 | 
---------------------------------------------------------------------------------- 
Query Block Name / Object Alias (identified by operation id): 
------------------------------------------------------------- 
1 - DEL$1 
2 - DEL$1 / M@DEL$1 
Outline Data 
------------- 
/*+ 
BEGIN_OUTLINE_DATA 
IGNORE_OPTIM_EMBEDDED_HINTS 
OPTIMIZER_FEATURES_ENABLE('11.2.0.4') 
DB_VERSION('11.2.0.4') 
OPT_PARAM('_bloom_filter_enabled' 'false') 
OPT_PARAM('_optimizer_extended_cursor_sharing' 'none') 
OPT_PARAM('_bloom_pruning_enabled' 'false') 
OPT_PARAM('_optimizer_extended_cursor_sharing_rel' 'none') 
OPT_PARAM('_optimizer_adaptive_cursor_sharing' 'false') 
OPT_PARAM('_optimizer_use_feedback' 'false') 
ALL_ROWS 
OUTLINE_LEAF(@"DEL$1") 
FULL(@"DEL$1" "M"@"DEL$1") 
END_OUTLINE_DATA 
*/ 
Predicate Information (identified by operation id): 
--------------------------------------------------- 
2 - filter(("M"."USER_ID"<>'0D3C0ACD-C95B-42DA-A5DE-70F019DAB52B' AND 
"M"."USER_ID"<>'8697D72E-C77B-4C70-A434-ED7D488ADC36')) 
Column Projection Information (identified by operation id): 
----------------------------------------------------------- 
2 - (cmp=2; cpy=2,3) "M".ROWID[ROWID,10], "M"."USER_ID"[CHARACTER,36], 
"M"."USER_NAME"[VARCHAR2,64], "USER_ISSYSTEM"[CHARACTER,1], 
"USER_STATUS"[CHARACTER,1] 
55 rows selected.

6、查詢SQL語句74j1zd36h4n96要保留的資料量

SQL> select count(*) from mw_sys.mwt_is_user where user_id ='0D3C0ACD-C95B-42DA-A5DE-70F019DAB52B'; 

COUNT(*) 
---------- 

SQL> 
SQL> select count(*) from mw_sys.mwt_is_user where user_id ='8697D72E-C77B-4C70-A434-ED7D488ADC36'; 
COUNT(*) 
---------- 
1

7、檢視SQL語句74j1zd36h4n96要刪除的資料量

SQL> select count(*) from mw_sys.mwt_is_user m where m.user_id not in('0D3C0ACD-C95B-42DA-A5DE 
-70F019DAB52B','8697D72E-C77B-4C70-A434-ED7D488ADC36'); 2 
COUNT(*) 
---------- 
18740

8、問題

   由以上資訊可知,24個會話分佈在兩個節點上通知對同一張表執行相同的delete操作,而且刪除的資料量是大範圍的,只保留2條記錄,

因此導致嚴重的enq:TM鎖。

9、建議

    delete操作分批執行,且控制會話間執行的delete語句刪除的資料沒有交集。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29357786/viewspace-2215381/,如需轉載,請註明出處,否則將追究法律責任。

相關文章