Académique Documents
Professionnel Documents
Culture Documents
http://www.insight-tec.com/en/mailmagazine/vol194.html
This dynamic SGA, as a new feature since Oracle 9i, allows changing the SGA configuration without
stopping the instance.
# The expansion and the shrinkage of buffer pool and SGA pool are executed by Oracle internal
management.
If the component takes memory, the internal automatic tuning will transmit memory from other
components.
Note: The buffer pool will be shrinked and the shared pool will be expanded.
# The SGA configuration memory parameters are organized and can be checked in the newly added
V$SGAINFO dynamic view. Granule size and other information are included in this view.
# Changes in SGA size are reflected synchronously in Oracle 9i but with some delay in Oracle 10g.
Therefore, a new flag value is defined in the dynamic view.
OPER_MODE:Operation mode
DISABLED (ADDED)
IMMEDIATE (ADDED)
AUTO (DELETED)
STATUS:Job-end status
INACTIVE (ADDED)
PENDING (ADDED)
COMPLETE (ADDED)
CANCELLED (ADDED)
NORMAL (DELETED)
CANCEL (DELETED)
Let's expand and shrink the memory dynamically. We will expand the shared pool, and the default buffer
pool will shrink or expand accordingly. In Oracle 10g, SGA_TARGET is also an important value as the
trigger of expansion or shrinkage.
Environment
Linux RAC10g1 2.4.9-e.40smp
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Prod
We can see the size of SGA by referring to the newly added dynamic view. One granule is 4MB in this
environment.
The time this process takes depends on the specified size. Let's confirm that the size is expanded.
NAME TYPE VALUE
------------------------------------ ----------- -----------
__shared_pool_size big integer 56M
shared_pool_size big integer 56M
__db_cache_size big integer 108M
The expansion size of shared pool is equal to the shrinkage size of default buffer cache.
Let's check the dynamic view that is related with SGA.
It is shown that
db_cache_size SHRINKS to 113246208 (108MB) and
shared_pool_size GROWS to 58720256 (56MB).
Note: FINAL_SIZE shows the final size.
START_TIME END_TIME
------------------- -------------------
2004/07/11 15:32:13 2004/07/11 15:32:13
2004/07/11 15:32:13 2004/07/11 15:32:13
Although it seems easy this time, sometimes it takes long for ALTER statement to get response after we
execute the same process several times. Be carefule when you want to apply it to the real system
We examined the expansion of the shared pool last week. Next, let's check how the shrinkage changes the
SGA component.
Environment
Linux RAC10g1 2.4.9-e.40smp
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Prod
Even if the shared pool parameter seems to be back, the buffer cache does not change. When will resizing
start?
NAME TYPE VALUE
------------------------------------ ----------- -----------
__shared_pool_size big integer 56M
shared_pool_size big integer 52M
__db_cache_size big integer 108M チ@<HERE!>
db_cache_size big integer 0
CURRENT_SIZE
------------
0
CURRENT_SIZE
------------
8388608
The result of resizing is shown in V$SGA_RESIZE_OPS. Default buffer cache is adjusted to 100MB
according to SGA_TARGET. Moreover, DEFERRED mode, which is not available in Oracle 9i, is
displayed now.
START_TIME END_TIME
------------------- -------------------
2004/07/11 15:35:23 2004/07/11 15:35:23
After a while...
In V$SGA_RESIZE_OPS, IMMEDIATE is shown, Java pool is expanded, and the default buffer pool
is shrinked from 100MB to 96MB.
START_TIME END_TIME
------------------- -------------------
2004/07/11 16:00:17 2004/07/11 16:00:17
2004/07/11 16:00:17 2004/07/11 16:00:17
As we have shown above, once SGA_TARGET parameter is changed, the optimal size will be determined
to fit the workload according to internal tuning algorithm. SGA component size will be changed
dynamically.
The shared pool, Java pool, large pool and default buffer cache work as source of memory; therefore,
whenever the system detects insufficiency of space after modifying the components automatically, the
expansion of the space will be executed automatically. Furthermore, the memory space will not move
among the components such as shared pool, Java pool and large pool.
Let's start the examination. In order to make the system recognize the insufficiency of shared pool size is
insufficient, we executed a lot of SQL statements to decrease the library cache hit rate. (After creating a
table, we execute a lot of SQL statements in PL/SQL without using any bind variable. This time we execute
3000 rows of insert statements.)
BEGIN
INSERT INTO TBL1(t1,t2,t3,t4) VALUES (i,(i*100),(i*100),(i*100));
INSERT INTO TBL1(t1,t2,t3,t4) VALUES (i,(i*100),(i*100),(i*101));
INSERT INTO TBL1(t1,t2,t3,t4) VALUES (i,(i*100),(i*100),(i*102));
チ@チ@チ idetails unwritten....チ j
END;
/
SQL>
select to_char(START_TIME,'YYYY/MM/DD HH24:MI:SS') as "ProcessTime",
COMPONENT as "Component",
OPER_TYPE as "Operation",
(FINAL_SIZE-INITIAL_SIZE)/1024/1024 as "Difference(MB)",
FINAL_SIZE/1024/1024 as "Size(MB)"
from V$SGA_RESIZE_OPS;
It looks like the memory space allocation to the shared pool is reflected and the space is always allocated
from buffer cache. The size increases or decreases by the unit of 4KB (1 granule).
SQL>
select to_char(START_TIME,'YYYY/MM/DD HH24:MI:SS') as "ProcessTime",
COMPONENT as "Component",
OPER_TYPE as "Operation",
(FINAL_SIZE-INITIAL_SIZE)/1024/1024 as "Difference(MB)",
FINAL_SIZE/1024/1024 as "Size(MB)"
from V$SGA_RESIZE_OPS;
We executed a lot of SQL statements to decrease the library cache hit rate. This is the result of shrinkage.
It does not work. It seems like the lower limit is taken as the stopper. The key point is the upper limit of
sga_target.
It worked well this time. Judging from the result of expansion, the size of default buffer cache has been
expanded. Due to the automatic modification, the lower limit of default buffer cache is always the upper
limit of sga_target (maximum sga_max_size).
Moreover, even if the size of default buffer cache is insufficient, the system does not shrink the shared
pool or other components to expand the default buffer cache.
We guess that
# when the size of buffer cache is insufficient, the status becomes standby and errors do not occur.
# insufficiency of shared pool or other components is a more serious problem than buffer cache standby.
Allocating space from the shared pool or other components might deteriorate the situation.
# when the size of shared pool, large pool and Java pool is insufficient,
ORA-4031(unable to allocate string bytes of shared memory) and
ORA-29554(Unhanded Java out of memory condition) occur and user processing will fail.
Review
We have confirmed a dynamic SGA action. When the size of shared pool, Java pool or large pool is
insufficient, the default buffer cache will shrink automatically;on the other hand, the shared pool, Java
pool and large pool will expand. Moreover, memory space will not be adjusted among these three
components. (shared pool, large pool, java pool)
After the sizes of components are modified automatically, will the space return back to the default buffer
cache? (1)shared pool-< default buffer cache (2) Java pool-< default buffer cache (3) large pool-<
default buffer cache.
Test 1
(1)Clear the shared pool. (alter system flush shared_pool)
(2)Confirm that the library cache hit rate is good.
(3)Decrease the buffer cache hit rate (In this examination, we lower it from 98% to 83%.)
select round(100
* ( ( max(decode(name,'db block gets',value))
+ max(decode(name,'consistent gets',value))
- max(decode(name,'physical reads',value)))
/ ( max(decode(name,'db block gets',value))
+ max(decode(name,'consistent gets',value)))),2) HIT_RATIO
from v$sysstat
/
HIT_RATIO
----------
83.01
The manual does not mention about the logic of the expansion of default buffer cache. In this case, is it
possible to alter it manually, then?
Test 2
Let's expand the default buffer cache manually.
shared pool (from 44MB to 40MB) * shrinked
default buffer cache (from 72MB to 76MB) *expanded
sga_target (from 128MB to 140MB: sga_max_size)
The sizes of SGA components have not change at all. It seems that default buffer cache cannot even be
executed manually. Moreover, we also failed to shrink the shared pool manually. (In this case, should we
take specifying "expansion" of shared pool as the trigger of recalculation?)
* In Oracle 9.2 , it is possible to shrink the shared pool manually.
We expand the shared pool since sga_target seems to have some more margin.
SQL> alter system set shared_pool_size=48M;
System changed.
The shared pool has been expanded. The remaining space in the sga_target range is allocated to default
buffer cache and recalculated. (from 72MB to 80MB) As a result, default buffer cache is also expanded.
Results
Although there is some ramaining space in the shared pool, Java pool and large pool and the space of
default buffer cache is insufficient, size change does not occur in dynamic SGA. Therefore, when the
application enters standby mode due to insufficient space of buffer cache, we cannot expect dynamic SGA
to solve this problem. If you really want to increase the size of default buffer cache, it is possible to
increase sga_target manually and modify the space of shared pool, Java pool and larege pool (when
sga_max_size>=sga_target). (The remaining space will be allocated to default buffer cache and the
difference may be more than the current default buffer cache.) It might be difficult to determine
automatically that there is remaining space in the shared pool, Java pooland large pool, but it is surprising
that it is also impossible to shrink the components manually.
There is still another case. When sga_target<=total size of SGA components, and an expansion error
occurrs after we execute alter system set db_cache_size="size to be expanded" (it is not surprising since
there is no remaining space in SGA), the following information is recorded in V$SGA_RESIZE_OPS
dynamic view.
It can be observed that we have tried to shrink the shared pool and expand the default buffer
cache(GROW). It means that such a kind of logic does exist.
Question
Dynamic SGA feature in Oracle Database 10g can allocate the space of default buffer cache to the
insufficient shared pool, Java pool and large pool. However, when and how does the system determine if
the shared pool, Java pool or large pool is insufficient? Let's focus on the shared pool to investigate the
timing and the value that is referred to.
We have introduced the processes shown above for the past few weeks. The fact that library cache hit rate
is low seems to be one of the indicator to determine shared pool should be expanded. However, we do not
know exactly how many percent is the threshold.
In order to investigate the threshold, let's check v$shared_pool_advice dynamic view. It includes the
information about the estimated analysis time of shared pool. (The history is kept in
dba_hist_shared_pool_advice.)
The number and interval of record depend on the size of shared pool.
(A) is the estimated size of shared pool. For the record whose estimated shared pool size matches the
current size, its size factor.
(B) will become 1. Other distribution records will be created according to that record. These are items
which have increased obviously.
(C) is the estimated occupied memory size in library cache;
(D) is the estimated number of library cache memory object;
(E) is the estimated required time (in second) for the object deleted from the memory to reload;
(G) is the estimated elapsed time (in second) to execute analysis in shared pool; and
(I) is the estimated number of time that library cache memory object is detected.