Beruflich Dokumente
Kultur Dokumente
TABLE OF CONTENT
INTRODUCTION.........................................................................................................................................2
SHARED POOL OVERVIEW................................................................................................................2
TOOLS AVAILABLE TO COLLECT INFORMATION................................................................2
ORA-4031 CAUSED FROM THE APPLICATION SIDED........................................................2
DATABASE ISSUES CAUSING ERRORS ORA-4031.............................................................2
METHODOLOGY FOR THE DIAGNOSTIC...................................................................................2
CASE STUDIES..........................................................................................................................................2
CASE 1. 4358485.996........................................................................................................................2
CASE 2. 4413750.999........................................................................................................................2
CASE 3. TAR 4383850.996...............................................................................................................2
CASE 4. TAR 4417034.995..............................................................................................................2
CASE 5. TAR 4326100.996................................................................................................................2
1/40
INTRODUCTION
The error ora-4031 generates a high volume of service requests to Oracle Support. This document has been
created to provide a description of the essentials of this error, details about the method used to diagnose the
error, usage of tools and sqls available to collect information. The document contains different case studies
from service requests where the material of this document was applied.
Although this error is reported for a specific area, the shared pool, the cause of the problem could come from
distinct layers, plsql, streams, row cache, backup and recovery (RMAN), etc. This method will provide a
general approach that will collect the information required for the diagnostic and this is independent of the
layer involved.
2/40
Free Lists
Heap
Descriptor
The free list buckets is a structure of free lists and each list correspond to a specific size. Oracle does a
binary search on the free list sizes to find the appropriate free list. The first bucket that is greater or equal to
the requested size will be returned. We will continue to walk the free list until we find a bucket which points
to a large enough extent of memory.
To get a better idea, see this informatio created by the heap.awk tool, for the free list bucket summary:
Free List Bucket Summary :
Bucket 0 [size=32
] Count= 0
Bucket 1 [size=40
] Count= 443
Bucket 2 [size=48
] Count= 1850
Av.Size=
Av.Size=
Av.Size=
0.00 Max=
40.00 Max=
48.00 Max=
0
40
48
This shows that bucket 1 has 443 chunks of memory where the maximum size is 40bytes and the average is
40bytes. Bucket 2 is a free list of memory chunks with sizes between 40 and 48 bytes.
3/40
When the database is started, the free list buckes will show buckets with chunks of large sizes.
Fragmentation or lack of space will show buckets with smaller chunk sizes.
When a chunk of space is freed, it is added to the bucket whose size is less than or equal to the chunks size.
To allocate space:
Find a free list bucket pointing to a linked list of heaps of size requested or larger.
Search the list for best fit
If larger, use what is needed and return the rest
If none found, ask other modules to identify freeable subheaps until enough memory is found
If unsuccessful, signal ora-4031
If successful, reuse or create a new heap descriptor
This works similar to extent allocations within the tablespaces. We first look for best fit. If not found we
may break up a larger chunk into smaller pieces. If nothing is larger, we invoke other modules to identify
memory that is freeable. As we free a heap, we look at its neighbors. If one or both are also free, then we
coalesce. We see if enough memory is available. If not we loop through the process again.
Allocation classes
Memory within shared pool can be allocated as PERMANENT wich remains until parent heap is
freed and is most used for library cache objects. FREEABLE memory is memory that can be reused
and RECREATABLE, memory that if is flushed from the shared pool it can be rebuilt if necessary.
There is not a specific list of structures or elements that can be list as permanent, freeable or
recreatable. After following this document, it will be possible to identify which type of memory is
causing the error ora-4031 and track the module where the memory is allocated.
Error
Error ora-4031 basically has three main arguments, size requested, area and comment.
ORA-4031: unable to allocate <size requested> bytes of shared memory ("area ","comment)
ORA-4031: unable to allocate 2196 bytes of shared memory
("shared pool","JOB$","KGLS heap","KGLS MEM BLOCK")
ORA-4031: unable to allocate 656 bytes of shared memory
(shared pool","select user#,type# from user...","sql area","ctxdef : kkslod")
4/40
5/40
Events
A. Heapdump event
The heapdump event is used to dump memory from different subheaps. Errors ora-4030 are
associated with problems in the pga, uga or cga heaps, and error ora-4031 is related only to problems
with the shared pool or large pool.
To diagnose problems for error ora-4031, event heapdump level 2 is required. The event can be set
on the fly running command alter system set events 4031 trace name heapdump level 2
scope=memory; or it can be set in the parameter files events=4031 trace name heapdump, level 2.
Event heapdump can also be used to get the heapdump at any time attaching to a process using
oradebug:
SQL>oradebug setmypid
SQL>oradebug dump heapdump 2
SQL>oradebug tracefile_name
When dealing with error ora-4031 there is not required dumping other heaps like pga, top call or
current call, so do not use level 13, 3, etc.
Here is a list of all levels available for heapdump event.
HEAP
LEVEL
HEX
Top PGA
Top SGA
Top UGA
Current call
User call
Large Pool
DEC
0x01
0x02
0x04
0x08
0x10
0x20
1
2
4
8
16
32
6/40
WITH CONTENTS
HEX
DEC
0x401
1025
0x802
2050
0x1004
4100
0x2008
8200
0x4010
16400
0x8020
32800
38e0caf48 sz=
38e0cc790 sz=
38e0cdfd8 sz=
9/40
10/40
DESCRIPTION
The hash table used to store the free memory is divided in buckets. Each bucket
stores allocations of a particular size
Determines the size of the allocations stored in the bucket
Number of free chunks allocated in the bucket
Average size for each chunk allocated in the bucket
Maximum size of the chunk that will be find in the bucket
Table 2.2. Description of columns for the breakdown section
In the following list it can be observed that free memory is available in the first 9 buckets. The
maximum size is in bucket 9 with 104 bytes. There are 396 chunks which give around 40k of free
memory.
The value in section one for free memory was 1328584. Now using the information from section
three, it can be determined that this 1328584 bytes are distributed in very little chunks.
Free List Bucket Summary :
Bucket 0 [size=32
] Count= 0
Bucket 1 [size=40
] Count= 443
Bucket 2 [size=48
] Count= 1850
Bucket 3 [size=56
] Count= 2007
Bucket 4 [size=64
] Count= 588
Bucket 5 [size=72
] Count= 455
Bucket 6 [size=80
] Count= 556
Bucket 7 [size=88
] Count= 744
Bucket 8 [size=96
] Count= 625
Bucket 9 [size=104
] Count= 396
/* Some lines removed on porpouse */
Bucket 65 [size=552
] Count= 0
Bucket 66 [size=560 ] Count= 0
Bucket 67 [size=568 ] Count= 0
Bucket 68 [size=576 ] Count= 0
Bucket 69 [size=584 ] Count= 0
/* Continue until the last bucket.
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
0.00 Max=
40.00 Max=
48.00 Max=
56.00 Max=
64.00 Max=
72.00 Max=
80.00 Max=
88.00 Max=
96.00 Max=
104.00 Max=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
Av.Size=
0.00 Max=
0.00 Max=
0.00 Max=
0.00 Max=
0.00 Max=
0
40
48
56
64
72
80
88
96
104
0
0
0
0
0
When the system presents a similar image to the data referenced above, this is an indication that
system is running with few memory error ora-4031 is emminent. A system with a large amount of
free memory will display large values for the buckets on the bottom of the list.
11/40
12/40
13/40
COLUMN
UNBOUND_CURSOR
SQL_TYPE_MISMATCH
OPTIMIZER_MISMATCH
OUTLINE_MISMATCH
STATS_ROW_MISMATCH
LITERAL_MISMATCH
SEC_DEPTH_MISMATCH
EXPLAIN_PLAN_CURSOR
BUFFERED_DML_MISMATCH
PDML_ENV_MISMATCH
PDML
INST_DRTLD_MISMATCH
SLAVE_QC_MISMATCH
TYPECHECK_MISMATCH
AUTH_CHECK_MISMATCH
BIND_MISMATCH
DESCRIBE_MISMATCH
LANGUAGE_MISMATCH
TRANSLATION_MISMATCH
ROW_LEVEL_SEC_MISMATC
H
INSUFF_PRIVS
14/40
Grant/revoke command
Alter view
Alter package | procedure
Analyze table |index
Dbms_stats
Truncate table
Alter index
Alter table move
Direct effects of this situation will be an increase in the parsing calls but also will be a latch
contention for the library cache latch. If the invalidation/reloads cause fragmentation of the
shared pool, error ora-4031 will be reported.
The diagnostic
View v$librarycache is the first reference, particular the reloads and invalidation columns. This view
is used by statspack and the AWR repository in 10g. Also dumping the librarycache at level 1 will
dump output of this view.
DESCRIPTION
allocation comment that describes the type of allocation.
amount of contiguous memory being allocated. Values over around 5K
start to be a problem, values over 10K are a serious problem, and values over
20K are very serious problems. Anything less then 5K should not be a problem
number of objects that were flushed from the shared pool in order
allocate the memory
the name of the object being loaded into the shared pool if the
object is a PL/SQL object or a cursor.
This query will show the name of the object being loaded into the shared pool (KSMLRHON)
and how many objects were flushed out from the shared pool.
What to Do?
Objects causing a large number of other objects been flushed out from the shared pool are candidates
to be pinned into the shared pool using dbms_shared_pool.keep procedure.
The content of the view is recycled every time the object is consulted, either spool the content to a
file or store in a temporary table.
In the statspack reports or AWR reloads/invalidations can be found in the library cache section.
16/40
17/40
18/40
session parame
25
589700
23588
19/40
CHUNKCOMMENT Size
COUNT(*) STATUS
BYTES
sga heap(1,0)
sga heap(1,0)
sga heap(1,0)
free memory
free memory
free memory
1055
1
15
54012
2300
3193500
0-1K
2-3K
>10K
free
free
R-free
0
40
48
56
64
72
80
Every bucket shows the number of chunks, the average size and the maximum chunk size. Bucket 1
indicates stores chunks between 0 and 48 bytes and there are 443 of these chunks. On the other side,
buckets for large size of memory will have 0 chunks. A system running out of free memory will show a
similar report.
20/40
21/40
22/40
23/40
CASE STUDIES
CASE 1. 4358485.996
PROBLEM
Testing the upgrade to 9i of a pre-production database . Hundreds of errors ora-4031
Shared pool size = 500M
Multiple subpools (2)
After first errors ora-4031 shared pool was increased from 250m to 400m and finally to 500m
DIAGNOSTIC
There was not available a trace file created by error ora-4031. A heapdump level 2 was requested during
a period of high workload in order to analyze the distribution of space in the shared pool.
Running tool heap.awk using the trace file created by heapdump produce the following information:
Section One. General Space Allocation
---> HEAP DUMP heap name="sga heap(1,0)" desc=38002bd20
Type
Count
Sum
Average
-----------------------------------------------------------R-freeable
76
1003536
13204.42
R-perm
44
3258720
74061.82
R-free
132
57088752
432490.55
perm
36868 176831808
4796.35
recreate
3935 2491256
633.10
R-recreate
2
1368
684.00
---> HEAP DUMP heap name="sga heap(2,0)" desc=380034888
Type
Count
Sum
Average
------------------------------------------------------------------R-freeable
84
1134544
13506.48
R-perm
53
2483864
46865.36
R-free
150
54004784
360031.89
perm
36633 147482896
4025.96
freeable
29376 31449192
1070.57
recreate
17902 12335184
689.04
free
14594 17005384
1165.23
Notes:
24/40
25/40
26/40
27/40
14 N N N
Normally with cursor sharing problems view v$sql_shared_cursor is used and the cause of the problem
could be identified if columns after child_number column show value Y. Unfortunately in this case for
all the 2900 records returned all columns showed N.
The next step was identifying for a particular sql the application where it was called and set events 10046
and 10270.
oradebug setorapid <oracle process id>
oradebug event 10046 trace name context forever, level 12:
10270 trace name context forever, level 10
oradebug tracefile_name
The trace file created after setting the event showed that when using literals with a different column
datatype, the type convertion marked the bind variable as unsafe and that cause the generation of a child
cursor.
The cursor used was :
SELECT REO_DISBRMT_LNE_ITM.REO_DISBRMT_LNE_ITM_OID,
REO_DISBRMT_LNE_ITM.REO_DISBRMT_OID,
REO_DISBRMT_LNE_ITM.PD_AMT,
REO_DISBRMT_LNE_ITM.REO_DISBRMT_LN_ITM_TYP_CD,
REO_DISBRMT_LNE_ITM.RQSD_AMT
, REO_DISBRMT_LNE_ITM.AUD_VER, REO_DISBRMT_LNE_ITM.LAST_UPD_DT
FROM CLM.REO_DISBRMT_LNE_ITM
WHERE REO_DISBRMT_LNE_ITM.REO_DISBRMT_OID IN
(:"SYS_B_0",:"SYS_B_1",:"SYS_B_2",:"SYS_B_3")
END OF STMT
The bind variable was marked unsafe. See oacfl2=0x300. In this example dty=1 is NUMBER but check
the value between which is a literal.
BINDS #1:
bind 0: dty=1 mxl=32(01) mal=00 scl=00 pre=00 oacflg=10 oacfl2=0300 size=32 offset=0
bfp=ffffffff7bc7a838 bln=32 avl=01 flg=09
value="1"
28/40
29/40
30/40
RUNTIME
6/27/2005 1:46:49 PM
6/27/2005 1:46:49 PM
6/27/2005 1:46:49 PM
6/27/2005 1:46:49 PM
NODE
PS88PRD1
PS88PRD1
PS88PRD1
PS88PRD1
POOL
shared pool
shared pool
shared pool
shared pool
CONCLUSION
Running a search in WebIV (words 4031 ges enqueues rac) provide the following bug:
3046725 ORA-4031 - SHARED_POOL FRAGMENTED WITH HIGH GES RESOURCE
& ENQUEUES
2563301 ORA-4031 possible in RAC environment under load
Customer implemented workaround of bug 2563301 using parameter _lm_cache_res_cleanout=70 to
increse the amount of cache resource to be clean out in each attempt.
This problem was due to the initial implementation for the GES resource and GES enqueues allocations
(global resources) in RAC environments, which are allocated as permanent allocations. Permanent
allocations are only released when the instance is recycled.
The cached resource state objects could be built up overtime. It could consume a lot of shared
pool memory. Since state objects could not be freed back to shared pool once they are allocated, it
may use up more and more shared pool memory if the cached resources were not cleanup fast
enough.
31/40
32/40
33/40
]
]
]
]
]
]
]
]
Count= 47 Av.Size=
Count= 56 Av.Size=
Count= 80 Av.Size=
Count= 36 Av.Size=
Count= 53 Av.Size=
Count= 279 Av.Size=
Count= 1103 Av.Size=
Count= 706 Av.Size=
3853 Max=
3905 Max=
3950 Max=
4004 Max=
4068 Max=
4586 Max=
10652 Max=
20164 Max=
3872
3920
3968
4016
4112
8120
16384
27456
16400
cprm
where
4eb38e5b8 is the memory address in the shared pool
sz= 16400 is the amount of permanent memory allocated
cprm trace buffer is the comment
PERMANENT CHUNKS:
Chunk
perm
cprm
cprm
cprm
"perm
" alo=20616
"trace buffer "
"kgl lock hash t"
"kgllk hash tabl"
Now tool heap.awk will create a summary for the permanent chunks, which in this document has been
defined as section four: Breakdown of CPRM Chunks (Commented Perm Chunks)
34/40
20527
3460
3453
2808
5498
6606
86814312
56744000
14198736
11726208
22255904
74504416
4229.27
16400.00
4112.00
4176.00
4048.00
11278.29
For the library cache allocations there is not much to do as they are required for the normal functioning
of the database. Kglsim allocations are related with the library cache simulators, introduced in 9iR2.
There is around 33mb. Trace buffer is part of the new tracing facility and is consuming around 50mb.
These features can be disabled with the following parameters:
Statistic_level=basic. At this value will turn off all the simulators. _library_cache_advice = FALSE will
turn off library cache simulator only.
Trace_enabled=false. Turn off trace generation
35/40
This query will show in which range the free memory is distributed, initially in ranges of one (1)
kilobyte. This query can be used to identify if the shared pool has sufficient memory (large value for
the range > 10K) or if there is a small amount of memory (values displayed on the small ranges, like
1 2k.). The query includes the information for every subpool and also the free memory from the
reserved pool.
col SubPool format a15
select 'sga heap('||KSMCHIDX||',0)' Subpool,ksmchcom ChunkComment,
decode(round(ksmchsiz/1000),0,'0-1K', 1,'1-2K', 2,'2-3K',3,
'3-4K',4,'4-5K',5,'5-6k',6,'6-7k',7,'7-8k',8,'8-9k', 9,'9-10k','> 10K') Size Range,
count(*) Count,
ksmchcls Class , sum(ksmchsiz) Bytes
from x$ksmsp
where KSMCHCOM = 'free memory'
group by 'sga heap('||KSMCHIDX||',0)',ksmchcom, ksmchcls,
decode(round(ksmchsiz/1000),0,'0-1K', 1,'1-2K', 2,'2-3K', 3,
'3-4K',4,'4-5K',5,'5-6k',6,'6-7k',7,'7-8k',8,'8-9k', 9,'9-10k','> 10K')
order by ksmchcls;
Subpool
CHUNK
COMMENT Size
Count
Class
BYTES
-------------------------------------------------------------------------------------sga heap(1,0) free memory
> 10K
2
R-free
335720
sga heap(2,0) free memory
> 10K
1
R-free
167860
sga heap(1,0) free memory
> 10K
1
free
16110576
sga heap(2,0) free memory
0-1K
156
free
8524
sga heap(2,0) free memory
2-3K
1
free
1888
sga heap(2,0) free memory
> 10K
1
free
2000020
36/40
sga heap(2,0)
sga heap(2,0)
sga heap(2,0)
sga heap(2,0)
sga heap(2,0)
perm
recr
R-free
R-freea
freeabl
1
1
2
2600
Breakdown
The following query displays the memory allocated but this time using the comments stored in
the shared pool. This is same information displayed in section two on the report created by
heap.awk tool.
col SubPool format a15
select 'sga heap('||KSMCHIDX||',0)' "SubPool",ksmchcom contents, count(*)
chunks,sum(ksmchsiz) "Tot.Bytes",avg(ksmchsiz) "Avg.Bytes"
from sys.x$ksmsp where inst_id = userenv('Instance')
--and ksmchcls not like 'R%'
group by 'sga heap('||KSMCHIDX||',0)' ,ksmchcom
SubPool
CONTENTS
CHUNKS Tot.Bytes Avg.Bytes
-------------------------------------------------------------------------------------sga heap(1,0) KQR PO
347
177396
511.227666
sga heap(1,0) KGK heap
1
3268
3268
sga heap(1,0) joxs heap
1
92
92
sga heap(1,0) PX subheap
1
52472
52472
sga heap(1,0) free memory
3
16446296
5482098.67
sga heap(1,0) KGK contexts
2
2376
1188
sga heap(1,0) MS alert log
1
10252
10252
sga heap(2,0) KQR PO
413
178500
432.20339
sga heap(2,0) errors
12
10512
876
sga heap(2,0) KGK heap
1
560
60
sga heap(2,0) sql area
694
1527912
2201.60231
sga heap(2,0) KGLS heap
475 645916
1359.82316
sga heap(2,0) parameters
1
1072
1072
sga heap(2,0) KGL handles
743 268408
361.248991
sga heap(2,0) free memory
163
1952768
11980.1718
sga heap(2,0) PL/SQL DIANA
237 1453976
1915.51055
38/40
39/40
4358485.996
4413750.999
4383850.996
4417034.995
4326100.996
rem_ora_23985.trc
ps88prd2_lmd0_2115.trc
p20_dbw0_16403.trc
ssbp_ora_83509.trc
40/40