Oracle 11gR2开始引入了 Adaptive Log File Sync,用于优化 log file sync 等待。很多DBA都知道这个隐藏参数:
"_use_adaptive_log_file_sync"
甚至不少性能优化文章都会建议:
alter system set "_use_adaptive_log_file_sync"=false;
今天一个客户问了一个有意思的问题:
Lgwr trc文件
*** 2026-07-29 08:39:15.416
kcrfw_update_adaptive_sync_mode: post->poll long#=3 sync#=20 sync=186 poll=10006 rw=188 ack=17 min_sleep=10006
*** 2026-07-29 08:39:15.416
Log file sync switching to polling
Current scheduling delay is 1 usec
Current approximate redo synch write rate is 6 per sec
DB alert log文件
Wed Jul 29 09:40:52 2026
ALTER SYSTEM SET _use_adaptive_log_file_sync='FALSE' SCOPE=BOTH SID='*';
问在调 _use_adaptive_log_file_sync改为false参数后,lgwr trace中kcrfw_update_adaptive_sync_mode: poll->post 有这条记录才对吗?
客户担心的是这个参数改为false是不是仅是禁用自动调整,而不会恢复LGWR到Post,因为日志里已经提示从post到polling模式了,而没出现poll 到post。
当然有经验的知道默认就是POST模式,改参数_use_adaptive_log_file_sync为false, 不仅会禁用adaptive lgwr sync,而且会恢复为默认值,始终会运行在Post/Wait模式,但是如果实例没有重启从哪去验证呢?
adaptive log file sync feature 是基于 ‘kernel cache redo file’ (kcrf)的, kcrfw_update_adaptive_sync_mode中的kcrfw应该的w是writer的意思。
Adaptive Log File Sync 到底是什么?
传统 Commit 流程如下:
User Process
|
| commit
|
V
LGWR
|
| 写redo
|
V
post 前台session
|
V
commit返回
Oracle 11gR2开始增加了一种新的模式:
User Process
|
| commit
|
V
不停poll LGWR状态
|
V
LGWR完成写入
|
V
commit返回
Oracle会根据系统负载,在下面两种方式之间自动切换:
- Post/Wait(传统)
- Polling(Adaptive)
目的就是减少LGWR唤醒大量Session带来的开销,提高高并发Commit性能。该特性自11.2.0.3起默认开启。
如何判断adaptive_log_file是否生效?
当然首先是看参数
select
ksppinm,
ksppstvl
from
x$ksppi a,
x$ksppsv b
where
a.indx=b.indx
and ksppinm='_use_adaptive_log_file_sync';
当是true时实际上,这只能说明功能允许开启。但也有可能没有切换到没有切换到Polling。
查看Redo Poll统计
SQL> @sys poll
NAME VALUE
-------------------------------------------------------------------------------------------------------------------------------- --------------------------
redo synch poll writes 0
redo synch polls 0
-- or --
select
name,
value
from v$sysstat
where name in
(
'redo synch poll writes',
'redo synch polls'
);
两个值持续增长:说明Oracle已经发生过Polling。
当然参数是true时,也可以查看lgwr trace就是开始我们看到的日志。
GDB查看变量kcrf_alfs_info_+0值
变量kcrf_alfs_info_+0值表示的是adaptive log file sync的功能开关, 下面我在我的26ai 版本测试一下。
SQL> @pd _use_adaptive_log_file_sync
Show all parameters and session values from x$ksppi/x$ksppcv...
NUM N_HEX NAME VALUE DESCRIPTION
---------- ---------- -------------------------------------------------------- ------------------------------ ---------------------------------------------------------------------------------------------------
2710 A96 _use_adaptive_log_file_sync TRUE Adaptively switch between post/wait and polling
SQL> @pvalid _use_adaptive_log_file_sync
Display valid values for multioption parameters matching "_use_adaptive_log_file_sync"...
PAR# PARAMETER ORD VALUE DEFAULT
------ -------------------------------------------------- ---------- ------------------------------ -------
2710 _use_adaptive_log_file_sync 1 TRUE DEFAULT
_use_adaptive_log_file_sync 2 FALSE
_use_adaptive_log_file_sync 3 POLLING_ONLY
_use_adaptive_log_file_sync有3个值:true,false,polling_only.
[oracle@db1 ~]$ gdb /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle -p 2227858
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-20.0.2.el8
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle...(no debugging symbols found)...done.
Attaching to program: /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle, process 2227858
ptrace: Operation not permitted.
(gdb)
-- oracle 用户没有注册成功
[oracle@db1 ~]$ cat /proc/sys/kernel/yama/ptrace_scope
0
[oracle@db1 ~]$ cat /proc/2227858/status | grep TracerPid
TracerPid: 0
[oracle@db1 ~]$ getenforce
Disabled
[oracle@db1 ~]$ ps -o pid,user,euid,ruid,comm -p 2227858
PID USER EUID RUID COMMAND
2227858 oracle 54323 54323 ora_mmon_anbob
[oracle@db1 ~]$ grep -E 'CoreDumping|Seccomp|TracerPid|Threads|Cap' /proc/2227858/status
TracerPid: 0
CoreDumping: 0
Threads: 1
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 000001ffffffffff
CapAmb: 0000000000000000
Seccomp: 0
Seccomp_filters: 0
不确认是不是26ai不允许oracle还是当前的OS配置问题,改为root 用户执行.
[root@db1 ~]# gdb /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle -p 2227858
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-20.0.2.el8
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
(gdb) p (uint32_t) kcrf_alfs_info_+0
$2 = 1
(gdb)
(gdb) info proc mappings
process 2227858
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x400000 0xf7c000 0xb7c000 0x0 /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle
0x1000000 0x19600000 0x18600000 0xc00000 /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle
0x19600000 0x19751000 0x151000 0x19200000 /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle
0x19800000 0x1f2dc000 0x5adc000 0x19400000 /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle
0x1f684000 0x1f800000 0x17c000 0x1f084000 /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle
0x1f800000 0x1f853000 0x53000 0x1f200000 /u01/app/oracle/product/26.0.0/dbhome_1/bin/oracle
0x1f853000 0x1f8af000 0x5c000 0x0
0x217d2000 0x2188a000 0xb8000 0x0 [heap]
可见默认值为1, 改参数_use_adaptive_log_file_sync
SQL> alter system set "_use_adaptive_log_file_sync"=false;
System altered.
SQL> exit
Disconnected from Oracle AI Database 26ai Enterprise Edition Release 23.26.1.0.0 - Production
(gdb) p (uint32_t) kcrf_alfs_info_+0
$1 = 0
SQL> alter system set "_use_adaptive_log_file_sync"=true;
System altered.
(gdb) p (uint32_t) kcrf_alfs_info_+0
$2 = 1
SQL> alter system set "_use_adaptive_log_file_sync"=polling_only;
System altered.
(gdb) p (uint32_t) kcrf_alfs_info_+0
$3 = 1
小结:
oracle adaptive log file sync的特性改参数为true是并不一定是polling,而是打开了开adaptive开关,有oracle判断用post还是polling, 改参数为false时会永久使用post模式。通过系统统计信息和lgwr trace文件中可以看到是否在使用过polling。也可以使用GDB工具,打印用个Oracle 进程中的kcrf_alfs_info_+0变量来判断当前使用哪种模式。