一次cursor: pin S wait on X事件的跟蹤
下午接到維護髮來的郵件,大體記憶體如下:
3月7號晚10點左右,資源管理系統資料庫 gxdb1 發生大量鎖等待,而且出現多個阻塞鎖。活動session數達到350左右, 等待事件為 cursor : pin s wait on X 。經殺掉相關session後系統恢復正常。
希望找出問題發生的原因。
下面記錄查詢問題的過程:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production
SQL>
由於hist_active_sess_history表的資料比較大,把'2011030717' ~ '2011030722' 這個時間段裡的session資料提取出來
SQL> create table temp_hist_active_sess_history nologging as
2 select * from dba_hist_active_sess_history
3 where to_char(sample_time, 'yyyymmddhh24') between '2011030717' and '2011030722';
2 select * from dba_hist_active_sess_history
3 where to_char(sample_time, 'yyyymmddhh24') between '2011030717' and '2011030722';
alter table temp_hist_active_sess_history add record_time varchar2(50);
update temp_hist_active_sess_history set record_time = to_char(sample_time,'yyyy-mm-dd hh24:mi:ss');
commit;
update temp_hist_active_sess_history set record_time = to_char(sample_time,'yyyy-mm-dd hh24:mi:ss');
commit;
...省略建立index的過程
SQL>col p2 format 9999999999999999
SQL> select distinct session_id,session_serial#,p1,p2
2 from temp_hist_active_sess_history
3 where event ='cursor: pin S wait on X'
4 and rownum<=50;
2 from temp_hist_active_sess_history
3 where event ='cursor: pin S wait on X'
4 and rownum<=50;
SESSION_ID SESSION_SERIAL# P1 P2
---------- --------------- ---------- -----------------
2861 52370 668057193 19387482374144
4173 62920 668057193 19155554140160
517 28649 3522657913 21333102559232
533 16512 3522657913 21333102559232
606 39602 3522657913 21333102559232
626 14637 3522657913 21333102559232
855 53933 3522657913 21333102559232
1062 46600 3522657913 21333102559232
1249 63282 3522657913 21333102559232
528 35867 3522657913 21333102559232
691 41082 3522657913 21333102559232
---------- --------------- ---------- -----------------
2861 52370 668057193 19387482374144
4173 62920 668057193 19155554140160
517 28649 3522657913 21333102559232
533 16512 3522657913 21333102559232
606 39602 3522657913 21333102559232
626 14637 3522657913 21333102559232
855 53933 3522657913 21333102559232
1062 46600 3522657913 21333102559232
1249 63282 3522657913 21333102559232
528 35867 3522657913 21333102559232
691 41082 3522657913 21333102559232
SESSION_ID SESSION_SERIAL# P1 P2
---------- --------------- ---------- -----------------
976 56788 3522657913 21333102559232
1196 41756 3522657913 21333102559232
1514 45826 3522657913 21333102559232
1525 16156 3522657913 21333102559232
1633 9783 3522657913 21333102559232
1677 52748 3522657913 21333102559232
933 13220 3522657913 21333102559232
942 17109 3522657913 21333102559232
979 33487 3522657913 21333102559232
1341 14797 3522657913 21333102559232
1398 15817 3522657913 21333102559232
---------- --------------- ---------- -----------------
976 56788 3522657913 21333102559232
1196 41756 3522657913 21333102559232
1514 45826 3522657913 21333102559232
1525 16156 3522657913 21333102559232
1633 9783 3522657913 21333102559232
1677 52748 3522657913 21333102559232
933 13220 3522657913 21333102559232
942 17109 3522657913 21333102559232
979 33487 3522657913 21333102559232
1341 14797 3522657913 21333102559232
1398 15817 3522657913 21333102559232
SESSION_ID SESSION_SERIAL# P1 P2
---------- --------------- ---------- -----------------
1441 10065 3522657913 21333102559232
1566 7846 3522657913 21333102559232
1667 62940 3522657913 21333102559232
3794 41447 668057193 19155554140160
549 36165 3522657913 21333102559232
631 9934 3522657913 21333102559232
812 42615 3522657913 21333102559232
934 18908 3522657913 21333102559232
1365 5812 3522657913 21333102559232
1491 41510 3522657913 21333102559232
1539 9132 3522657913 21333102559232
---------- --------------- ---------- -----------------
1441 10065 3522657913 21333102559232
1566 7846 3522657913 21333102559232
1667 62940 3522657913 21333102559232
3794 41447 668057193 19155554140160
549 36165 3522657913 21333102559232
631 9934 3522657913 21333102559232
812 42615 3522657913 21333102559232
934 18908 3522657913 21333102559232
1365 5812 3522657913 21333102559232
1491 41510 3522657913 21333102559232
1539 9132 3522657913 21333102559232
SESSION_ID SESSION_SERIAL# P1 P2
---------- --------------- ---------- -----------------
851 35281 3522657913 21333102559232
1597 48481 3522657913 21333102559232
2824 37947 668057193 19155554140160
2961 17626 668057193 19155554140160
660 30581 3522657913 21333102559232
472 6095 3522657913 21333102559232
881 54009 3522657913 21333102559232
889 14408 3522657913 21333102559232
1098 36953 3522657913 21333102559232
1675 4908 3522657913 21333102559232
1720 46180 3522657913 21333102559232
---------- --------------- ---------- -----------------
851 35281 3522657913 21333102559232
1597 48481 3522657913 21333102559232
2824 37947 668057193 19155554140160
2961 17626 668057193 19155554140160
660 30581 3522657913 21333102559232
472 6095 3522657913 21333102559232
881 54009 3522657913 21333102559232
889 14408 3522657913 21333102559232
1098 36953 3522657913 21333102559232
1675 4908 3522657913 21333102559232
1720 46180 3522657913 21333102559232
SESSION_ID SESSION_SERIAL# P1 P2
---------- --------------- ---------- -----------------
640 61791 3522657913 21333102559232
817 13269 3522657913 21333102559232
951 20788 3522657913 21333102559232
970 57853 3522657913 21333102559232
1423 22083 3522657913 21333102559232
1709 10839 3522657913 21333102559232
---------- --------------- ---------- -----------------
640 61791 3522657913 21333102559232
817 13269 3522657913 21333102559232
951 20788 3522657913 21333102559232
970 57853 3522657913 21333102559232
1423 22083 3522657913 21333102559232
1709 10839 3522657913 21333102559232
50 rows selected.
我們來分析p2=21333102559232,前兩個位元組資料為 4967
SQL> select session_id,
2 session_serial#,
3 event,
4 blocking_session,
5 blocking_session_serial#
6 from temp_hist_active_sess_history
7 where session_id = 4967
8 order by record_time;
2 session_serial#,
3 event,
4 blocking_session,
5 blocking_session_serial#
6 from temp_hist_active_sess_history
7 where session_id = 4967
8 order by record_time;
SESSION_ID SESSION_SERIAL# EVENT BLOCKING_SESSION BLOCKING_SESSION_SERIAL#
---------- --------------- ---------------------------------------------------------------- ---------------- ------------------------
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
---------- --------------- ---------------------------------------------------------------- ---------------- ------------------------
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
4967 12169 library cache pin 2704 36420
.....
SQL> select session_id,
2 session_serial#,
3 event,
4 blocking_session,
5 blocking_session_serial#
6 from temp_hist_active_sess_history
7 where session_id = 2704
8 and session_serial# = 36420;
2 session_serial#,
3 event,
4 blocking_session,
5 blocking_session_serial#
6 from temp_hist_active_sess_history
7 where session_id = 2704
8 and session_serial# = 36420;
SESSION_ID SESSION_SERIAL# EVENT BLOCKING_SESSION BLOCKING_SESSION_SERIAL#
---------- --------------- ---------------------------------------------------------------- ---------------- ------------------------
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
---------- --------------- ---------------------------------------------------------------- ---------------- ------------------------
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
2704 36420 enq: TX - row lock contention 3537 32344
這樣迴圈找下去,得到如下
SQL> select session_id,
2 session_serial#,
3 event,
4 blocking_session,
5 blocking_session_serial#,
6 sql_id,
7 program,
8 record_time
9 from temp_hist_active_sess_history
10 where session_id = 3738
11 and session_serial# = 45559
12 order by record_time;
2 session_serial#,
3 event,
4 blocking_session,
5 blocking_session_serial#,
6 sql_id,
7 program,
8 record_time
9 from temp_hist_active_sess_history
10 where session_id = 3738
11 and session_serial# = 45559
12 order by record_time;
.....
SESSION_ID SESSION_SERIAL# EVENT BLOCKING_SESSION BLOCKING_SESSION_SERIAL# SQL_ID PROGRAM RECORD_TIME
---------- --------------- ------------------------------- ---------------- ------------------------ ------------- ---------------- -------------
3738 45559 db file sequential read 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:00
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:10
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:20
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:30
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:40
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:50
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:00
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:10
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:20
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:30
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:40
....
SESSION_ID SESSION_SERIAL# EVENT BLOCKING_SESSION BLOCKING_SESSION_SERIAL# SQL_ID PROGRAM RECORD_TIME
---------- --------------- ------------------------------- ---------------- ------------------------ ------------- ---------------- ------------
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:30:57
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:07
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:17
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:27
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:37
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:48
SESSION_ID SESSION_SERIAL# EVENT BLOCKING_SESSION BLOCKING_SESSION_SERIAL# SQL_ID PROGRAM RECORD_TIME
---------- --------------- ------------------------------- ---------------- ------------------------ ------------- ---------------- -------------
3738 45559 db file sequential read 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:00
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:10
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:20
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:30
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:40
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:54:50
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:00
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:10
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:20
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:30
3738 45559 8qg7sa3nramwx plsqldev.exe 2011-03-07 17:55:40
....
SESSION_ID SESSION_SERIAL# EVENT BLOCKING_SESSION BLOCKING_SESSION_SERIAL# SQL_ID PROGRAM RECORD_TIME
---------- --------------- ------------------------------- ---------------- ------------------------ ------------- ---------------- ------------
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:30:57
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:07
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:17
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:27
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:37
3738 45559 SQL*Net break/reset to client 8qg7sa3nramwx plsqldev.exe 2011-03-07 18:31:48
現在我們來看看‘8qg7sa3nramwx ’在做什麼
SQL> select to_char(sql_text) from dba_hist_sqltext where sql_id ='8qg7sa3nramwx'
2 ;
2 ;
TO_CHAR(SQL_TEXT)
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
update rmgz.opt_ocf set ponmark=2 where ponmark is null and ocftype in (8,9)
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
update rmgz.opt_ocf set ponmark=2 where ponmark is null and ocftype in (8,9)
現在很明顯了:有維護人員在批量更新資料。
opt_ocf是一個比較大的表,裡面ocftype in (8,9)的重複記錄有很多,鎖了很多記錄,造成大量的Lock。
對於負載很大的應用系統,批量更新資料時一定要非常小心。
必須把大批量更新資料放在晚上閒時做或者把大事務劃分成小事務來分批提交.
附:
網上有許多關於cursor: pin S wait on X事件問題的描述,有的說是BUG,有的說停用ASMM就好了,有的說修改了某某引數就OK了。其實只要我們注意日常在生產庫中的操作和維護,排除掉人為的因素,這樣的問題是很少會出現的。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/195110/viewspace-688790/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- cursor pin S wait on XAI
- cursor: pin S wait on XAI
- oracle等待事件之cursor:pin S wait on XOracle事件AI
- cursor:pin S wait on X故障診分析AI
- [20201117]解析cursor pin S等待事件.txt事件
- cursor: pin S簡單說明以及測試、解決
- [20190320]測試相同語句遇到導致cursor pin S的情況.txt
- [20190321]測試相同語句遇到導致cursor pin S的疑問.txt
- Cursor Mutex S Waits等待事件引發hangMutexAI事件
- [20240920]跟蹤library cache lock library cache pin使用gdb.txt
- [20240824]跟蹤library cache lock library cache pin使用gdb.txt
- oracle跟蹤常用內部事件號Oracle事件
- springcloudBus 2.x 事件追蹤SpringGCCloud事件
- [20200417]跟蹤特定sql語句以及v$open_cursor檢視.txtSQL
- [20190917]oracle跟蹤事件簡單寫法.txtOracle事件
- [20241105]跟蹤library cache lock library cache pin使用gdb(11g)2.txt
- [20241108]跟蹤library cache lock library cache pin使用gdb(11g)4.txt
- [20241108]跟蹤library cache lock library cache pin使用gdb(11g)3.txt
- [20200422]跟蹤特定sql語句以及v$open_cursor檢視(補充).txtSQL
- [20200417]跟蹤特定sql語句以及v$open_cursor檢視2.txtSQL
- Oracle:cursor:mutex XOracleMutex
- 【等待事件】library cache pin事件
- 利用errorstack事件進行錯誤跟蹤和診斷Error事件
- [20200424]跟蹤特定sql語句以及v$open_cursor檢視(再補充).txtSQL
- git的跟蹤分支和遠端跟蹤分支學習筆記Git筆記
- 在Axon框架中揭開跟蹤事件處理器的神秘面紗框架事件
- sp_trace_setfilter sqlserver篩選跟蹤或跟蹤過濾FilterSQLServer
- EF Core中Key屬性相同的實體只能被跟蹤(track)一次
- 主力跟蹤戰法
- 反跟蹤技術
- 以藍軍視角跟蹤和分析CANVAS攻擊框架洩露事件Canvas框架事件
- git列出跟蹤的檔案列表Git
- Mac好用的時間跟蹤器Mac
- 記一次除錯YOLOv5+DeepSort車輛跟蹤專案的經過除錯YOLO
- 常見的wait等待事件及處理(zt)AI事件
- [20190402]跟蹤vmstat.txt
- Linux 跟蹤器之選Linux
- SQLServer進行SQL跟蹤SQLServer
- 會話跟蹤技術會話