最近学习Oracle Library cache内部机制时,参考了如下帖子:
http://blog.csdn.net/tianlesoftware/article/details/6629869
但是本人使用的是11.2.0.3的版本,具体如下:
操作系统:Oracle Linux 5.7 64bit
Oracle版本:11.2.0.3 RAC
发现在DUMP出来的library cache结构与帖子中介绍的不太一样,帖子中没有提到版本,现在把自己在学习过程中的一些心得整理下来备忘,希望大家一起探讨:
1.数据库中两个用户分别为:SCOTT、HFF
两个用户下都有一个T表
2.清空共享池:alter system flush shared_pool;
3.两个用户分别执行:select * from t;
4.SCOTT用户DUMP出library cache:
alter session set events 'immediate trace name library_cache level 10';
--更新--
后来经过学习发现不太一样的地方可以也是由于DUMP级别不够,信息不全导致了一部分不一样,Heap 6还是有的。
使用alter session set events 'immediate trace name library_cache level 16';或32导出。
5.SCOTT用户查找trace文件:
select * from v$diag_info;
6.vi该trace文件,搜索select \* from t
注:这里要把*使用\进行转译,否则直接搜select * from t搜不到
7.trace文件的内容,跟之前帖子中的介绍有了较多的变化,分析可能是11g变动大,导致一些数据结构改变:
Bucket: #=16419 Mutex=0x93611290(0, 39, 0, 6)
LibraryHandle: Address=0x900ea8a0 Hash=43984023 LockMode=N PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=select * from t
FullHashValue=3f66bd30d280fb7284ca64b443984023 Namespace=SQL AREA(00) Type=CURSOR(00) Identifier=1134051363 OwnerIdn=83
Statistics: InvalidationCount=0 ExecutionCount=2 LoadCount=3 ActiveLocks=5 TotalLockCount=6 TotalPinCount=1
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=2 BucketInUse=5 HandleInUse=5 HandleReferenceCount=0
Concurrency: DependencyMutex=0x900ea950(0, 2, 0, 0) Mutex=0x900ea9d0(155, 43, 0, 6)
Flags=RON/PIN/TIM/PN0/DBN/[10012841]
WaitersLists:
Lock=0x900ea930[0x900ea930,0x900ea930]
Pin=0x900ea910[0x900ea910,0x900ea910]
LoadLock=0x900ea988[0x900ea988,0x900ea988]
Timestamp: Current=01-08-2014 14:57:17
HandleReference: Address=0x900eaa48 Handle=(nil) Flags=[00]
ReferenceList:
Reference: Address=0x8e5b0f80 Handle=0x8ae96948 Flags=ROD[21]
Reference: Address=0x8f975298 Handle=0x9025a950 Flags=ROD[21]
LibraryObject: Address=0x8f976f88 HeapMask=0000-0001-0001-0000 Flags=EXS[0000] Flags2=[0000] PublicFlags=[0000]
DataBlocks:
Block: #='0' name=KGLH0^43984023 pins=0 Change=NONE
Heap=0x9025d8e8 Pointer=0x8f977028 Extent=0x8f976f08 Flags=I/-/P/A/-/-
FreedLocation=0 Alloc=3.250000 Size=3.976562 LoadTime=4300309640
ChildTable: size='16'
Child: id='0' Table=0x8f977e38 Reference=0x8f977878 Handle=0x8f0e3058
Child: id='1' Table=0x8f977e38 Reference=0x8f977bb0 Handle=0x8e9ef0a8
NamespaceDump:
Parent Cursor: sql_id=89km4qj1thh13 parent=0x8f977028 maxchild=2 plk=y ppn=n
CursorDiagnosticsNodes:
ChildNode: ChildNumber=0 ID=37 reason=Authorization Check failed(4) size=5x4 translation_table_position=0 original_handle=2418990504 temp_handle=2367580488 schema=119 synonym_object_number=0
8.在之前的帖子中介绍的ChildTable(子游标),根据子游标的Handle来查看Heap 6(用于存放执行计划)
但是查找到的信息跟之前的不一样了,查找到的内容都没有了Heap 6的信息(后来发现是LEVEL 10级别低,使用16后就有Heap 6的信息了),内容如下:
根据Child: id='0' Table=0x8f977e38 Reference=0x8f977878 Handle=0x8f0e3058里的Handle查找:
第一个查找到的是如下内容,发现是SCOTT用户对象:
Bucket: #=108417 Mutex=0x943dbd58(0, 15, 0, 6)
LibraryHandle: Address=0x8eb6b4e8 Hash=de8ba781 LockMode=S PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=SCOTT
FullHashValue=b57d9e745d1d0f49e0530388de8ba781 Namespace=SCHEMA(73) Type=NONE(255) Identifier=83 OwnerIdn=1
Statistics: InvalidationCount=0 ExecutionCount=0 LoadCount=0 ActiveLocks=1 TotalLockCount=6 TotalPinCount=0
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=0 BucketInUse=4 HandleInUse=4 HandleReferenceCount=0
Concurrency: DependencyMutex=0x8eb6b598(0, 8, 0, 0) Mutex=0x8eb6b618(155, 30, 0, 6)
Flags=PIN/TIM/[00002801]
WaitersLists:
Lock=0x8eb6b578[0x8eb6b578,0x8eb6b578]
Pin=0x8eb6b558[0x8eb6b558,0x8eb6b558]
LoadLock=0x8eb6b5d0[0x8eb6b5d0,0x8eb6b5d0]
Timestamp: Current=NULL
LockInstance: id='VVb57d9e745d1d0f49' GlobalEnqueue=(nil) ReleaseCount=0
PinInstance: id='YVb57d9e745d1d0f49' GlobalEnqueue=(nil)
ReferenceList:
Reference: Address=0x8d1e6b08 Handle=0x8d1e6948 Flags=OWN[200] -后来发现这个Handle是SCOTT.T对象的地址
Reference: Address=0x8f976518 Handle=0x8f0e3058 Flags=DEP[01] -0x8f0e3058
Timestamp=NULL InvalidatedFrom=0
第二个查找到的内容为如下,发现是SCOTT.T对象:
LibraryHandle: Address=0x8d1e6948 Hash=bee9cfac LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=SCOTT.T
FullHashValue=452aa1534462ad37d471937dbee9cfac Namespace=TABLE/PROCEDURE(01) Type=TABLE(02) Identifier=76880 OwnerIdn=83
Statistics: InvalidationCount=0 ExecutionCount=0 LoadCount=1 ActiveLocks=0 TotalLockCount=5 TotalPinCount=5
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=0 BucketInUse=0 HandleInUse=0 HandleReferenceCount=0
Concurrency: DependencyMutex=0x8d1e69f8(0, 1, 0, 0) Mutex=0x8d1e6a78(155, 68, 1, 6)
Flags=PIN/TIM/[00002801]
WaitersLists:
Lock=0x8d1e69d8[0x8d1e69d8,0x8d1e69d8]
Pin=0x8d1e69b8[0x8d1e69b8,0x8d1e69b8]
LoadLock=0x8d1e6a30[0x8d1e6a30,0x8d1e6a30]
Timestamp: Current=07-12-2013 18:54:47
HandleReference: Address=0x8d1e6b08 Handle=0x8eb6b4e8 Flags=OWN[200]
LockInstance: id='LB452aa1534462ad37' GlobalEnqueue=(nil) ReleaseCount=0
PinInstance: id='NB452aa1534462ad37' GlobalEnqueue=(nil)
ReferenceList:
Reference: Address=0x8f9765b8 Handle=0x8f0e3058 Flags=DEP[01]
Timestamp=07-12-2013 18:54:47 InvalidatedFrom=0
LibraryObject: Address=0x90b710b0 HeapMask=0000-0701-0701-0000 Flags=EXS/LOC[0004] Flags2=[0000] PublicFlags=[0000]
DataBlocks:
Block: #='0' name=KGLH0^bee9cfac pins=0 Change=NONE
Heap=0x902cac08 Pointer=0x90b71150 Extent=0x90b71030 Flags=I/-/-/A/-/-
FreedLocation=0 Alloc=1.265625 Size=3.976562 LoadTime=4300309650
Block: #='8' name=KGLS^bee9cfac pins=0 Change=NONE
Heap=0x90b71368 Pointer=0x889fc2e0 Extent=0x889fb520 Flags=I/-/-/A/-/-
FreedLocation=0 Alloc=2.875000 Size=4.000000 LoadTime=4300309650
Block: #='9' name=KGLS^bee9cfac pins=0 Change=NONE
Heap=0x90b71490 Pointer=0x889fb350 Extent=0x889fa520 Flags=I/-/-/A/-/-
FreedLocation=0 Alloc=0.429688 Size=4.000000 LoadTime=4300309650
Block: #='10' name=KGLS^bee9cfac pins=0 Change=NONE
Heap=0x90b71518 Pointer=0x889fa430 Extent=0x889f9520 Flags=I/-/-/A/-/-
FreedLocation=0 Alloc=0.210938 Size=4.000000 LoadTime=4300309650
第三个查找到的内容为如下,其实这应该就是包含执行计划的Handle了:
Bucket: #=6635 Mutex=0x935b19d0(0, 25, 0, 6)
LibraryHandle: Address=0x9025a950 Hash=742019eb LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=3f66bd30d280fb7284ca64b443984023 Child:0
FullHashValue=4ce0bac038dca88ea6c42fec742019eb Namespace=SQL AREA STATS(75) Type=CURSOR STATS(102) Identifier=1948260843 OwnerIdn=83
Statistics: InvalidationCount=0 ExecutionCount=0 LoadCount=1 ActiveLocks=0 TotalLockCount=1 TotalPinCount=1
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=1 BucketInUse=0 HandleInUse=0 HandleReferenceCount=0
Concurrency: DependencyMutex=0x9025aa00(0, 1, 0, 0) Mutex=0x9025aa80(155, 9, 0, 6)
Flags=RON/PIN/TIM/KEP/KPR/[00012805]
WaitersLists:
Lock=0x9025a9e0[0x9025a9e0,0x9025a9e0]
Pin=0x9025a9c0[0x9025a9c0,0x9025a9c0]
LoadLock=0x9025aa38[0x9025aa38,0x9025aa38]
Timestamp: Current=01-08-2014 14:57:17
ReferenceList:
Reference: Address=0x8f976418 Handle=0x8f0e3058 Flags=ROD/KPP[61]
LibraryObject: Address=0x8f974f88 HeapMask=0001-0001-0001-0000 Flags=EXS[0000] Flags2=[0000] PublicFlags=[0000]
ReadOnlyDependencies: count='1' size='16'
ReadDependency: num='0' Table=0x8f975e58 Reference=0x8f975298 Handle=0x900ea8a0 Flags=DEP/ROD[21]
DataBlocks:
Block: #='0' name=KGLH0^742019eb pins=0 Change=NONE
Heap=0x9025a898 Pointer=0x8f975028 Extent=0x8f974f08 Flags=I/-/P/A/-/-
FreedLocation=0 Alloc=0.960938 Size=3.976562 LoadTime=4300309650
NamespaceDump:
STATS: phd=0x900ea8a0 chd=0x8f0e3058 planhsh=b5cd3b57 flg=0 Parse Count=5 Disk Reads=746 Disk Writes=0 Physical read requests=156 Physical read bytes=5062656 Physical write requests=0 Physical write bytes=0 IO Interconnect bytes=5062656 Buffer Gets=1189 Rows Processed=18586 Serializable Aborts=0 Fetches=1240 Execution count=1 PX Server Execution Count=0 Full Execution Count=0 CPU time=113986 Elapsed time=1809291 Avg Hard Parse Time=11790 Application time=0 Concurrency time=368529 Cluster/RAC time=0 User I/O time=1214421 Plsql Interpretor time=0 JVM time=0 Sorts=0
注:第二个子游标的Handle查找出来的内容差不多,不贴出来了。
9.其实我发现还可以根据第7步中的
FullHashValue=3f66bd30d280fb7284ca64b443984023 的 3f66bd30d280fb7284ca64b443984023 值进行查找
或者根据第7步中的如下内容中的Handle来查找执行计划的存储位置:
ReferenceList:
Reference: Address=0x8e5b0f80 Handle=0x8ae96948 Flags=ROD[21]
Reference: Address=0x8f975298 Handle=0x9025a950 Flags=ROD[21]
10.根据0x9025a950查找,会找到第8步中的第三个查找到的内容:
Bucket: #=6635 Mutex=0x935b19d0(0, 25, 0, 6)
LibraryHandle: Address=0x9025a950 Hash=742019eb LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=3f66bd30d280fb7284ca64b443984023 Child:0
FullHashValue=4ce0bac038dca88ea6c42fec742019eb Namespace=SQL AREA STATS(75) Type=CURSOR STATS(102) Identifier=1948260843 OwnerIdn=83
Statistics: InvalidationCount=0 ExecutionCount=0 LoadCount=1 ActiveLocks=0 TotalLockCount=1 TotalPinCount=1
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=1 BucketInUse=0 HandleInUse=0 HandleReferenceCount=0
Concurrency: DependencyMutex=0x9025aa00(0, 1, 0, 0) Mutex=0x9025aa80(155, 9, 0, 6)
Flags=RON/PIN/TIM/KEP/KPR/[00012805]
WaitersLists:
Lock=0x9025a9e0[0x9025a9e0,0x9025a9e0]
Pin=0x9025a9c0[0x9025a9c0,0x9025a9c0]
LoadLock=0x9025aa38[0x9025aa38,0x9025aa38]
Timestamp: Current=01-08-2014 14:57:17
ReferenceList:
Reference: Address=0x8f976418 Handle=0x8f0e3058 Flags=ROD/KPP[61]
LibraryObject: Address=0x8f974f88 HeapMask=0001-0001-0001-0000 Flags=EXS[0000] Flags2=[0000] PublicFlags=[0000]
ReadOnlyDependencies: count='1' size='16'
ReadDependency: num='0' Table=0x8f975e58 Reference=0x8f975298 Handle=0x900ea8a0 Flags=DEP/ROD[21]
DataBlocks:
Block: #='0' name=KGLH0^742019eb pins=0 Change=NONE
Heap=0x9025a898 Pointer=0x8f975028 Extent=0x8f974f08 Flags=I/-/P/A/-/-
FreedLocation=0 Alloc=0.960938 Size=3.976562 LoadTime=4300309650
NamespaceDump:
STATS: phd=0x900ea8a0 chd=0x8f0e3058 planhsh=b5cd3b57 flg=0 Parse Count=5 Disk Reads=746 Disk Writes=0 Physical read requests=156 Physical read bytes=5062656 Physical write requests=0 Physical write bytes=0 IO Interconnect bytes=5062656 Buffer Gets=1189 Rows Processed=18586 Serializable Aborts=0 Fetches=1240 Execution count=1 PX Server Execution Count=0 Full Execution Count=0 CPU time=113986 Elapsed time=1809291 Avg Hard Parse Time=11790 Application time=0 Concurrency time=368529 Cluster/RAC time=0 User I/O time=1214421 Plsql Interpretor time=0 JVM time=0 Sorts=0
根据0x8ae96948查找,内容如下:
Bucket: #=44702 Mutex=0x937255c8(0, 10, 0, 6)
LibraryHandle: Address=0x8ae96948 Hash=c6b8ae9e LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=3f66bd30d280fb7284ca64b443984023 Child:1
FullHashValue=162af46dfbcd2f30c7026b4cc6b8ae9e Namespace=SQL AREA STATS(75) Type=CURSOR STATS(102) Identifier=3333992094 OwnerIdn=119
Statistics: InvalidationCount=0 ExecutionCount=0 LoadCount=1 ActiveLocks=0 TotalLockCount=1 TotalPinCount=1
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=1 BucketInUse=0 HandleInUse=0 HandleReferenceCount=0
Concurrency: DependencyMutex=0x8ae969f8(0, 1, 0, 0) Mutex=0x8ae96a78(155, 9, 0, 6)
Flags=RON/PIN/TIM/KEP/KPR/[00012805]
WaitersLists:
Lock=0x8ae969d8[0x8ae969d8,0x8ae969d8]
Pin=0x8ae969b8[0x8ae969b8,0x8ae969b8]
LoadLock=0x8ae96a30[0x8ae96a30,0x8ae96a30]
Timestamp: Current=01-08-2014 14:57:34
ReferenceList:
Reference: Address=0x8e5b2100 Handle=0x8e9ef0a8 Flags=ROD/KPP[61]
LibraryObject: Address=0x8e5b0c70 HeapMask=0001-0001-0001-0000 Flags=EXS[0000] Flags2=[0000] PublicFlags=[0000]
ReadOnlyDependencies: count='1' size='16'
ReadDependency: num='0' Table=0x8e5b1b40 Reference=0x8e5b0f80 Handle=0x900ea8a0 Flags=DEP/ROD[21]
DataBlocks:
Block: #='0' name=KGLH0^c6b8ae9e pins=0 Change=NONE
Heap=0x9037e5c0 Pointer=0x8e5b0d10 Extent=0x8e5b0bf0 Flags=I/-/P/A/-/-
FreedLocation=0 Alloc=0.960938 Size=3.976562 LoadTime=4300326290
NamespaceDump:
STATS: phd=0x900ea8a0 chd=0x8e9ef0a8 planhsh=5f705349 flg=0 Parse Count=1 Disk Reads=1 Disk Writes=0 Physical read requests=1 Physical read bytes=8192 Physical write requests=0 Physical write bytes=0 IO Interconnect bytes=8192 Buffer Gets=267 Rows Processed=2000 Serializable Aborts=0 Fetches=135 Execution count=1 PX Server Execution Count=0 Full Execution Count=1 CPU time=11998 Elapsed time=69920 Avg Hard Parse Time=62222 Application time=0 Concurrency time=6707 Cluster/RAC time=0 User I/O time=47093 Plsql Interpretor time=0 JVM time=0 Sorts=0
11.这两段内容的共同点是ObjectName: Name=3f66bd30d280fb7284ca64b443984023,
与之前的FullHashValue=3f66bd30d280fb7284ca64b443984023值是一样的,
但是里面的DataBlocks:里只有Block: #='0'(Heap 0)堆的地址
12.从网上搜11g的DSI也没有泄露的,在此备忘,希望大家一起讨论。
13.经过后来自己的重新测试,发现是导出级别不够导致没有Heap 6的信息,后来又做了一次实验,如下:
使用16级DUMP:alter session set events 'immediate trace name library_cache level 16';
导出内容如下:
Bucket: #=33080 Mutex=0x936b3dd8(0, 19, 0, 6)
LibraryHandle: Address=0x902bec20 Hash=a4b28138 LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=select count(*) from t
FullHashValue=10bef657c8a7ea0dcf7ff45fa4b28138 Namespace=SQL AREA(00) Type=CURSOR(00) Identifier=2763161912 OwnerIdn=119
Statistics: InvalidationCount=0 ExecutionCount=2 LoadCount=2 ActiveLocks=0 TotalLockCount=2 TotalPinCount=1
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=1 BucketInUse=1 HandleInUse=1 HandleReferenceCount=0
Concurrency: DependencyMutex=0x902becd0(0, 1, 0, 0) Mutex=0x902bed50(159, 28, 0, 6)
Flags=RON/PIN/TIM/PN0/DBN/[10012841]
WaitersLists:
Lock=0x902becb0[0x902becb0,0x902becb0]
Pin=0x902bec90[0x902bec90,0x902bec90]
LoadLock=0x902bed08[0x902bed08,0x902bed08]
Timestamp: Current=01-08-2014 17:08:37
HandleReference: Address=0x902bedd0 Handle=(nil) Flags=[00]
ReferenceList:
Reference: Address=0x90b773c0 Handle=0x901a1098 Flags=ROD[21]
LibraryObject: Address=0x90b6e0b0 HeapMask=0000-0001-0001-0000 Flags=EXS[0000] Flags2=[0000] PublicFlags=[0000]
DataBlocks:
Block: #='0' name=KGLH0^a4b28138 pins=0 Change=NONE
Heap=0x90385f38 Pointer=0x90b6e150 Extent=0x90b6e030 Flags=I/-/P/A/-/-
FreedLocation=0 Alloc=2.437500 Size=3.976562 LoadTime=4308188630
ChildTable: size='16'
Child: id='0' Table=0x90b6ef60 Reference=0x90b6e9a0 Handle=0x902fd880
Children:
Child: childNum='0'
LibraryHandle: Address=0x902fd880 Hash=0 LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
Name: Namespace=SQL AREA(00) Type=CURSOR(00)
Statistics: InvalidationCount=0 ExecutionCount=2 LoadCount=1 ActiveLocks=0 TotalLockCount=2 TotalPinCount=3
Counters: BrokenCount=1 RevocablePointer=1 KeepDependency=0 BucketInUse=0 HandleInUse=0 HandleReferenceCount=0
Concurrency: DependencyMutex=0x902fd930(0, 0, 0, 0) Mutex=0x902bed50(159, 28, 0, 6)
Flags=RON/PIN/PN0/EXP/CHD/[10012111]
WaitersLists:
Lock=0x902fd910[0x902fd910,0x902fd910]
Pin=0x902fd8f0[0x902fd8f0,0x902fd8f0]
LoadLock=0x902fd968[0x902fd968,0x902fd968]
ReferenceList:
Reference: Address=0x90b6e9a0 Handle=0x902bec20 Flags=CHL[02]
LibraryObject: Address=0x90b780b0 HeapMask=0000-0001-0001-0000 Flags=EXS[0000] Flags2=[0000] PublicFlags=[0000]
Dependencies: count='2' size='16' table='0x90b78ee8'
Dependency: num='0'
Reference=0x90b78640 Position=0 Flags=DEP[0001]
Handle=0x8f0e31b8 Type=NONE(255) Parent=HFF
Dependency: num='1'
Reference=0x90b786d8 Position=21 Flags=DEP[0001]
Handle=0x9025edb0 Type=TABLE(02) Parent=HFF.T
ReadOnlyDependencies: count='1' size='16'
ReadDependency: num='0' Table=0x90b78f80 Reference=0x90b78540 Handle=0x901a1098 Flags=DEP/ROD/KPP[61]
Authorizations: count='1' size='16' entryeize='16'
Accesses: count='1' size='16'
Dependency: num='1' Type=0009
Translations: count='1' size='16'
Translation: num='0' Original=0x9025edb0 Final=0x9025edb0
DataBlocks:
Block: #='0' name=KGLH0^a4b28138 pins=0 Change=NONE
Heap=0x90215c20 Pointer=0x90b78150 Extent=0x90b78030 Flags=I/-/-/A/-/-
FreedLocation=0 Alloc=2.546875 Size=3.976562 LoadTime=4308188630
Block: #='6' name=SQLA^a4b28138 pins=0 Change=NONE
Heap=0x90b6e770 Pointer=0x8ceb5288 Extent=0x8ceb4630 Flags=I/-/-/A/-/E
FreedLocation=0 Alloc=5.617188 Size=7.898438 LoadTime=0
NamespaceDump:
Child Cursor: Heap0=0x90b78150 Heap6=0x8ceb5288 Heap0 Load Time=01-08-2014 17:08:37 Heap6 Load Time=01-08-2014 17:08:37
NamespaceDump:
Parent Cursor: sql_id=cyzznbykb509s parent=0x90b6e150 maxchild=1 plk=n ppn=n