linux 生成时间日志,日志产生的过程

1.牛人的关于日志的文章()

第一步:获取闩Theredo copylatchesare used to indicate that a process is copying redo into the log buffer,

and that LGWR should wait until the copy has finished, before writing the target log buffer blocks to disk.

获取闩的方式No-wait mode is used for most gets against the redo copy latches,

because the process can use any one of them to protect its copy into the log buffer.

It first attempts to get the copy latch that it last held.

Failing that, the process attempts to get each other copy latch in turn, in no-wait mode.

Willing-to-wait mode is only used to get the last copy latch if no-wait gets against all the other copy latches have failed.

这种闩的个数:初始化参数_LOG_SIMULTANEOUS_COPIES,定义允许同时写redo的redo copy latch的数量。

在Oracle7和Oracle8里,_LOG_SIMULTANEOUS_COPIES缺省的等于CPU的数量。

从Oracle8.1.3开始,缺省的_LOG_SIMULTANEOUS_COPIES变成2倍的CPU数量,并且成为了一个隐含参数.

第二步:获取空间Once a redo copy latch has been acquired, the redo allocationlatch must be taken to allocate space in the log buffer.

This latch protects the SGA variables that are used to track which log buffer blocks are used and free.到底获取多大的空间呢?The amount of space allocated is that required for all of the change

vectors comprising the logical database change,

plus an allowance for a 16-byte block headerat the beginning of each

redo log block, if the redo entry spans the beginning of one or more

log blocks.获取到空间后就把数据拷贝进去了,The change vectors are then copied into the log buffer from temporary buffers in the PGA of the process.

redo allocation latch得个数:

在Oracle9.2之前,Redo allocation latch 是唯一的,因此向Log Buffer Cache中写入redo entries时是串行的。在Oracle9.2企业版中,Redo allocation latch 的数量由LOG_PARALLELISM控制。

Redo allocation latch 在Log Buffer中为每个事务分配空间,如果事务很小或者服务器只有一个CPU,Redo

allocation latch 同时COPY事务数据到Log Buffer Cache。在Log Switch释放空间时,Redo

allocation latch 和 Redo Copy Latch同时被释放,也即在Log Switch过程中,Redo的生成是被禁止的。

在Oracle10g中,为了减少竞争,Oracle缺省的预分配19个redo allocation Latch.

第三步:如何写入日志文件

At this point the process may need to post LGWR to signal that it should begin to flush the log buffer.

This applies if the allocation raised the number of used blocks in the log buffer above the background write threshold,

or if a commit marker has been copied into the redo stream and needs to be synced.

However, to ensure that LGWR is not posted needlessly,

the process takes the redo writing latch to check whether LGWR is already active or has already been posted.

The redo writinglatch is then released, and if appropriate the LGWR process is posted.

Theredo allocationlatch is needed again by processes waking up from log file sync waits,

to check whether the log buffer block containing the redo of interest has yet been written to disk.

If not, that process must continue to wait.

The SGA variable that shows whether a particular log buffer block has yet been written to disk

is the index into the log file representing the base disk block for the log buffer.

This variable is of course protected by the redo allocation latch, and so the redo allocation latch must be taken to check it.

Similarly, DBWn needs the redo allocation latch to check whether the high RBA of a set blocks that it intends to write has yet been synced.

如果分配的空间使用超过了_log_io_size参数的设置,或者重做流中包含了提交标记符,此时进程可能需要唤醒lgwr并通知刷新日志缓冲。为了确

保lgwr不会不必要的被唤醒,进程将采用redo writing latch检查lgwr是否active或者已经被唤醒。然后释放redo

writing latch。

第四步:关于日志写

LGWR使用redo latches的机制

获得redo latches不仅仅与重做产生和log file

sync有关,同时它们也被lgwr用来写重做到日志文件上。当lgwr被唤醒的时候,其首先得到redo writing

latch更新sga变量指示其active状态,以避免其他进程不必要的唤醒lgwr。如果没有被唤醒,lgwr将获得redo

allocation latch确定是否有重做可写。如果没有,在启动rdbms ipc message前,将重新得到redo writing

latch指示其不再active。

如果有任何重做可写,lgwr将会为redo copy

latches预计latch恢复区域以确定重做缓冲中是否有任何不完整的拷贝需要写。如果有,lgwr将在LGWRwait for redo

copy上沉睡,并且在需要的copy latches被释放后被唤醒。

LGWR用来得到redo writing latch,redo allocation latch和redo copy latches花费的时间的和累计在redo writer latching time统计中。

在每次写完成后,LGWR必须再次得到redo allocation latch更新饱含日志缓冲基磁盘块的sga变量。使用这种机制高效的释放日志缓冲块,并可以重用。

redo latches的调整

通常仅在redo allocation latch上的等待模式未命中率很高或者redo copy latch上的非等待模式很高时,才考虑调整redo latch。

Redo Allocation

在每个实例中只有一个redo allocation,并且不能并行使用。通常也没有办法减少latch保持的延迟。DBA能做的通常只是减少LATCH上的负载。最重要的是确保LGWR不能过分活跃,并且DBWn不能过渡频率的检查点最近的改变。

在应用程序级别,主要频繁的commit,避免SELECT FOR UPDATE和before行触发器,以及最小化redo的产生。

Redo Copy

在Oracle 8.1下,LGWR自身是不会在redo copy

latch上沉睡的,在这些latch上的沉睡指示并行性的程度超过了latch支持的并行度。在这种情况下, redo copy

latch可以使用 _log_simultaneous_copies参数增加,但是不能超过32的限制。

总的来说,除非产生的重做最小化了并且redo allocation已经调整过了,否则不应该调整redo copy latch。同时也应该检查latch持有者的CPU短缺问题。参考文章

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值