High ‘latch: shared pool’ and ‘library cache: mutex X’ in Oracle 19c(19.13)

好久没有处理oracle的故障了,因为我的客户在oracle 升级19c后的数据库非常稳定,前几年随着X创推进,几乎oracle都被国产化替代了,刚好最近遇到了一个问题,有家医院客户,最近每隔几天早高峰会出现较高的’latch: shared pool’ 和’library cache: mutex X’,导致数据库节点hang, 等待函数 kghfrunp ,重启解决,如果发现的早做flush sharedpool也可以缓解。数据库版本19.13.

latch: shared pool 和 library cache: mutex X 本质上是shared pool的争用。

先看awr

DB NameDB IdUnique NameRoleEditionReleaseRACCDB
ORAxx1978474438oraxxPRIMARYEE19.0.0.0.0YESNO
InstanceInst NumStartup TimeUser NameSystem Data Visible
oraxx207-Jul-26 12:56SYSYES
Host NamePlatformCPUsCoresSocketsMemory (GB)
anbob2AIX-Based Systems (64-bit)16020 998.25
Snap IdSnap TimeSessionsCursors/SessionInstances
Begin Snap:15068609-Jul-26 09:30:4925072.12
End Snap:15068709-Jul-26 10:00:0526582.22
Elapsed: 29.26 (mins)   
DB Time: 8,964.26 (mins)   

Report Summary

Load Profile

Per SecondPer TransactionPer ExecPer Call
DB Time(s):306.33.90.140.08
DB CPU(s):4.30.10.000.00
Background CPU(s):0.30.00.000.00
Redo size (bytes):355,712.54,549.2  
Logical read (blocks):1,387,449.517,744.0  
Block changes:2,307.829.5  
Physical read (blocks):19,421.9248.4  
Physical write (blocks):3,675.847.0  
Read IO requests:8,090.6103.5  
Write IO requests:152.01.9  
Read IO (MB):151.71.9  
Write IO (MB):28.70.4  
IM scan rows:0.00.0  
Session Logical Read IM:0.00.0  
Global Cache blocks received:336.74.3  
Global Cache blocks served:251.93.2  
User calls:3,937.250.4  
Parses (SQL):1,304.916.7  
Hard parses (SQL):92.01.2  
SQL Work Area (MB):47.80.6  
Logons:9.50.1  
User logons:8.40.1  
Executes (SQL):2,198.128.1  
Rollbacks:2.80.0  
Transactions:78.2  

Top 10 Foreground Events by Total Wait Time

EventWaitsTotal Wait Time (sec)Avg Wait% DB timeWait Class
latch: shared pool173,268246.1K1420.50ms45.8Concurrency
library cache: mutex X91,00598.3K1080.17ms18.3Concurrency
DB CPU 7509.4 1.4 
latch: call allocation3,7017454.72014.24ms1.4Other
library cache load lock6,7955707.7839.98ms1.1Concurrency
db file sequential read8,768,7793400.3387.77us.6User I/O
row cache lock9,2582104.2227.28ms.4Concurrency
library cache: bucket mutex X16,7542048.5122.27ms.4Concurrency
gc buffer busy acquire3,043,4901971.6647.81us.4Cluster
row cache mutex300,15517515.83ms.3Concurrency

Host CPU

CPUsCoresSocketsLoad Average BeginLoad Average End%User%System%WIO%Idle
16020 9.6625.678.71.70.789.6

Instance CPU

%Total CPU%Busy CPU%DB time waiting for CPU (Resource Manager)
2.927.60.0

Note: 从上面可以发现数据库出现了非常高的性能负载问题,但是看sql parse和logon 并不高或导致这么严重问题的地步。并且主机的CPU使用率也并不高。

Latch Sleep Breakdown

  • ordered by misses desc
