To review one of our primary shared pool tuning goals, we want to find small, high-use packages and pin them into our shared pool library cache. We can use the V$DB_OBJECT_CACHE fixed view to display this information. To look at pinned packages in the SGA run the following script. The output from this listing should show those packages that are frequently used by your application.
memory.sql - Display used SGA memory for triggers,
packages, & procedures
SET PAGESIZE 60;
COLUMN EXECUTIONS FORMAT 999,999,999;
COLUMN Mem_used FORMAT 999,999,999;
SELECT SUBSTR(owner,1,10) Owner,
SUBSTR(type,1,12) Type,
SUBSTR(name,1,20) Name,
executions,
sharable_mem Mem_used,
SUBSTR(kept||' ',1,4) "Kept?"
FROM V$db_object_cache
WHERE TYPE IN ('TRIGGER','PROCEDURE','PACKAGE BODY',
'PACKAGE')
ORDER BY EXECUTIONS DESC;
View the diagram for the Shared Pool Objects output script below to see a description of the process.
Pinned packages Output
In this listing, we see those packages that have the highest number of executions and their memory size. In general, you will want to pin those packages that are frequently referenced. Be aware, however, that pinned packages will leave less re-usable memory in the shared pool, and you may want to increase the shared_pool size to accommodate the pinned packages.
Configuring the Reserved Pool
Although Oracle Database breaks down very large requests for memory into smaller chunks, on some systems there might still be a requirement to find a contiguous chunk (for example, over 5 KB) of memory. (The default minimum reserved pool allocation is 4,400 bytes.) If there is not enough free space in the shared pool, then Oracle Database must search for and free enough memory to satisfy this request. This operation could conceivably hold the latch resource for detectable periods of time, causing minor disruption to other concurrent attempts at memory allocation.
Thus, Oracle Database internally reserves a small memory area in the shared pool that the database can use if the shared pool does not have enough space. This reserved pool makes allocation of large chunks more efficient. By default, Oracle Database configures a small reserved pool. The database can use this memory for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects. After the memory allocated from the reserved pool is freed, it returns to the reserved pool. You probably will not need to change the default amount of space Oracle Database reserves. However, if necessary, the reserved pool size can be changed by setting the SHARED_POOL_RESERVED_SIZE initialization parameter. This parameter sets aside space in the shared pool for unusually large allocations.
For large allocations, Oracle Database attempts to allocate space in the shared pool in the following order:
From the unreserved part of the shared pool.
From the reserved pool. If there is not enough space in the unreserved part of the shared pool, then Oracle Database checks whether the reserved pool has enough space
From memory. If there is not enough space in the unreserved and reserved parts of the shared pool,
then Oracle Database attempts to free enough memory for the allocation. It then retries the unreserved and reserved parts of the shared pool.
Trigger pins packages on Database Startup
The following trigger pins packages on each database startup. Pinning packages is an effective way of keeping large PL/SQL objects in the shared pool of memory, improving performance and enhancing database stability. This trigger, PIN_ON_STARTUP, will run each time the database is started. You should create this trigger while connected as a user with ADMINISTER DATABASE TRIGGER privilege.
rem while connected as a user with the
rem ADMINISTER DATABASE TRIGGER system privilege:
create or replace trigger PIN_ON_STARTUP
after startup on database
begin
DBMS_SHARED_POOL.KEEP (
'SYS.STANDARD', 'P');
end;
In the next lesson, you will learn how to identify swapped-out items from the shared pool.