tuning 第七章(三)

四、配置和使用redo log buffer

在buffer cache上完成数据块的修改的服务器进程会生成重做数据(redo data)到log buffer。
在如下情况下,LGWR进程开始将重做日志缓存redo log buffer中的内容写入到在线重做日志中:
1)日志缓存达到1/3满
2)进行LGWR的服务器进程提交会回滚事务
3)DBWR告知LGWR需要写入

当LGWR将redo条目从redo log buffer写入redo文件(磁盘)后,用户进程可以将磁盘中新的条目放入写入内存。
LGWR通常能够保证buffer中有足够的空间供新的条目使用,即使在redo log 负载很重时。

大的buffer提高了新条目有可用空间的可能性,同时使LGWR能够高效地写出redo records
如果系统中的日志缓存太小,且有大量update操作,意味着LGWR不断地将redo刷到磁盘中来保证日志缓存有2/3是空的。

On computers with fast processors and relatively slow disks, the processors might be filling the rest of the buffer in the time it takes the redo log writer to move a

portion of the buffer to disk. A larger log buffer can temporarily mask the effect of slower disks in this situation.

可以通过提高检查点或归档进程、提高LGWR的性能(比如将所有在线日志放到速度更快的磁盘上)

以下操作会使重做日志缓存的利用率高:
对于批量的jobs,批量提交操作,以便LGWR写入重做日志更高效;
加载大量数据时使用nologging操作。

1.设置日志缓存的大小
大量数据的DML操作通常需要增大默认的日志缓存大小。
和SGA比,日志缓存非常小。初始设置可以参考:max(0.5M,(128K*cpu数量))
一般而言,日志缓存增加到1M以上是没有意义的。

2.日志缓存的统计数据
redo buffer allocation retries反映了一个用户进程等待redo log buffer(空间)的时间。可以在v$sysstat查询到。

监控语句为:
select name,value
from v$sysstat
where name='redo buffer allocation retries';

redo buffer allocation retries应该接近0,如果一直在增加,表明用户需要等待redo log buffer释放空间。这可能是由于log buffer太小或者检查点造成的。增加redo log buffer的大小

,必要时增加初始化参数log_buffer的大小。也可以增加检查点或归档进程。
另外一种检查手段是看log buffer space是否发生,如果没有,则说明log buffer是充足的。

 

五、PGA内存的管理

程序全局区包含服务器进程的数据和控制信息,内存时私有的。
The Program Global Area (PGA) is a private memory region containing data and control information for a server process. Access to it is exclusive to the server process

and is read and written only by the Oracle Database code acting on behalf of it. An example of such information is the run-time area of a cursor. Each time a cursor is

executed, a new run-time area is created for that cursor in the PGA memory region of the server process executing that cursor.

进行复杂查询时,大部分的run-time area用于work areas,如:
基于排序的操作,(order by、group by、rollup及开窗函数)
hash-join
bitmap merge
bitmap create
write buffers used by bulk load operations

A sort operator uses a work area (the sort area) to perform. the in-memory sort of a set of rows. Similarly, a hash-join operator uses a work area (the hash area) to

build a hash table from its left input.

work area的大小是可以调整的。通常来说大的工作区能够提高那些需要大量内存的操作的性能。理想状态下,工作区的大小足够容纳输入数据和完成相关操作的辅助内存。
This is known as the optimal size of a work area。

当work area的大小小于optimal时,由于对输入数据需要额外的操作,响应时间会增加。
这叫做工作区的one-pass size。

当工作区的大小远远小于输入数据的大小,就需要多次传递输入数据。响应时间急剧增加。叫做工作区的multi-pass大小。

系统的目标是有大多数工作区运行于优化大小下(The goal is to have most work areas running with an optimal size),oltp系统中大于90%,而少于10%是运行在one-pass 大小下的。

应该避免multi-pass执行。

即使是对于运行大量查询、hash-join的DSS系统,one-pass执行的内存需要相对小。
一个配置了较大PGA内存的系统不应该需要输入数据的multi-pass