Latch NameGet RequestsMissesSleepsSpin Gets
cache buffers chains4,840,975,07311,165,535755,55710,476,003
shared pool52,028,140492,1244,714,323273,603
ges resource hash list124,844,804373,6966,911366,865

Latch Miss Sources

  • only latches with sleeps are shown
  • ordered by name, sleeps desc
Latch NameWhereNoWait MissesSleepsWaiter Sleeps
unknown latchkghfrunp: alloc: wait04,526,661526,884
unknown latchkghalo0116,9103,048,314
unknown latchkghfre025,182642,385
unknown latchkghalp016,261285,663
unknown latchkghfrunp: no latch015,8180
Note: 发现了一条标签为“unknown latch:kghfrunp:alloc:wait”的条目,其中包含最大睡眠计数。

kghfrunp==> kernel generic heap manager free unused space in a heap free unpinned space

kghalo==>kernel generic heap manager main allocation entry point

Mutex Sleep Summary

  • ordered by number of sleeps desc
Mutex TypeLocationSleepsWait Time (ms)
Library Cachekglhdgn2 1067,593,65572,536,578
Cursor Pinkkslce [KKSCHLPIN2]1,555,9511,598,425
Library Cachekgllkdl1 851,441,43413,616,083
Library Cachekgllkal1 80567,2195,332,435
Row Cache[19] kqrpre207,8891,175,250
kglhdgn ==> kernel generic library cache management object handle get new(?)

ASH

Top Event P1/P2/P3 Values

  • Top Events by DB Time and the top P1/P2/P3 values for those events.
  • % Event is the percentage of DB Time due to the event
  • % Activity is the percentage of DB Time due to the event with the given P1,P2,P3 Values.
Event% EventP1, P2, P3 Values% ActivityParameter 1Parameter 2Parameter 3
latch: shared pool52.20“504403158276130312”,”619″,”0″6.45addressnumberwhy
latch: shared pool“504403158276130152”,”619″,”0″6.33addressnumberwhy
latch: shared pool“504403158276129992”,”619″,”0″5.77addressnumberwhy
library cache: mutex X19.51“991821498”,”51586852192256″,”18446744069419106410″1.71idnvaluewhere
library cache: mutex X“1696937788”,”30769145708544″,”7288292302806581354″1.31idnvaluewhere
library cache: mutex X“991821498”,”6287832121344″,”18446744069419106410″1.07idnvaluewhere
latch: call allocation2.72“504403158265523224”,”24″,”0″0.95addressnumberwhy
row cache mutex1.84“10”,”19″,”0″0.84cache idwhere requestedNOT DEFINED
gc buffer busy acquire1.13“188”,”1561563″,”1″0.03file#block#class#

一个堵塞者可能会导致2种等待事件latch: shared pool 和library cache: mutex X, 看https://ksun-oracle.blogspot.com/2021/05/oracle-19c-new-shared-pool-so-private.html

latch: shared pool

查询v$session 可以blocking_session, 或查询V$LATCHHOLDER

library cache: mutex X的p1和p2值 找 library object和堵塞者。 如p1 p2 p3 “991821498”,”51586852192256″,”18446744069419106410″

select mutex_identifier, sleep_timestamp, mutex_type, gets, sleeps
                ,requesting_session, blocking_session, location
   from v$mutex_sleep_history
  where mutex_identifier in (991821498) and sleep_timestamp > sysdate-1/1440 and sleeps > 3
  order by sleep_timestamp desc, location;

-- waiters
 select chain_signature, sid, p1 
   from v$wait_chains where p1 in (991821498) or chain_signature = 'library cache: mutex X';

