今天遇到一個生產庫產生大量row cache lock,如下是相應步驟:
1 查詢當時P1的狀況sql
select INSTANCE_NUMBER,p1,count(*) cnt from dba_hist_active_sess_history where event='row cache lock' and SAMPLE_TIME>=to_date('2018-08-31 10:00:00','yyyy-mm-dd hh24:mi:ss') and SAMPLE_TIME <=to_date('2018-08-31 10:40:00','yyyy-mm-dd hh24:mi:ss') group by INSTANCE_NUMBER,p1 order by cnt;session
2 根據第一步查詢的P1,代入到下面cache#,這裏查詢出來的結果是13,dc_sequenceside
select INST_ID, CACHE#,TYPE,GETS,PARAMETER from gv$rowcache where CACHE# in (?) order by gets;code
3 查詢當時用戶會話量狀況get
select INSTANCE_NUMBER,USER_ID,count(*) cnt from dba_hist_active_sess_history 2 where SAMPLE_TIME>=to_date('2018-08-31 10:00:00','yyyy-mm-dd hh24:mi:ss') and SAMPLE_TIME <=to_date('2018-08-31 10:30:00','yyyy-mm-dd hh24:mi:ss') 3 group by INSTANCE_NUMBER,USER_ID order by 1,cnt;it
4 查詢對應SQL的狀況io
select INSTANCE_NUMBER,SAMPLE_TIME,event,sql_opname,sql_id,count(*) cnt from dba_hist_active_sess_history where SAMPLE_TIME>=to_date('2018-08-31 10:00:00','yyyy-mm-dd hh24:mi:ss') and SAMPLE_TIME <=to_date('2018-08-31 10:30:00','yyyy-mm-dd hh24:mi:ss') group by INSTANCE_NUMBER,SAMPLE_TIME,event,sql_opname,sql_id order by 2,1;event
5 查詢對應節點更詳細的會話信息class
select INSTANCE_NUMBER,SAMPLE_TIME,session_id,BLOCKING_SESSION,current_obj#,user_id,event,sql_id,P1 from dba_hist_active_sess_history where SAMPLE_TIME>=to_date('2018-08-31 10:17:00','yyyy-mm-dd hh24:mi:ss') and SAMPLE_TIME <=to_date('2018-08-31 10:20:00','yyyy-mm-dd hh24:mi:ss') and INSTANCE_NUMBER=2 and event='row cache lock';date
最後定位是一個高頻INSERT 語句引用SEQUENCE引發的,而這個序列是NOCAHE,改爲cache恢復正常