Oracle cursor pin S wait on X 等待事件 说明

2024-04-04 02:48

本文主要是介绍Oracle cursor pin S wait on X 等待事件 说明,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

       这个等待事件也算一个常见的等待事件。 warehouse blog  itpub 上有相关的2个帖子。 连接如下:

 

cursor: pin S wait on X等待事件模拟

http://warehouse.itpub.net/post/777/493962

 

 

cursor: pin S wait on X

http://space.itpub.net/756652/viewspace-348176

 

 

.  Mutex 说明

       Oracle Mutex 机制 说明

       http://blog.csdn.net/tianlesoftware/archive/2011/05/30/6455517.aspx

 

       To improve cursor execution and also hard parsing, a new memory serialization mechanism has been created in 10gR2.
       For certain shared-cursor related operations, mutexes are used as a replacement for library cache latches and librarycache pins.

       -- mutexes 替代 library cache latches librarycache pins

 

       Using mutexes is faster, uses less CPU and also allows significantly improved concurrency over the existing latch mechanism.
       The use of mutexes for cursor pins can be enabled by setting the init.ora parameter _use_kks_mutex toTRUE.

      

       Btw, things get more fun in 10.2, you can pin cursors without getting library cache pin latch, using KGX mutexes. Mutexes are new thing in 10.2 and they enable shared access to objects in somewhat similar manner than shared latches, that every successful get of particular mutex will increment its value and release will decrement. When the count is zero, no-one has the mutex and it is safe to get it in exclusive mode too. However they are more fine grained than kgl latches and provide better waiting mechanism as far as I understand.

       So if your environment supports atomic compare and swap operation (as CMPXCHG on Intel), you might get away without cursor_space_for_time setting for ultrahigh execution rates. Otherwise the atomic mutex operations would be achieved using new KGX latches.

       At least on my laptop this feature isn’t enabled by default (from andOracleWorld’s paper I remember that it should become default in 10.2.0.2), but so far you can experiment with it if you set _kks_use_mutex_pin = true and bounce the instance (mutex structures will be stored in shared pool, so you might need to increase SP size).

       There are also x$mutex_sleep and x$mutex_sleep_history fixed tables that can show some interesting information if you generate some mutex waits into them.

 

       Oracle 10.2中,对shared pool中的一些Serialization operation使用更轻量的 KGX mutexes (_use_kks_mutex) 取代library cache pin,从而降低CPU Usage, 是否使用这种muetx机制受到隐含参数_kks_use_mutex_pin的限制

 

       10.2.0.2开始该参数defaulttrue,使用这种机制oracle是为了解决library cache bin latch的串行使用问题,但是mutex貌似还不是很稳定,在很多系统中会出现cursor: pin S wait on X等待事件,这个事件和mutex的使用有关,最近一客户受到cursor: pin S wait on X等待事件的困扰,出现cursor: pin S wait on X等待事件时通常等待比较严重,系统会出现hang

 

cursor: pin S wait on X
       A session waits for this event when it is requesting a shared mutex pin and another session is holding an exclusive mutex pin on the same cursor object.

 

Wait Time: Microseconds

 

Parameter Description
       P1 Hash value of cursor
       P2 Mutex value (top 2 bytes contains SID holding mutex in exclusive mode, and bottom two bytes usually hold the value 0)
       P3 Mutex where (an internal code locator) OR'd with Mutex Sleeps

 

 

这个事件的出现受到很多因素的影响,在高并发的情况下:

              1sga自动管理,sga的频繁扩展和收缩

              2)过渡硬解析,造成library cache中的cursor object被频繁的reload

              3bug

 

       _kks_use_mutex_pin 是隐含参数,通过v$parameter 视图查不到,需要通过如下SQL 来查看。

 

SELECT   i.ksppinm name,

           i.ksppdesc description,

           CV.ksppstvl VALUE,

           CV.ksppstdf isdefault,

           DECODE (BITAND (CV.ksppstvf, 7),

                   1, 'MODIFIED',

                   4, 'SYSTEM_MOD',

                   'FALSE')

              ismodified,

           DECODE (BITAND (CV.ksppstvf, 2), 2, 'TRUE', 'FALSE') isadjusted

    FROM   sys.x$ksppi i, sys.x$ksppcv CV

   WHERE       i.inst_id = USERENV ('Instance')

           AND CV.inst_id = USERENV ('Instance')

           AND i.indx = CV.indx

           AND i.ksppinm LIKE '/_%' ESCAPE '/'

           and i.ksppinm like '_kks%'

ORDER BY   REPLACE (i.ksppinm, '_', '');

 

 

Oracle 参数分类 参数的查看方法

http://www.cndba.cn/Dave/article/1173

 

 

. 相关测试

SYS@anqing2(rac2)> select * from v$version where rownum<2;

 

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod

 

SESSION 1:

-------------------------

 

 

--创建测试表

SYS@anqing2(rac2)> create table t as select * from dba_objects;

Table created.

 

--查看session ID

SYS@anqing2(rac2)> select sid from v$mystat where rownum=1;

SID

----------

125

 

 

