IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

[Oracle]记一次由sequence引发的enq sv-contention等待事件

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

数据库版本:11.2.0.4 RAC
(1)问题现象
从EM里面可以看到,在23号早上8:45~8:55时,数据库等待会话暴增,大约到了80个会话。通过查看EM的SQL信息,发现等待产生于SQL语句

select TIMEKEYID.nextval from dual

92_1.png

92_2.png

(二)问题追踪
获取AWR报告观察,在TOP事件中,排名第二的enq:SV-contention

92_3.png

再去查看AWR报告,发现该语句执行频率非常的高,在8:00~9:00期间执行了51万多次。

92_4.png

从执行的语句可以看出,使用到的数据库对象是一个sequence,查询可看到该sequence的语法:

CREATE SEQUENCE MODMGR.TIMEKEYID
  START WITH 1000
  MAXVALUE 999
  MINVALUE 0
  CYCLE
  CACHE 100
  ORDER;

(1)定位哪些程序执行该SQL

select    to_char(sample_time,'yyyy-mm-dd hh24:mi:ss') timekey,
          ash.session_id,
          ash."SESSION_SERIAL#",
          ash."MODULE"

from      dba_hist_active_sess_history  ash
where     ash.instance_number = 1
and       ash."SQL_ID" = '6ac0x1yudr8gq'
and       ash.sample_time between to_date('2018-12-23 08:00:00','yyyy-mm-dd hh24:mi:ss') 
          and to_date('2018-12-23 09:00:00','yyyy-mm-dd hh24:mi:ss')
group by  to_char(sample_time,'yyyy-mm-dd hh24:mi:ss'),
          ash.session_id,
          ash."SESSION_SERIAL#",
          ash."MODULE"
order by  timekey;

92_5.png

(2)定位该语句的执行频率

select    to_char(sample_time,'yyyy-mm-dd hh24:mi:ss') timekey,



          count(*) as sql_count
from      dba_hist_active_sess_history  ash
where     ash.instance_number = 1
and       ash."SQL_ID" = '6ac0x1yudr8gq'
and       ash.sample_time between to_date('2018-12-23 08:00:00','yyyy-mm-dd hh24:mi:ss') 
          and to_date('2018-12-23 09:00:00','yyyy-mm-dd hh24:mi:ss')
group by  to_char(sample_time,'yyyy-mm-dd hh24:mi:ss')



order by  timekey;

92_6.png

(3)再把时间扩长一些,查看最近4天的该sql捕获记录,发现其它时间段该sequence的使用并不是如此频繁,真正出问题是在大约23日8:49

select    sample_time,
          ash.session_id,
          ash."SESSION_SERIAL#",
          ash."MODULE",
          ash.event
from      dba_hist_active_sess_history  ash
where     ash.instance_number = 1
and       ash."SQL_ID" = '6ac0x1yudr8gq'
and       ash.sample_time between to_date('2018-12-20 00:00:00','yyyy-mm-dd hh24:mi:ss') 
          and to_date('2018-12-24 00:00:00','yyyy-mm-dd hh24:mi:ss')
order by sample_time;

92_7.png

至此可以得出结论:
程序BidmMES在早上8:49产生了大量的“select TIMEKEYID.nextval from dual”语句,导致缓存的100个sequcence快速使用完,缓存使用完后,数据库实例会为其分配新的缓存,异常就发生在分配缓存的时候,Oracle会更新sequence的字典信息,频繁的数据字典更新会导致要使用该sequence的session产生enq:SV-contention等待。

(三)解决方案

如果确认业务没问题,那么需要修改序列的最大值为9999和cache值为1000

alter sequence modmgr.TIMEKEYID maxvalue 9999 cache 1000;

另外,需要考虑,业务上是采用3位的sequence来与其它字符做连接,如果需要保持业务一致,需要截取数字。

(四)案例重现
(1)创建sequence

CREATE SEQUENCE b7dba.seq_test
  START WITH 1
  MAXVALUE 99999999
  MINVALUE 0
  CYCLE
  CACHE 10
  ORDER;

(2)创建一个plsql来消耗seq_test

create or replace procedure p_seq_test is
  seq_value    number ;begin

    select seq_test.nextval into seq_value from dual;

(3)创建400个job来调用该pl/sql

create or replace procedure create_more_job is
  v_counter    number;begin
  for v_counter in 1..400 loop
    declare
      job1 number;
    begin
      sys.dbms_job.submit(job => job1,
                          what => 'p_seq_test;',
                          next_date => sysdate,
                          interval => 'sysdate + 1/(1440*60)'    
                          );
    commit;
    end;
  end loop;end create_more_job;

(4)通过修改cache来查看等待
alter sequence b7dba.seq_test cache {cache数量};
(4、1)no cacahe

drop  SEQUENCE b7dba.seq_test;CREATE SEQUENCE b7dba.seq_test
  START WITH 1
  MAXVALUE 99999999
  MINVALUE 0
  CYCLE
  NOCACHE
  ORDER;

(4、2)cache = 2

drop  SEQUENCE b7dba.seq_test;
CREATE SEQUENCE b7dba.seq_test
  START WITH 1
  MAXVALUE 99999999
  MINVALUE 0
  CYCLE
  CACHE 2
  ORDER;

(4、3)cache = 10

alter sequence b7dba.seq_test cache 10;

(4、4)cache = 100

alter sequence b7dba.seq_test cache 100;

(4、5)cache = 1000

alter sequence b7dba.seq_test cache 1000;

92_8.png

【完】

文章永久链接:https://tech.souyunku.com/?p=35295


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(86) 打赏



未经允许不得转载:搜云库技术团队 » [Oracle]记一次由sequence引发的enq sv-contention等待事件

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367