tuning 03 Sizing the Share pool

share pool : (组成)
library cache: stores shared sql and pl/sql code (包含 statement text, parsed code, execution plan)
data dictionary cache : keeps information about dictionary objects. (包含 definitions for tables, columns, and privileges from the data dictionary tables)
调优 share pool 考虑的内容:
A cache miss on the data dictionary cache or library cache is more expensive than a miss on the database buffer cache. Tuning the shared pool is a priority.
当你调优 share pool 时, 你首先要集中精神调优 library cache, 因为 语法上, 倾向于保存 data dictionary data 在内存中的时间要大于 library cache data. 所以, 如果 library cache 的命中率可以接受的同时, data dictionary cache 也必然是可以接受的.
shared_pool_size 是用来定义 share pool 大小的参数
在 share pool 中存储的 sql 和 pl/sql 是对所有用户共享的, 这样可以避免重复解析, 另外这里使用的算法是 LRU (least recently used)
If a user issues a statement that is already in the cache, the Oracle server can use the cached version without having to reparse it.
To find whether a statement is already cached, the Oracle server:
- Reduces the statement to the numeric value of the ASCII text
- Uses a hash function of this number
那么要如何调优 library cache 呢?
- Make sure that users can share statements (As much generic code as possible, Bind variables rather than constants)
- Prevent statements from being aged out by allocating enough space
- Avoid invalidations that induce reparsing
注: If a schema object is referenced in a sSQL statement and that object is later modified in any way, the SQL statement held in memory is rendered invalid.
一些术语: Terminology
Gets: (Parse) The number of lookups for objects of the newspace (搜索时需要的资源)
Pins: (Execution) The number of reads or executions of the objects of the namespace (执行SQL statement时需要的资源)
Reloads: (Reparse) The number of library cache misses on the execution step, causing implicit reparsing of the statement and block. (重解析时, 需要的资源)
在 v$librarycache 中的每一行, 都包含着一个namespace 统计信息, 这里的namespace 就对应了内存中的一个空间(这个空间就好比一个房子, 卧室是一个namespace, 它的名字是卧室, 客厅也是一个空间, 它的名字是客厅)
一些重要的动态视图:
v$sgastat , 用来显示 SGA structure, The contents of the shared pool are not aged out as long as free memory is avalilable in the shared pool.
v$librarycache, statistics on library cache management
v$sqlarea, Full statistics about all shared cursors, and the first 1000 characters of the SQL statement
v$sqltext, The full SQL text without truncation, in multiple rows
v$db_object_cache: Database objects cached, including packages; also objects such as tables and synonyms, where these are referenced in SQL statements.
在 v$librarycache 这个视同中的 GETHITRATIO determines the percentage of parse calls that find a cursor to share(GETHITS/GETS). This ratio should be in the high 90s in OLTP environments. If not, you can improve the efficency of your application code.
select sum(pins) "Executions", sum(reloads) "Cache Misses", sum(reloads)/sum(pins) from v$librarycache;
如果以上sql语句执行结果大于1%, 那么就要增加 SHARED_POOL_SIZE.
When Invalidations Occur
If a schema object is referenced in a SQL statement and that object is later modified in any way, the shared SQL area becomes invalidated(marked as invalid), and the statement must be reparsed the next time it is executed, and therefore reloaded.
For example, when a table, sequence, synonym or view is re-created or altered or dropped, or a procedure or package specification is recompiled, all dependent shared SQL areas are invalidated.
Example:
select count(*) from hr.employees;
select namespace, pins, reloads, invalidations from v$librarycache; -- 这时 invalidation 是 0
analyze table hr.employees compute statistics;
select count(* ) from hr.employees;
select namespace, pins, reloads, invalidations from v$librarycache; -- 这时 invalidation 是 2, 其余参数 reloads 等也都增加了
Cached Execution Plans
这个是真正解析后的, oracle 执行 SQL 语句的步骤
With this feature, the Oracle server preserves the actual execution plan of a cached SQL statement in memory. 注意, 这个执行计划必须已经是cache中的了, 所以之前说的 SQL 语句调优, 首先要保证 shared pool 的命中率, 后面的是在命中率的基础上, 再调优 SQL 语句.
When the SQL statement ages out of the library cache, the corresponding cached execution plan is removed.
The main benefit of this feature is better diagnosis of query performance. 这个执行计划对 SQL语句的调优很有用.
v$sql_plan, can be used to view the actual execution plan information for cached cursors.
还有一个 table 跟这个视图很类似, PLAN_TABLE