SYS@anqing2(rac2)> declare

  2  v_string varchar2(100) := 'alter system flush shared_pool';

  3  msql varchar2(200);

  4  begin

  5  loop

  6  execute immediate v_string;

  7  for i in 1..100 loop

  8  msql:='select object_id from t where object_id='||i;

  9  execute immediate msql;

 10  end loop;

 11  end loop;

 12  end;

 13  /

 

session 2

-------------------------

--查看session ID

SYS@anqing2(rac2)> select sid from v$mystat where rownum=1;

SID

----------

130

 

SYS@anqing2(rac2)> declare

  2  v_string varchar2(100) := 'alter system flush shared_pool';

  3  msql varchar2(200);

  4  begin

  5  loop

  6  execute immediate v_string;

  7  for i in 1..100 loop

  8  msql:='select object_id from t where object_id='||i;

  9  execute immediate msql;

 10  end loop;

 11  end loop;

 12  end;

 13  /

 

 

session 3

------------------------

用如下SQL 进行监控,在sqlplus 里看起来格式有点乱,我放到Toad执行了。

 

/* Formatted on 2011/6/16 16:06:44 (QP5 v5.163.1008.3004) */

SELECT b.*, sq.sql_text

  FROM v$session se,

       v$sql sq,

       (SELECT a.*, s.sql_text

          FROM v$sql s,

               (SELECT sid,

                       event,

                       wait_class,

                       p1,

                       p2raw,

                       TO_NUMBER (SUBSTR (p2raw, 1, 4), 'xxxx')

                          sid_hold_mutex_x

                  FROM v$session_wait

                 WHERE event LIKE 'cursor%') a

         WHERE s.HASH_VALUE = a.p1) b

 WHERE se.sid = b.sid AND se.sql_hash_value = sq.hash_value;

 

 

       通过监控发现两个session在执行相同的sql,他们在相同的cursor object上交互请求a shared mutex pin或者 an exclusive mutex pin 从而造成等待。

 

--监视sql reae区的cursor object reload情况

SYS@anqing2(rac2)>  select namespace ,reloads from v$librarycache;

 

NAMESPACE          RELOADS

--------------- ----------

SQL AREA            790805

TABLE/PROCEDURE     103713

BODY                    59

TRIGGER                 27

INDEX                94280

CLUSTER                 11

OBJECT                   0

PIPE                     0

JAVA SOURCE              0

JAVA RESOURCE            0

JAVA DATA                0

 

11 rows selected.

 

--监视parse情况

SYS@anqing2(rac2)> col name format a40

SYS@anqing2(rac2)> select s.sid, s.serial#,b.name,a.value

  2   from v$sesstat a, v$statname b, v$session s

  3   where a.statistic# = b.statistic# and s.sid=a.sid

  4   and b.name like '%parse%'

  5   and s.sid in (130,125);

 

sid    serial# name                         value

---------- ---------- ---------------------------------------- ----------

125      41915 parse time cpu                115260

125      41915 parse time elapsed             146605

125      41915 parse count (total)             633792

125      41915 parse count (hard)             602732

125      41915 parse count (failures)           4

130       6074 parse time cpu                69559

130       6074 parse time elapsed              99149

130       6074 parse count (total)              394689

130       6074 parse count (hard)               365538

130       6074 parse count (failures)             0

 

从这里看出,硬解析很多,library cache中的cursor object被频繁的reload

 

 

. 几个与mutex 相关的视图

       在第一部分,提到了x$mutex_sleep x$mutex_sleep_history。我们在联机文档里看不到相关的说明。

 

       不过可以查看到v$mutex_sleep  v$mutex_sleep_history的说明。 但是v$ x$ 字典显示的列要少。

 

select * from x$mutex_sleep;

 

select * from v$mutex_sleep;

 

 

SYS@anqing2(rac2)> desc x$mutex_sleep_history

 Name                                      Null?    Type

 ----------------------------------------- -------- ----------------------------

 ADDR                                               RAW(4)

 INDX                                               NUMBER

 INST_ID                                            NUMBER

 MUTEX_ADDR                                         RAW(4)

 MUTEX_IDENTIFIER                                   NUMBER

 SLEEP_TIMESTAMP                                    TIMESTAMP(6)

 MUTEX_TYPE                                         VARCHAR2(32)

 MUTEX_TYPE_ID                                      NUMBER

 GETS                                               NUMBER

 SLEEPS                                             NUMBER

 REQUESTING_SESSION                                 NUMBER

 BLOCKING_SESSION                                   NUMBER

 LOCATION_ID                                        NUMBER

 LOCATION                                           VARCHAR2(40)

 MUTEX_VALUE                                        RAW(4)

 P1                                                 NUMBER

 P1RAW                                              RAW(4)

 P2                                                 NUMBER

 P3                                                 NUMBER

 P4                                                 NUMBER

 P5                                                 VARCHAR2(64)

 