自动PGA内存管理简化并提高了PGA内存分配的效率。默认情况下,pga内存管理是开启的。这种模式下oracle动态调整pga内存分区大小来决定工作区。最小值为10MB。

通过设置pga_aggregate_target=0可以禁用自动pga内存管理。这种状态下,工作区最大大小由_area_size系列参数决定,如sort_area_size。

1.配置自动pga内存

自动pag内存管理模式下,自动为所有会话设置工作区,*_area_size参数被忽略。
在给定时间内,pga可用内存总量自动给予pga_aggregate_target参数变化。这个数量被设置为pga_aggregate_target减去为其他系统组件分配的pga内存数量。之后pga内存给予特定的内存需

要分配给每个活动的工作区。

在自动pga内存管理模式下,oracle的主要目标是遵照dba设置的pga_aggregate_target(通过动态控制pga内存分配给sql工作区的内存)。同时通过最大化使用optimal 数量pga内存(缓存内

存)的工作区数量来最大化需要内存较多的sql的性能。
其他的工作区运行在one-pass模式下,除非dba用pga_aggregate_target限制了pga大小,且限制值太小,以致需要multi-pass执行来减少pga的消耗。

新建实例后很难准确设置pga_aggregate_target,可以通过三个步骤来确定:
1)第一次评估。默认情况下,oracle使用sga大小的20%,但对于大型的DSS系统,这个值太小了。
2)系统正常负载下,监控性能,使用oracle收集的pga统计数据,查看是否合理
3)使用oracle pga advice统计数据调整pga_aggregate_target

(1)设置pga_aggregate_target
基于oracle实例的可用内存进行设置。可以动态在实例级别进行调整。

如一个有4GB物理内存的系统中运行oracle实例,可能考虑为oracle分配3.2GB。
然后就需要分配SGA和PGA:
对于oltp系统,pga的分配量较少,如分配20%,其他的80%用于SGa
对于DSS系统,查询需要很大量的内存,PGA可能占到70%

pga_aggregate_target的合理初始值为:
OLTP:pga_aggregate_target=(total_mem*80%)*20%
DSS:pga_aggregate_target=(total_mem*80%)*50%

(2)监控自动pga内存管理的性能
利用动态性能视图来实现

v$sgastat中的列含义:
aggregate pga target parameter:
参数的当前值,默认是sga的20%。如果设置为0,自动PGA内存管理被禁用。
aggregate pga auto target:
在自动调整模式下oracle可以分配给工作区的内存大小。由pga_aggregate_target和当前工作区负载决定。如果此参数比pga_aggregate_target小,那么大量的pga内存被系统的其他组件(如

pl/sql、java内存)使用了,工作区的很少。自动调整模式下应该确保为工作区预留了足够的pga内存
global memory bound:
自动调整模式下分给工作区的最大内存量。反映当前工作区的负载情况。当系统中活动工作区的数量增加时,这个值就减小。经验值为:global bound不小于1MB,否则应该增加

pga_aggregate_target的值
total pga allocated:
实例当前为pga分配的内存量。oracle让这个值尽可能小于pga_aggregate_target。如果工作区的负载迅速增加或pga_aggregate_target设置的太小,某段时间该值可能超过

pga_aggregate_target
total freeable pga memory:
显示分配的pga内存中能够被释放的有多少
total pga used for auto workareas:
自动内存管理模式下多少pga内存用于工作区。此参数可以用来判断多少内存被用于pga内存的其他花费了(如pl/sql、java)
PGA ther = total PGA allocated - total PGA used for auto workareas
over allocation count:
自实例启动时开始累积。Over-allocating PGA memory can happen if the value of PGA_AGGREGATE_TARGET is too small to accommodate the PGA other component in the previous

