August 2009
M T W T F S S
« Jun   Dec »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

How to Tune log File Sync?

当会话等待redo log buffer 中的信息被写到磁盘的时候就会发生Log file sync waits 等待事件。
通常这是由LGWR的磁盘写入速度慢或者用户的频繁递交引起的。
下面是一些常用的减少log file sync waits 等待时间的方法:
1)调整LGWR以获得更好的磁盘写入吞吐量。
2)如果在短时间段内有很多事务,看有没有可能把这些事务分批处理以减少commit操作。
每个递交动作oracle都会首先去确认相关的redo log 信息以及被写到了磁盘。
3)看是不是有可能使用COMMIT NOWAIT 选项。在Oracle 10g R2中,Oracle增强了COMMIT命令,
增加了WRITE语句来控制redo log文件写入磁盘的方式以提高性能。这个新特性应该只是被用在以下情况:
(1)大事务量导致的redo log 写。
(2)在实例崩溃的时候,可以接受数据的丢失。
(3)处理的事务会引起严重的redo log writes 等待。

COMMIT语句的一些可用选项:
COMMIT;
COMMIT WRITE WAIT;      –> The commit command is synchronous. It doesn’t return until the relevant redo information is written to the online redo log.
COMMIT WRITE NOWAIT;    –> The commit command is asynchronous. It can return before the relevant redo information is written to the online redo log.
COMMIT WRITE BATCH;     –> The commit command is synchronous. It doesn’t return until the relevant redo information is written to the online redo log.
COMMIT WRITE IMMEDIATE; –> The commit “prods” the LGWR process by sending a message, so that the redo is written immediately to the redo logs.

Default COMMIT behavior New option
IMMEDIATE The redo information is written to disk immediately (forcing a disk I/O for each commit). BATCH Oracle buffers the redo information. The log writer will write this redo information to disk, but in its own time. Thus, several I/Os can be “batched”.
WAIT Oracle does not return from the commit until the commit has completed successfully. NOWAIT Oracle doesn’t wait for the commit to complete, but returns right away.

为了避免代码的修改,可以修改COMMIT_WRITE参数文件,参数可以在会话级别或者系统级别设置。
例如:
SQL> ALTER [SYSTEM | SESSION] SET COMMIT_WRITE=’IMMEDIATE,NOWAIT’;

你也可以创建一个触发器在运行程序的用户级别设置COMMIT 方式:
SQL> CREATE OR REPLACE TRIGGER sys.global_commit_session_settings AFTER LOGON ON <your application_username>.SCHEMA
BEGIN
execute immediate ‘alter session set COMMIT_WRITE =”IMMEDIATE,NOWAIT”’;
END;
/

4)看看是否可以使用NOLOGGING/UNRECOVERYABLE选项处理事务,以减少redo log 的生成。

Reference:
DOC ID:857576.1

1 comment to How to Tune log File Sync?

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>