Shared Pool   «Prev  Next»
Lesson 2 Tuning the Shared Pool for Optimal Performance
Objective List shared pool tuning techniques.

Tuning the Shared Pool for Optimal Performance

The shared pool is a critical component of the Oracle System Global Area (SGA). It stores shared memory structures such as shared SQL areas, dictionary cache, library cache, and server handles. Efficient shared pool management is crucial for optimizing database performance. Here are several shared pool tuning techniques in Oracle:
  1. Size Appropriately: The initial step in shared pool tuning is sizing it properly. An undersized shared pool can lead to performance degradation, while an oversized one can waste memory resources. Monitor the library cache miss ratio, free memory in the shared pool, and reloads of objects from the dictionary cache to assess if resizing is needed.
  2. Use Bind Variables: Using bind variables can significantly reduce parsing overhead and improve scalability. Without bind variables, even slightly different SQL statements are parsed and stored separately, leading to excessive memory consumption and increased parse time.
  3. Pin Packages and Procedures: You can use the DBMS_SHARED_POOL package's KEEP procedure to pin frequently used packages, procedures, and triggers in memory. This prevents them from being aged out of the shared pool, which reduces hard parses and improves performance.
  4. Avoid Shared Pool Fragmentation: Ensure that your shared pool size and the size of your large pool are set adequately to avoid fragmentation. Monitor the shared pool's free memory and the sizes of the largest chunks of free memory to identify potential fragmentation.
  5. Control Session Cursors: Limit the number of open cursors (OPEN_CURSORS parameter) to a realistic number based on your application's requirements. Excessive cursors can lead to increased shared pool usage.
  6. Optimize Shared Pool Reserved Size: The shared pool reserved size (SHARED_POOL_RESERVED_SIZE) can be set to manage large allocations. If you have large objects in your shared pool, you may want to increase this size to avoid running out of contiguous space.
  7. Cursor Sharing: In some cases, using the CURSOR_SHARING parameter can reduce the amount of memory consumed by duplicate SQL statements. It should be used judiciously as it may impact execution plans.
  8. Monitor and Diagnose Issues: Regularly monitoring the shared pool using Oracle's dynamic performance views (V$ views) can help identify potential issues. This includes checking for issues such as excessive invalidations, high reloads, and library cache misses.
  9. Automatic Shared Memory Management (ASMM): Enable ASMM so Oracle can automatically adjust the shared pool size based on the workload. The automatic tuning of shared pool sizes can be done by setting the SGA_TARGET parameter.
  10. Use Automatic Memory Management (AMM): If you are using Oracle 11g or later, consider using AMM. It allows Oracle to dynamically increase or decrease the size of the shared pool and other SGA components in response to changes in workload.

Remember that tuning should be based on specific needs and evidence from performance metrics, not arbitrary rules. Always test the effects of tuning changes to ensure they have the desired effect.

Reduce Resource Consumption

Within the library cache, hit ratios can be determined for all dictionary objects that are loaded. These include table/procedures, triggers, indices, package bodies, and clusters. If any of the hit ratios fall below 75 percent, you should add to the shared_pool_size. Proper sizing of the shared pool can reduce resource consumption in at least three ways:
  1. Parse time is avoided if the SQL statement is already in the shared pool. This saves CPU resources.
  2. Application memory overhead is reduced, since all applications use the same pool of shared SQL statements and dictionary resources.
  3. I/O resources are saved, since dictionary elements which are in the shared pool do not require disk access.

Accelerate Executions within cache

Setting cursor_space_for_time parameter to FALSE will accelerate executions within the library cache. This tells Oracle that a shared SQL area can be deallocated from the library cache to make room for a new SQL statement. Setting cursor_space_for_time to TRUE means that all shared SQL areas are pinned in the cache until all application cursors are closed. When set to TRUE, Oracle will not bother to check the library cache on subsequent execution calls because it has already pinned the SQL in the cache. This technique can improve the performance for some queries, but cursor_space_for_time should not be set to TRUE if there are cache misses on execution calls. Cache misses indicate that the shared_pool_size is already too small, and forcing the pinning of shared SQL areas will only aggravate the problem.
Another way to improve performance in the library cache is to use the init.ora session_cached_cursors parameter.
In the next lesson, you will learn about pinning packages in the shared pool.

Shared Pool Concepts

The main components of the shared pool are
  1. the library cache,
  2. the dictionary cache, and depending on your configuration,
  3. the server result cache.
The library cache stores the executable (parsed or compiled) form of recently referenced SQL and PL/SQL code. The dictionary cache stores data referenced from the data dictionary. The server result cache stores the results of queries and PL/SQL function results. Many of the caches in the shared pool automatically increase or decrease in size, as needed, including the library cache and the dictionary cache. Old entries are aged out to accommodate new entries when the shared pool does not have free space. A cache miss on the data dictionary cache or library cache is more expensive than a miss on the buffer cache. For this reason, the shared pool should be sized to ensure that frequently used data is cached. Several features make large memory allocations in the shared pool: for example, the shared server, parallel query, or Recovery Manager. Oracle recommends segregating the SGA memory used by these features by configuring a distinct memory area, called the large pool. Allocation of memory from the shared pool is performed in chunks. This chunking enables large objects (over 5 KB) to be loaded into the cache without requiring a single contiguous area. In this way, the database reduces the possibility of running out of enough contiguous memory due to fragmentation.
Infrequently, Java, PL/SQL, or SQL cursors may make allocations out of the shared pool that are larger than 5 KB. To allow these allocations to occur most efficiently, Oracle Database segregates a small amount of the shared pool. This memory is used if the shared pool does not have enough space. The segregated area of the shared pool is called the reserved pool.