equation plus the minimum memory required to execute the work area workload.这种情况下oracle无法使用pga_aggregate_target设置的值,需要分配额外的pga内存。
当发生over-allocation,应该根据v$pga_target_Advice的信息增加pga_aggregate_target的值。
total bytes processed:
实例启动以来,占用大量内存的sql操作所使用的字节数。
extra bytes read/written:
当一个工作区不能优化运行时,一个或多个额外的被用于输入数据。
represents the number of bytes processed during these extra passes since instance startup. This number is also used to compute the cache hit percentage. Ideally, it

should be small compared to total bytes processed.
cache hit percentage:
反映pga内存组件的性能,累计值。100%代表所有工作区都是优化的,这是理想值。但通常总会有one-pass或multi-pass,这些会减少缓存命中率。

缓存命中率的计算:
Consider a simple example: Four sort operations have been executed, three were small (1 MB of input data) and one was bigger (100 MB of input data). The total number

of bytes processed (BP) by the four operations is 103 MB. If one of the small sorts runs one-pass, an extra pass over 1 MB of input data is performed. This 1 MB value

is the number of extra bytes read/written, or EBP. The cache hit percentage is calculated by the following formula:
BP x 100 / (BP + EBP)

The cache hit percentage in this case is 99.03%, almost 100%. This value reflects the fact that only one of the small sorts had to perform. an extra pass while all

other sorts were able to run optimally. Hence, the cache hit percentage is almost 100%, because this extra pass over 1 MB represents a tiny overhead. However, if the

big sort is the one to run one-pass, then EBP is 100 MB instead of 1 MB, and the cache hit percentage falls to 50.73%, because the extra pass has a much bigger impact.

v$process:
每个连接到实例的进程对应一行。通过如下语句监控pga内存使用情况:
SELECT PROGRAM, PGA_USED_MEM, PGA_ALLOC_MEM, PGA_FREEABLE_MEM, PGA_MAX_MEM
FROM V$PROCESS;

v$process_memory:
通过命名组件为每个oracle进程进行pga内存使用情况的分类。每个oracle process最多六行,分别是:
java、pl/sql、OLAP、sql、为系统分配但未指定具体类的内存、其他。

v$sql_workarea_histogram:
显示optimal memory size、one-pass memory size、multi-pass memory size工作区的大小。

v$sql_workarea_active:
查看活动的工作区。
SELECT to_number(decode(SID, 65535, NULL, SID)) sid,
operation_type OPERATION,
trunc(EXPECTED_SIZE/1024) ESIZE,
trunc(ACTUAL_MEM_USED/1024) MEM,
trunc(MAX_MEM_USED/1024) "MAX MEM",
NUMBER_PASSES PASS,
trunc(TEMPSEG_SIZE/1024) TSIZE
FROM V$SQL_WORKAREA_ACTIVE
ORDER BY 1,2;
精确查询当前活动工作区的大小。

v$sql_workarea:
每个使用了一或多个工作区的负载游标累积信息。


调整pga_aggregate_target:
通过v$pga_target_advice、v$pga_target_advice_histogram可以看到pga_aggregate_target变化对pga数据的影响。
显示了当前值的1/8到8倍间变化会有什么影响。

开启pga性能视图的建议功能,需要设置参数:pga_aggregate_target、statistics_level(typical或all)
当实例重启或pga_aggregate_target修改时pga的建议内容也会变化。

v$pga_target_Advice:
predicts how the statistics cache hit percentage and over allocation count in V$PGASTAT will be impacted if you change the value of the initialization parameter

PGA_AGGREGATE_TARGET

v$pga_target_advice_histogram:
predicts how the statistics displayed by the performance view V$SQL_WORKAREA_HISTOGRAM will be impacted if you change the value of the initialization parameter

PGA_AGGREGATE_TARGET.

2.配置OLTP_PAGE_POOL_SIZE
为OLAP会话分配的最大页缓存(KB)
通常设置一个小的olap页缓存值,并用db_cache_Size设置一个大的默认buffer pool。


 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26451536/viewspace-752405/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26451536/viewspace-752405/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值