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 ...
随机推荐
- 【实践】用 js 封装java shuffle函数(打乱数组下标方法)
此方法返回的会是一个全新的数组 所以并不会像java里的shuffle函数一样返回一个引用一样的数组 思路如下: 1.新建一个函数传入需要打乱下标的数组 2.获取数组的长度 3.新建一个用来保存并且返 ...
- json字符串 与 json对象 的相互转换
var obj=JSON.parse(jsonstr); // 将json字符串转换成json对象 var str=JSON.stringify(jsonobj); // 将json对象转换成json ...
- 服务器变量 超级全局数组$_SERVER (附加超简单表单与html5表单属性)
001.html <html> <head><title>user log</title> <meta http-equiv="cont ...
- {...formItemLayout} 标签布局
{...formItemLayout}是reactjs中属性的写法{...props},formItemLayout标签布局,wrapperCol需要为输入控件设置布局样式时,和label 标签布局, ...
- Java集合-Map接口相关操作方法
Map接口不是Collection接口的继承.Map接口用于维护键/值对(key/value pairs). 该接口描述了从不重复的键到值的映射. (1) 添加.删除操作: Object put(Ob ...
- ConfigurationManager读取dll的配置文件
ConfigurationManager读取dll的配置文件 最近一个项目,需要发布dll给第三方使用,其中需要一些配置参数. 我们知道.NET的exe工程是自带的App.config文件的,编译之后 ...
- mqtt选择
1.名称 MQTT kafka 2.历史 IBM推出的一种针对移动终端设备的发布/预订协议. LinkedIn公司开发的分布式发布-订阅消息系统.后来,成为Apache项目的一部分. 3.原理 基于二 ...
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!问题解决
用mac终端ssh连接Linux服务器,提示以下错误: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: RE ...
- NYOJ 10 skiing (深搜和动归)
skiing 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 Michael喜欢滑雪百这并不奇怪. 由于滑雪的确非常刺激.但是为了获得速度.滑的区域必须向下倾斜.并且 ...
- C 语言 mmap
/* *@author cody *@date 2014-08-12 *@description */ /* #include <sys/mman.h> void *mmap(void * ...