SYS@anqing2(rac2)> desc v$mutex_sleep_history

 Name                                      Null?    Type

 ----------------------------------------- -------- ----------------------------

 MUTEX_IDENTIFIER                                   NUMBER

 SLEEP_TIMESTAMP                                    TIMESTAMP(6)

 MUTEX_TYPE                                         VARCHAR2(32)

 GETS                                               NUMBER

 SLEEPS                                             NUMBER

 REQUESTING_SESSION                                 NUMBER

 BLOCKING_SESSION                                   NUMBER

 LOCATION                                           VARCHAR2(40)

 MUTEX_VALUE                                        RAW(4)

 P1                                                 NUMBER

 P1RAW                                              RAW(4)

 P2                                                 NUMBER

 P3                                                 NUMBER

 P4                                                 NUMBER

 P5                                                 VARCHAR2(64)

 

 

 

 

 

 

-------------------------------------------------------------------------------------------------------

QQ:492913789

Email:ahdba@qq.com

Blog: http://www.cndba.cn/dave


DBA1 群:62697716();   DBA2 群:62697977()   DBA3 群:62697850()  

DBA 超级群:63306533();  DBA4 群: 83829929  DBA5群: 142216823   

DBA6 群:158654907  聊天 群:40132017   聊天2群:69087192

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

这篇关于Oracle cursor pin S wait on X 等待事件 说明的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/874619

相关文章

oracle 11g导入\导出(expdp impdp)之导入过程

《oracle11g导入导出(expdpimpdp)之导入过程》导出需使用SEC.DMP格式,无分号;建立expdir目录(E:/exp)并确保存在;导入在cmd下执行,需sys用户权限;若需修... 目录准备文件导入(impdp)1、建立directory2、导入语句 3、更改密码总结上一个环节,我们讲了

Redis中哨兵机制和集群的区别及说明

《Redis中哨兵机制和集群的区别及说明》Redis哨兵通过主从复制实现高可用,适用于中小规模数据;集群采用分布式分片,支持动态扩展,适合大规模数据,哨兵管理简单但扩展性弱,集群性能更强但架构复杂,根... 目录一、架构设计与节点角色1. 哨兵机制(Sentinel)2. 集群(Cluster)二、数据分片

Springboot项目构建时各种依赖详细介绍与依赖关系说明详解

《Springboot项目构建时各种依赖详细介绍与依赖关系说明详解》SpringBoot通过spring-boot-dependencies统一依赖版本管理,spring-boot-starter-w... 目录一、spring-boot-dependencies1.简介2. 内容概览3.核心内容结构4.

redis和redission分布式锁原理及区别说明

《redis和redission分布式锁原理及区别说明》文章对比了synchronized、乐观锁、Redis分布式锁及Redission锁的原理与区别,指出在集群环境下synchronized失效,... 目录Redis和redission分布式锁原理及区别1、有的同伴想到了synchronized关键字

MySQL 临时表创建与使用详细说明

《MySQL临时表创建与使用详细说明》MySQL临时表是存储在内存或磁盘的临时数据表,会话结束时自动销毁,适合存储中间计算结果或临时数据集,其名称以#开头(如#TempTable),本文给大家介绍M... 目录mysql 临时表详细说明1.定义2.核心特性3.创建与使用4.典型应用场景5.生命周期管理6.注

Java中数组与栈和堆之间的关系说明

《Java中数组与栈和堆之间的关系说明》文章讲解了Java数组的初始化方式、内存存储机制、引用传递特性及遍历、排序、拷贝技巧,强调引用数据类型方法调用时形参可能修改实参,但需注意引用指向单一对象的特性... 目录Java中数组与栈和堆的关系遍历数组接下来是一些编程小技巧总结Java中数组与栈和堆的关系关于

Oracle迁移PostgreSQL隐式类型转换配置指南

《Oracle迁移PostgreSQL隐式类型转换配置指南》Oracle迁移PostgreSQL时因类型差异易引发错误,需通过显式/隐式类型转换、转换关系管理及冲突处理解决,并配合验证测试确保数据一致... 目录一、问题背景二、解决方案1. 显式类型转换2. 隐式转换配置三、维护操作1. 转换关系管理2.

Oracle查询表结构建表语句索引等方式

《Oracle查询表结构建表语句索引等方式》使用USER_TAB_COLUMNS查询表结构可避免系统隐藏字段(如LISTUSER的CLOB与VARCHAR2同名字段),这些字段可能为dbms_lob.... 目录oracle查询表结构建表语句索引1.用“USER_TAB_COLUMNS”查询表结构2.用“a

Oracle数据库定时备份脚本方式(Linux)

《Oracle数据库定时备份脚本方式(Linux)》文章介绍Oracle数据库自动备份方案,包含主机备份传输与备机解压导入流程,强调需提前全量删除原库数据避免报错,并需配置无密传输、定时任务及验证脚本... 目录说明主机脚本备机上自动导库脚本整个自动备份oracle数据库的过程(建议全程用root用户)总结

mybatis-plus QueryWrapper中or,and的使用及说明

《mybatis-plusQueryWrapper中or,and的使用及说明》使用MyBatisPlusQueryWrapper时,因同时添加角色权限固定条件和多字段模糊查询导致数据异常展示,排查发... 目录QueryWrapper中or,and使用列表中还要同时模糊查询多个字段经过排查这就导致只要whe