UGA 不用考虑,是给 shared server 准备的, dedicate server 不用
library cache 是用来解析 sql 的,把文本的sql语句编译成可执行的文件

自动内存管理参数 SGA_TARGET, 就是说, 你只要指定这么一个参数就可以了. 这样 SGA 里的组件都会自动指定.
SGA_TARGET 参数,指定整个SGA大小,之后的很多参数会被自动指定,oracle会自己优化
alter system set shared_pool_size=10000 scope=both

最大指标: 尽量多的使用已经解析的sql语句
olap: 给领导用的,用户少,但是查询的量都比较大,不太注意reparsing,因为查询的sql语句复杂,一般都需要reparsing。因为sql语句少, 所以肯定可重复利用的就不多.
oltp: 给n多人用,并发量大, 所以要注意尽量避免 reparsing 

两条语句共享一个sql parse代码
注释,空格,等等都要必须一摸一样,才能被认为是同样的,例如下边的不能共享

上面设定了参数 CURSOR_SHARING 如果设置成 similar, 那么上例中的两个一样的SQL语句就可以不经过解析.

注意 schema, 因为有可能 employees 这个表在多个schema中都有, 比如你写 select * from employees; 但是如果是另一个用户也这么写, 而那个用户自己也有employees表, 那么这两条sql语句不能共享.
绑定变量的名字要一样,绑定变量对提高性能很有用


set timing on
每次执行, 都会报告执行时间
接下来执行了两个存储过程, 一个是使用绑定变量的, 一个是不使用绑定变量, 执行出来的结果插入10000条记录, (0.77 秒, 3.60秒, 可以看到是5倍的关系)
-- 使用绑定变量的
create or replace procedure proc1
begin
for i in 1..10000
loop
execute immediate ' insert into m values(:x)' USING i;
end loop;
end;
/
-- 不使用绑定变量的
create or replace procedure proc2
begin
for i in 1..10000
loop
execute immediate 'insert into m values('||i||')';
end loop;
end;
/

Latch 是一种锁. 内存锁

增大 library cache 大小.
确认 sql 语句的问题, 为什么不能共享 sql parse.

调优 library 总的指导原则是, 尽量少的 parse .

v$librarycache

v$librarycache

v$sgastat 里有个重要指标就是 shared pool free memory
以上的各种动态视图, 需要各种查询联机文档.

数据仓库是OLAP,是用来分析的,跟OLTP不一样,目前我们使用的是OLTP



尽量避免使用动态SQL语句





select namespace, gethitration, pinhitratio, reloads, invalidations from v$librarycache;

只看前 4 行就可以了.

这个参数上边已经提到过, 如果你没有能力调优SQL了, 你可以将这个参数设置成 similar, 当然尽量不改, 因为改了以后会有副作用.

v$librarycache 中的值都是累积的, 所以我们可以参考 statspack 的方法, 找一个时间段, 看这个时间段之内的值, 这样就比较准确.











select free_space, requests, request_misses, request_failures from v$shared_pool_reserved;











例子:






tuning 03 Sizing the Share pool的更多相关文章
- oracle 内存结构 share pool sql解析的过程
1.sql解析的过程 oracle首先将SQL文本转化为ASCII字符,然后根据hash函数计算其对应的hash值(hash_value).根据计算出的hash值到library cache中找到对应 ...
- 共享内存 share pool (2):BUCKET /FREE LISTS /RESERVED FREE LISTS /UNPINNED RECREATABLE CHUNKS (lru first)
相关概念 BUCKET :每个bucket上挂有一个 chunk list.同一个BUCKET中的chunk在物理地址上是不一定相邻的 FREE LISTS:按bucket划分,共有255个,buck ...
- 共享内存 share pool (1):heap /extent /chunk/
相关概念 CHUNK: Shared pool物理层面上由许多内存块组成,这些内在块称为chunk.但是chunk是大小不一的,在内存中一个chunk是连续的. EXTENT:由多个连续的chunk组 ...
- share pool 管理机制
Library cache是Shared pool的一部分,它几乎是Oracle内存结构中最复杂的一部分,主要存放shared curosr(SQL)和PLSQL对象(function,procedu ...
- Tuning 04 Sizing the Buffer Cache
Buffer Cache 特性 The buffer cache holds copies of the data blocks from the data files. Because the bu ...
- Tuning 05 Sizing other SGA Structure
Redo Log Buffer Content The Oracle server processes copy redo entries from the user’s memory space t ...
- (转载)处理SQL解析失败导致share pool 的争用
通过关联x$kglcursorx$kglcursor_child_sqlid视图: 通过使用Oracle10035Event事件可以找到解析失败的SQL: 通过oraclesystemdump也可以找 ...
- SPA测试
1.生产端:环境准备为了进行SPA测试,在生产数据库中创建了SPA测试专用用户,避免与其他用户相互混淆与可能产生的误操作. CREATE USER SPA IDENTIFIED BY SPA DEFA ...
- Improve Scalability With New Thread Pool APIs
Pooled Threads Improve Scalability With New Thread Pool APIs Robert Saccone Portions of this article ...
随机推荐
- Linux 搭建svn环境
第一步:下载并安装svn sudo apt-get install subversion 第二步:创建版本库目录(此仅为目录,为后面创建版本库提供存放位置) 选择在var路径下创建版本库,当前处于根目 ...
- JQuery插件:动态列和无间隙网格布局Mason.js
来源:GBin1.com 在线演示 JavaScript提供很多强有力的方案,解决动态列的网格布局(例如:Pinterest).这些方案很有效,但是,有时候,会造成网格的间隙或粗糙的边缘. Mason ...
- Solidworks如何让齿轮运动副保证持续啮合状态
出现这种情况一般是齿轮的比例有问题,如果你选择两个齿轮的齿顶圆的面,则自动比例是44:74,然后手动转动某个齿轮,就会出现不能啮合的情况 只要模数相同的齿轮不管大小都能始终啮合,但是你需要首先为每 ...
- centos 7安装 navicat
下载地址: http://download.navicat.com/download/navicat111_mysql_en.tar.gz 下载后copy到指定安装文件夹 [hcr@localhost ...
- SOA初探
背景 曾今SOA的概念犹如今日“云计算.大数据”一样,被炒得火热,不少企业便纷纷响应,并宣称会拥抱和实施SOA.而事实上,业界出现了两种极端:一种是由于各类文章和书籍关于SOA的描述往往太过抽象,再加 ...
- python __slot__
class Player(object): def __init__(self,name,age,life): self.name=name self.age=age self.life=life c ...
- 运行maven pom.xml文件后编译环境变为jdk1.5
idea中运行pom.xml文件后,将编译环境变成了1.5,造成一系列的编译问题很是不方便. 以下是解决方法: 在"pom.xml"里加入如下代码: <properties& ...
- maven modules
所有用Maven管理的真实的项目都应该是分模块的,每个模块都对应着一个pom.xml.它们之间通过继承和聚合(也称作多模块,multi-module)相互关联.那么,为什么要这么做呢?我们明明在开发一 ...
- 老项目转为maven的步骤具体说明
可先阅读 关于已有项目转为maven的一点看法 新建maven项目要点 事实上之前已转过几个.但忘了记录下来.今天又转了一个项目,补记录一下. 步骤 1.写pom.xml 最耗费时间的一步.由于不用m ...
- 【Linux】VMware上安装Linux操作系统
Vmware上安装Linux系统 1. 文件菜单选择新建虚拟机 2. 选择经典类型安装,下一步. 3. 选择稍后安装操作系统,下一步. 4. 选择Linux系统,版本选择CentOS 64位. 给虚拟 ...