Академический Документы
Профессиональный Документы
Культура Документы
=======================
We will see the memory structures in the Shared Pool and how we can tune it by
keeping PL/SQL blocks in it.
This query can help us decide what objects to keep in memory, based on the memory
requirement (the SHARABLE_MEM column). We can also query the EXECUTIONS column to
see objects that are used most often.
Note: If the DBMS_SHARED_POOL was not created during the installation, the
$ORACLE_HOME/rdbms/admin/dbmspool. sql script—executed as SYSDBA—will create it.
We have used the SIZES procedure of DBMS_SHARED_POOL to show objects that are
larger than the size given in the shared pool.
We execute a (simple) anonymous PL/SQL block and then query V$SQLAREA to identify
the ADDRESS and HASH_VALUE of the statement. We then use these values as parameters
for the KEEP procedure of DBMS_SHARED_POOL package to pin the anonymous block in
the Shared Pool.
DECLARE I NUMBER;
BEGIN
/* BLOCK_TO_KEEP */
I := 26;
END;
/
Note: We can also "pin" some objects in the Shared Pool using the
DBMS_SHARED_POOL.KEEP procedure. The pinned objects are removed from the Least
Recently Used list, so they are never aged out and removed from the Shared Pool.
You can experience ORA-4031 error (unable to allocate "x" bytes of shared memory)
if there is no free block with the
required memory in the shared pool, due to fragmentation. You can find a good place
to start investigating ORA-4031 error on Oracle Blogs at the following site:
http://blogs.oracle.com/db/entry/ora-4031_ troubleshooting
Due to the LRU algorithm, blocks of code can be aged out of the shared pool. When a
large block is aged out to make room for a small piece of code, and is needed
again, then the large block is reloaded. There can be fragmentation in the Shared
Pool, which causes
performance degradation.
To avoid fragmentation, we can separate the memory required to store frequently
used large blocks of code from other blocks, using the Shared Pool Reserved Space.
We need to set the SHARED_POOL_RESERVED_SIZE initialization parameter. Querying the
V$SHARED_POOL_RESERVED dynamic performance view, we can inspect the Reserved Pool
statistics.
In this view, we need to lower the value for REQUEST_MISSES and REQUEST_FAILURES.
Using the V$DB_OBJECT_CACHE, we can inquire for large objects that are not kept in
the Shared Pool and decide to keep them in the reserved pool using the KEEP
procedure of the
DBMS_SHARED_POOL package. Doing so also prevents flushing of the pinned object when
executing the ALTER SYSTEM FLUSH SHARED_POOL command.
The SIZES procedure of the same package allows us to identify the objects that
exceed the defined size in the Shared Pool.
A problem may arise when there are large PL/SQL anonymous blocks. In these
situations, we have two alternatives—the first, as explained in the recipe, is to
keep the anonymous block in the Reserved Pool, using the ADDRESS and HASH_VALUE to
identify the statement to keep;
these values are obtained from the V$SQLAREA dynamic performance view. The second
alternative, to improve performance when we have large PL/SQL anonymous blocks, is
to divide large blocks into smaller blocks that execute stored procedures.
The column ESTD_LC_TIME_SAVED indicate the estimated elapsed parse time saved in
seconds, while the ESTD_LC_LOAD_TIME column contains estimated elapsed time in
seconds for parsing.