select 'BLOCKING_SESSION'   sess, program, event, mod(s.p1, power(2, 17)) "buckt muext(child_latch)", s.p1, s.p2, s.p3, s.sql_id, q.sql_text, m.*, s.*, q.*
from v$session s, v$mutex_sleep_history m, v$sqlarea q
where s.sid = m.blocking_session and s.sql_id = q.sql_id and m.sleep_timestamp > sysdate-5/1440 and m.sleeps > 3
union all
select 'REQUESTING_SESSION' sess, program, event, mod(s.p1, power(2, 17)) "buckt muext(child_latch)", s.p1, s.p2, s.p3, s.sql_id, q.sql_text, m.*, s.*, q.*
from v$session s, v$mutex_sleep_history m, v$sqlarea q
where s.sid = m.requesting_session and s.sql_id = q.sql_id and m.sleep_timestamp > sysdate-5/1440 and m.sleeps > 3;

-- find obj,  ADDR is its object_handle
 select hash_value, addr, owner, name, namespace, type from v$db_object_cache where hash_value in (991821498)

HASH_VALUE ADDR             OWNER                          NAME                                               NAMESPACE                     TYPE
---------- ---------------- ------------------------------ -------------------------------------------------- ----------------------------- ----------
 991821498 00000000FA5A4168                                RECO.ORACLE.COM                                    DBLINK                        CURSOR

-- find blocker
SQL> @dec 51586852192256

                                DEC                  HEX
----------------------------------- --------------------
              51586852192256.000000         2EEB00000000

SQL> @hex 2EEB

                                DEC                  HEX
----------------------------------- --------------------
                       12011.000000                 2EEB

LMHB trace 文件

Dumping process info for latch holder 34735110
(latch info) hold_bits=0x40 ud_influx=0x7e
  Waiting For:
    0x700000000a244c8 Child 'shared pool' (level=10, SGA latch, child#=2)
    Holder Location: kgh.h LINE:9698 ID:kghfrunp: alloc: wait: 
    Holder Context: 0
    Waiter Location: kgh.h LINE:9637 ID:kghfre: Chunk Header
...

Short stack dump: 
ksedsts()+512<-ksdxfstk()+68<-ksdxcb()+892<-sspuser()+240<-__sighandler()<-thread_wait()+556<-sskgpwwait()+56<-skgpwwait()+268<-IPRA.$kslges()+1480<-IPRA.$kslgetl_int()+2880<-kslgetl()+60<-ksfglt()+188<-IPRA.$kghfrunp()+3328<-IPRA.$kghfnd()+1476<-IPRA.$kghprmalo()+1404<-kghalo()+3892<-IPRA.$dbktbPoolBufAlloc()+256<-IPRA.$dbktbPoolBucketAddBuf()+60<-dbktbDefaultBucketAlloc()+224<-ksucrp()+1512<-opiino()+1428<-opiodr()+1256<-opidrv()+1080<-sou2o()+208<-opimai_real()+680<-ssthrdmain()+460<-main()+216<-__start()+112
Kernel stack:
...

Note: 在ash中也没看到特别突出的SQL

原因

这个库确实有较大的内存分配, shared pool几乎200GB(SGA 500G) 对于一家医院来说确实是不小的配置, 而且也查询了sharedpool只的内存区,基本上就是SQLA 与handle占用的,并不存在其他异常增加或内存溢出。

MOS有一个bug较为匹配

Bug 33225584 – Instance Slow or Hung With High Shared Pool Latch Contention With Waits/Sleeps in kghfrunp() and Possible ‘ORA-32701: Possible hangs up to hang ID= detected’

影响版本:

  • 19.14.0
  • 19.13.0
  • 19.12.0
  • 19.11.0
  • 19.10.0
  • 19.8.0
  • 19.5.0
  • 19.1.0
  • 12.2.0.1 (Base Release)

Note that this fix has been superseded by the fix in Bug:34220943

Symptoms Related To:

  • Hang (Involving Shared Resource)
  • Latch Contention
  • Shared Pool Affected
  • ORA-32701
  • Stack is likely to include kghfrunp

解决方法

安装对应的补丁 34220943 

— or

定期检查shared pool free, 定期触发flush sharedpool ,临时解决

Leave a Comment