cursor: pin s on x:
今天是2013-11-11,传说中的光棍节,呵呵。之前数据库出现过一次cursor:pin s on x等待事件,距上次出现该问题已经有10天了,但是一直也懒的去总结这个事件,今天就深入研究一下:
第一:什么是cursor:pin s 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 objec(注意在10G之后library cache pin 被mutex取代)
也就是说当一个会话请求共享mutex pin的时候,另一个会话正好在同一个游标对象上持有排他pin。
第二 :cursor:pin s on x参数?
查看该会话参数如下:
p1 = the mutex Id
This has the same definition as v$mutex_sleep_history.mutex_identifier
p2raw = holding Session Id | Ref Count
The most significant bytes always store the Holding Session Id (Holding SId).
The least significant bytes always store the Ref Count.
64 bit platforms
8 bytes are used.
Top 4 bytes hold the session id (if the mutex is held X)
Bottom 4 bytes hold the ref count (if the mutex is held S).
32 bit platforms
4 bytes are used.
Top 2 bytes hold the session id (if the mutex is held X)
Bottom 2 bytes hold the ref count (if the mutex is held S).
P3 Mutex where (an internal code locator) OR'd with Mutex Sleeps
第三:产生该等待事件的原因:
1)频繁的硬解析
简言之,shared pool 中的library cache 存放sql语句、解析树、执行计划等信息,它被free list buckets组成,每个bucket都有library cache object handle,每个handle又连接了其他的handle,在library cache handle中指向library cache object (heap 0),当我们执行一条 语句的时候首先查看该语句是否被执行过,通过计算执行sql的hash 值与library cache中的heap 0的hash值进行比较,如果一样则说明该sql只需要进行软解析,如果没有hash值,那么就需要进行英解析,在进行解析的时候需要获得library cache object handle的lock,在对对象进行解析的时候需要pin住该对象也就是library cache pin ,如果这是时候又有很多的会话需要获得该对象的s,那么其他会话就必须进行等待。在10G中library cache pin 被 mutex取代了。
假如在某一个时间数据库突然存在很多英解析,那么首先要看的就是相关对象是否统计信息存在问题,从而影响了执行计划。
如何知道哪些sql进行了频繁的英解析,方式有很多中,可以通过addm进行诊断,可以通过ash结合awr进行诊断,获得sql之后可以更具dbms_sqltune进行相关问题的调优,还可以通过v$sql 和 v$session进行结合获得该等待事件对应的sql信息。另外还可以通过oradebug设置 oradebug dump systemstate 266进行诊断。
另外我们可以通过x$mutex_sleep视图获得相关hang住的详细信息.
如下是一个案例:
查看数据库dbtime明显负载过重:
SQL> select a.sid,a.serial#,a.username,b.name,c.value from v$session a,v$statname b,v$sesstat c
2 where a.sid=c.sid and b.statistic#=c.statistic# and name like '%parse%' and a.sid=&sid;
Enter value for sid: 1
old 2: where a.sid=c.sid and b.statistic#=c.statistic# and name like '%parse%' and a.sid=&sid
new 2: where a.sid=c.sid and b.statistic#=c.statistic# and name like '%parse%' and a.sid=1
SID SERIAL# USERNAME NAME VALUE
---------- ---------- ------------------------------ ---------------------------------------------------------------- ----------
1 5 SYS ADG parselock X get attempts 0
1 5 SYS ADG parselock X get successes 0
1 5 SYS parse time cpu 79
1 5 SYS parse time elapsed 432
1 5 SYS parse count (total) 947
1 5 SYS parse count (hard) 486
1 5 SYS parse count (failures) 1
1 5 SYS parse count (describe) 0