Chapter 04-Tuning the shared Pool


Objectives

shared pool tune(shared pool 調優)

After completing this lesson,you should be able to do the following:

  • Determine the size of an object and pin it in the shared pool
  • Tune the shared pool reserved space
  • Describe the user global area (UGA) and session memory considerations
  • Measure the library cache hit ratio
  • List other tuning issues related to the shared pool
  • Measure the dictionary cache hit ratio
  • Set the large pool

Shared Pool Contents

Major components of the shared pool are:

Oracle處於shared server mode時,UGA才會有用,對於在dedicate server mode時,無用;

  • Library cache
  • Data dictionary cache
  • User global area(UGA) for shared server session.

因為dedicate server mode擁有自己的PGA,不需要UGA;

即使DBA使用的是Shared server mode,存在着UGA,DBA也可以將UGA移動到Large pool中. 通過此方式也可以達到shared pool 性能調優的目的.所以一般情況下,我們在shared pool性能調優的過程中,可以只關注Library cache和Data dictionary cache兩部分內容即可.

數據字典存放在系統表空間上(system tablespace)

Library cache中,存放是編譯好的SQL;

Shared pool是oracle中影響性能的一個重要部件,是性能調優的重點工作之一.一般情況下shared pool里面只要Libarary cache的性能調優比較正常,dictionary cache基本上也是一致的,比較正常的,二者是統一的、關聯的.

Shared Pool

  • Defined  by SHARED_POOL_SIZE

  在oracle 10g中,oracle提供了內存管理技術叫做automtaic memory management,對應的參數為sga_target;

  到了oracle11g中,Oracle又提供了memory_target;

  • Library cache contains statement text,parsed,code,and execution plan.
  • Data dictionary cache contains definitons for tables,columns,and privileges from the data dictionary tables.
  • UGA contains session information for Oracle Shared Server users when a large pool is not configured.

The Library Cache

Used to store SQL statements and PL/SQL blocks that are to be shared by users

Managed by a least recently used(LRU) algorithm

Used to prevent statements reparsing

  對於OLAP系統,不需要關系reparsing問題.

Reports error ORA-04031 if the shared pool is out of free memory.

  |-解決方案一:擴充內存

  |-解決方案二:減少parse

如何查看shared pool大小?

SQL> show parameter share

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
hi_shared_memory_address             integer     0
max_shared_servers                   integer
shared_memory_address                integer     0
shared_pool_reserved_size            big integer 6501171
shared_pool_size                     big integer 0
shared_server_sessions               integer
shared_servers                       integer     1
SQL>

 如何查看free memory size?

SQL> select * from v$sgastat where name = 'free memory';

POOL         NAME                            BYTES
------------ -------------------------- ----------
shared pool  free memory                  20571536
large pool   free memory                    300000
java pool    free memory                   4194304

The Library Cache

Hard parse就是將SQL statement轉換成oracle server可執行的代碼;

soft parse就是當有SQL Statement提交到Library Cache中的時候,首先檢查有沒有已經parse好的SQL,如果有就使用已經parse好的代碼;這個過程就叫做soft parse.

Tuning The library Cache的一個重要方法就是提高soft parse的數量,減少hard parse的數量.

SQL Shareing Criteria 

Oracle 是如何判斷多個SQL Statement共享同一段內存區域的?

SELECT * FROM employees;

SELECT * FROM Employees;

SELECT *  FROM  employees;

以上三條SQL語句,在oracle看來,是不同的三條語句,不能共享同一塊內存區域(shared SQL area);

ORACLE PARAMETER CURSOR_SHARING has three values(EXACT、SIMILAR、FORCE)

SQL> show parameter CURSOR_SHARING

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cursor_sharing                       string      EXACT

 

SIMILAR DEMO

|-SELECT COUNT(*) FROM employee WHERE manager_id = 121;

|-SELECT COUNT(*) FROM employee WHERE manager_id = 247;

The only exception to this rule is when the parameter CURSOR_SHARING has been set to SIMILAR or FORCE.Similar statements can share SQL areas when the CURSOR_SHARING parameter is set to SIMILAR or FORCE.The costs and benefits involved in using CURSOR_SHAREING are explained later in the section.

Use Bind Variables

A bind variable is a placeholder in a query.For example,to retrieve the record for employee 123,I can use this query:

select * from emp where empno = 123;

Alternatively,I can set the bind variable:empno to 123 and execute the following query:

select * from emp where empno = :empno;

In a typical system,you would query up employee 123 maybe onece and then never agina.Later,you would query employee 456,then 789,and so on.If you use literals(constants) in the query,then each and every query is a brand-new query,never before seen by the database.It will have to be parsed,qualified(names resolved),security checked,optimized,and so on-in short,each and every unique statement you execute will have to be compiled every time it is execurted.

The second query uses a bind variable,:empno,the value of which is supplied query execution time.This query is compiled once,and then the query plan is stored in a shared pool(the libary cache),from which it can be retrieved and reused.The difference between the two in terms of performance and scalability is huge-dramatic,even.

Diagnostic Tools

Parameters affetcing the components:

SHARED_POOL_SIZE(似乎還不能單獨調整library cache,shared sql的大小,如果想調整他們的大小,只能調整shared_pool_size的大小)

OPEN_CURSORS

SESSION_CACHED_CURSORS

CURSOR_SPACE_FOR_TIME

CURSOR_SHARING

SHARED_POOL_RESERVED_SIZE

Using Shared Pool Effectively

An important purpose of the shared pool is to cache the executable versions of SQL and PL/SQL statements.This allows multiple executions of the same SQL or PL/SQL code to be performed without the resources required for a hard parse,which results in significant reductions in CPU,memory,and latch usage.

The shared pool is also support unshared SQL in data warehousing applications,which execute low-concurrency,high-resource SQL statements.In this situation,using unshared SQL with literal values is recommended.Using literal values rahter than bind variables allows the optimizer to make good column selectivity estimates ,thus providing an optimal data access plan.

In a data warehousing environment,the SQL query result cache also enables you to optimize the use of the shared pool.

IN an OLTP system,there are a number of ways to ensure efficient use of the shared pool and related resources.Discuss the following items with application developers and agree on strateies to ensure that the shared pool is used 

effectively:

Shared Cursors

Single-User Logon and Qualified Table Reference

Use of PL/SQL

Avoid Performing DDL

Cache Sequence Numbers

Cursor Access and Management

Use of Result Cache

Efficient use of the shared pool in high-concurrency  OLTP systems significantly reduces the probability of parse-related application scalability issues.

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM