SlideShare a Scribd company logo
还原 Oracle 中真实的
 Cache Recovery


    by Maclean.liu
          liu.maclean@gmail.com
      www.oracledatabase12g.com
About Me

l Email:liu.maclean@gmail.com
l Blog:www.oracledatabase12g.com
l Oracle Certified Database Administrator Master 10g
and 11g
l Over 6 years experience with Oracle DBA technology
l Over 7 years experience with Linux technology
l Member Independent Oracle Users Group
l Member All China Users Group
l Presents for advanced Oracle topics: RAC,
DataGuard, Performance Tuning and Oracle Internal.
我们在学习 Oracle 基础知识的时候会了解到实例恢复(Instance Recovery)或者说崩溃恢复
(Crash recovery)的概念,有时候甚至于这 2 个名词在我们日常的语言中表达同样的意思。实
际上 Instance Recovery 与 Crash Recovery 是存在区别的:针对单实例(single instance)或者
RAC 中所有节点全部崩溃后的恢复,我们称之为 Crash Recovery。而对于 RAC 中的某一个
节点失败,存活节点(surviving instance)试图对失败节点线程上 redo 做应用的情况,我们称之
为 Instance Recovery。


不管是 Instance Recovery 还是 Crash Recovery,都由 2 个部分组成:cache recovery 继以
transaction recovery。


根据官方文档的 介绍,Cache Recovery 也叫 Rolling Forward,就是我们常说的前滚;而
Transaction Recovery 也叫 Rolling Back,就是我们常说的回滚。前滚和回滚贯穿 Oracle 恢复
的基本概念,是我们入门必要学习的知识,在次不多介绍。

有文事者,必济之以武略。理论学得再好,不实践也无用。所幸 Crash Recovery 是很容易做
成的实验,我们不妨来看一看:



SQL> shutdown abort;
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1065353216 bytes
Fixed Size                  2089336 bytes
Variable Size             486542984 bytes
Database Buffers          570425344 bytes
Redo Buffers                6295552 bytes
Database mounted.

SQL> alter database open;

Crash Recovery 将从 alter database open 开始,我们来观察其日志

==================alert.log====================
alter database open
Tue Jun 14 18:19:53 2011
Beginning crash recovery of 1 threads
 parallel recovery started with 2 processes
Tue Jun 14 18:19:53 2011
Started redo scan
Tue Jun 14 18:19:53 2011
Completed redo scan
 0 redo blocks read, 0 data blocks need recovery
Tue Jun 14 18:19:53 2011
Started redo application at
 Thread 1: logseq 1004, block 1124, scn 17136185
Tue Jun 14 18:19:53 2011
Recovery of Online Redo Log: Thread 1 Group 2 Seq 1004 Reading mem 0
 Mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_2_6v34jokt_.log
 Mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_2_6v34jotq_.log
Tue Jun 14 18:19:53 2011
Completed redo application
Tue Jun 14 18:19:53 2011
Completed crash recovery at
 Thread 1: logseq 1004, block 1124, scn 17156186
 0 data blocks read, 0 data blocks written, 0 redo blocks read
Tue Jun 14 18:19:53 2011
LGWR: STARTING ARCH PROCESSES
ARC0: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC0 started with pid=16, OS id=7829
Tue Jun 14 18:19:53 2011
Thread 1 advanced to log sequence 1005 (thread open)
Thread 1 opened at log sequence 1005
 Current log# 3 seq# 1005 mem# 0:
/flashcard/oradata/G10R2/onlinelog/o1_mf_3_6v34jpmp_.log
 Current log# 3 seq# 1005 mem# 1:
/s01/flash_recovery_area/G10R2/onlinelog/o1_mf_3_6v34jpyn_.log
Successful open of redo thread 1
Tue Jun 14 18:19:53 2011
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
ARC0: Becoming the heartbeat ARCH
Tue Jun 14 18:19:53 2011
SMON: enabling cache recovery
Tue Jun 14 18:19:53 2011
db_recovery_file_dest_size of 204800 MB is 6.81% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Tue Jun 14 18:19:54 2011
Successfully onlined Undo Tablespace 1.
Tue Jun 14 18:19:54 2011
SMON: enabling tx recovery
Database Characterset is UTF8
Opening with internal Resource Manager plan
where NUMA PG = 1, CPUs = 2
replication_dependency_tracking turned off (no async multimaster replication
found)
Starting background process QMNC
QMNC started with pid=17, OS id=7831
Tue Jun 14 18:19:55 2011
Completed: alter database open
注意上述单实例 Crash Recovery 到数据库打开的整个过程:
   •   alter database open
   •   Beginning crash recovery of 1 threads
   •   Started redo scan
   •   Completed redo scan
   •   Started redo application at
   •   Completed redo application
   •   Completed crash recovery at
   •   SMON: enabling cache recovery
   •   Successfully onlined Undo Tablespace 1
   •   SMON: enabling tx recovery
   •   Completed: alter database open

从上述步骤中我们可以看到三种恢复名词,即:
   • crash recovery
   • cache recovery
   • tx recovery




这和官方文档所描述的 Crash Recovery 概念是不一致的,我们现在来理清这几种 recovery。


crash recovery 包含对 redo 的 scan 和 application,显然其完成的是 Rolling Forward 前滚的工
作,告警日志中出现的 crash recovery 等同于官方文档中介绍的”cache recovery”,我们可以
将” Completed crash recovery”看做前滚完成的标志。而 tx recovery 从字面就可以看出实际上
是 Transaction Recovery,tx recovery 发生在 Undo Tablespace online 之后(回滚事务的前提是
Undo 可用),数据完成打开操作之前(“Completed: alter database open”)。注意 tx recovery 并不
要求数据库打开前完成,仅仅是在数据库打开之前由 smon 启动(“SMON: enabling tx
recovery”)。


剩下的唯一的问题是,这里的 cache recovery 是什么?显然它不是官方文档中所描述的”cache
recovery”,几乎没有任何文档介绍存在这样一个 recovery 操作,这也是本文重点要介绍的。
我们来看另一个演示,这个演示用以说明 cache recovery 还存在于最普通的不包含 Crash
Recovery 的数据库打开过程中:


SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.
Total System Global Area 1065353216 bytes
Fixed Size                  2089336 bytes
Variable Size             486542984 bytes
Database Buffers          570425344 bytes
Redo Buffers                6295552 bytes
Database mounted.

SQL> alter database open;
Database altered.

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
www.oracledatabase12g.com

==================alert.log====================
alter database open
Tue Jun 14 18:43:52 2011
LGWR: STARTING ARCH PROCESSES
ARC0: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC0 started with pid=14, OS id=8133
Tue Jun 14 18:43:52 2011
Thread 1 opened at log sequence 1005
Current log# 3 seq# 1005 mem# 0:
/flashcard/oradata/G10R2/onlinelog/o1_mf_3_6v34jpmp_.log
Current log# 3 seq# 1005 mem# 1:
/s01/flash_recovery_area/G10R2/onlinelog/o1_mf_3_6v34jpyn_.log
Successful open of redo thread 1
Tue Jun 14 18:43:52 2011
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
ARC0: Becoming the heartbeat ARCH
Tue Jun 14 18:43:52 2011
SMON: enabling cache recovery
Tue Jun 14 18:43:53 2011
Successfully onlined Undo Tablespace 1.
Tue Jun 14 18:43:53 2011
SMON: enabling tx recovery
Database Characterset is UTF8
Opening with internal Resource Manager plan
where NUMA PG = 1, CPUs = 2
replication_dependency_tracking turned off (no async multimaster replication
found)
Tue Jun 14 18:43:53 2011
Incremental checkpoint up to RBA [0x3ed.624.0], current log tail at RBA
[0x3ed.944.0]
Tue Jun 14 18:43:53 2011
Starting background process QMNC
QMNC started with pid=15, OS id=8135
Tue Jun 14 18:43:53 2011
Completed: alter database open


因为是 clean shutdown,所以这里不存在 crash recovery。但这里同样出现了”SMON: enabling
cache recovery”,可见 cache recovery 是每次实例启动 instance startup 必要执行的一种恢复操
作。但问题是,这个恢复操作到底针对何种对象?

实际上 cache recovery 所要恢复的是 rowcache,也就是我们常说的字典缓存(dictionary
cache)。关于这个结论,肯定有很多人要问我这样说的依据是什么,对应于这个”cache
recovery”的问题,我们很难从 google 中得到一些启示,因为它和官方文档所描述的”cache
recovery-rolling forward”存在重名的关系。

为了证明 cache recovery 所恢复的是 rowcache,我们需要一个实证,从正式的系统中得到验
证。要做到这一点是比较困难的,我们需要 Oracle 愿意把整个 database open 的过程变成慢
动作来供我们参考,验证要用到一些调试工具,例如 gdb 或者 dbx。

我们首先将实例启动到 mount 状态,并对执行 startup 的 LOCAL 进程做 gdb 的 breakpoint 断
点调试:



SQL> shutdown abort;
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.
Total System Global Area 1065353216 bytes
Fixed Size                  2089336 bytes
Variable Size             486542984 bytes
Database Buffers          570425344 bytes
Redo Buffers                6295552 bytes
Database mounted.

找出 LOCAL 进程的系统进程号 SPID

SQL> select spid from v$process
2 where addr in (
3 select paddr from v$session
4 where sid=(select distinct sid from v$mystat))
5 /

SPID
------------
8326

在实例 startup nomount/mount 后共享池的 library cache 就是可用的
SQL> select namespace from v$librarycache where gets!=0;

NAMESPACE
---------------
SQL AREA
TABLE/PROCEDURE

而 rowcache 则尚未被填充,因为字典缓存来源于自举对象(bootstrap$)和字典基表
SQL> select parameter,count,gets from v$rowcache where count!=0;
no rows selected

另开一个 terminal 窗口,并执行对 LOCAL 进程 8326 的 gdb breakpoint 调试
[oracle@rh2 ~]$ gdb $ORACLE_HOME/bin/oracle 8326
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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".
For bug reporting instructions, please see:
...
Reading symbols from /s01/db_1/bin/oracle...(no debugging symbols found)...done.
Attaching to program: /s01/db_1/bin/oracle, process 8326
Reading symbols from /s01/db_1/lib/libskgxp10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libskgxp10.so
Reading symbols from /s01/db_1/lib/libhasgen10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libhasgen10.so
Reading symbols from /s01/db_1/lib/libskgxn2.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libskgxn2.so
Reading symbols from /s01/db_1/lib/libocr10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libocr10.so
Reading symbols from /s01/db_1/lib/libocrb10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libocrb10.so
Reading symbols from /s01/db_1/lib/libocrutl10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libocrutl10.so
Reading symbols from /s01/db_1/lib/libjox10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libjox10.so
Reading symbols from /s01/db_1/lib/libclsra10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libclsra10.so
Reading symbols from /s01/db_1/lib/libdbcfg10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libdbcfg10.so
Reading symbols from /s01/db_1/lib/libnnz10.so...(no debugging symbols
found)...done.
Loaded symbols for /s01/db_1/lib/libnnz10.so
Reading symbols from /usr/lib64/libaio.so.1...(no debugging symbols
found)...done.
Loaded symbols for /usr/lib64/libaio.so.1
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols
found)...done.
[Thread debugging using libthread_db enabled]
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnsl.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols
found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols
found)...done.
Loaded symbols for /lib64/libnss_files.so.2
0x0000003181a0d8e0 in __read_nocancel () from /lib64/libpthread.so.0

输入断点 kcrf_commit_force 和 kqlobjlod
(gdb) break kcrf_commit_force
Breakpoint 1 at 0x2724b6c

(gdb) break kqlobjlod
Breakpoint 2 at 0x1ac5e8c

在之前的 terminal 中执行数据库打开操作,因为 breakpoint 的关系这个 open 操作会
hang 住,
这时我们通过观察告警日志来了解恢复进度

SQL> alter database open;                              --这里会 hang 住

在 gdb 下输入 continue,
(gdb) c
Continuing.

Breakpoint 1, 0x0000000002724b6c in kcrf_commit_force ()

观察告警日志可以发现 redo application 已经完成,但还未进入 cache recovery 阶
段
alter database open
Tue Jun 14 19:14:33 2011
Beginning crash recovery of 1 threads
parallel recovery started with 2 processes
Tue Jun 14 19:14:33 2011
Started redo scan
Tue Jun 14 19:14:33 2011
Completed redo scan
39 redo blocks read, 74 data blocks need recovery
Tue Jun 14 19:14:33 2011
Started redo application at
Thread 1: logseq 1006, block 1155
Tue Jun 14 19:14:33 2011
Recovery of Online Redo Log: Thread 1 Group 1 Seq 1006 Reading mem 0
Mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_1_6v34jnkn_.log
Mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_1_6v34jnst_.log
Tue Jun 14 19:14:33 2011
Completed redo application
Tue Jun 14 19:14:33 2011
Completed crash recovery at
Thread 1: logseq 1006, block 1194, scn 17200193
74 data blocks read, 74 data blocks written, 39 redo blocks read
Tue Jun 14 19:14:33 2011
LGWR: STARTING ARCH PROCESSES
ARC0: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC0 started with pid=17, OS id=8656
Tue Jun 14 19:14:33 2011
Thread 1 advanced to log sequence 1007 (thread open)
Thread 1 opened at log sequence 1007
Current log# 2 seq# 1007 mem# 0:
/flashcard/oradata/G10R2/onlinelog/o1_mf_2_6v34jokt_.log
Current log# 2 seq# 1007 mem# 1:
/s01/flash_recovery_area/G10R2/onlinelog/o1_mf_2_6v34jotq_.log
Successful open of redo thread 1
Tue Jun 14 19:14:33 2011
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
ARC0: Becoming the heartbeat ARCH
db_recovery_file_dest_size of 204800 MB is 6.81% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Tue Jun 14 19:14:37 2011
Incremental checkpoint up to RBA [0x3ef.3.0], current log tail at RBA
[0x3ef.3.0]

且此时 rowcache 仍未被填充
SQL> select parameter,count,gets from v$rowcache where count!=0;
no rows selected

在 gdb 界面下再次执行 continue 2 次
(gdb) c
Continuing.

Breakpoint 1, 0x0000000002724b6c in kcrf_commit_force ()
(gdb) c
Continuing.

Breakpoint 2, 0x0000000001ac5e8c in kqlobjlod ()

观察告警日志可以发现已开始 cache recovery,但也卡陷在 cache recovery 上,这保
证我们的演示不受骚扰
Tue Jun 14 19:16:44 2011
SMON: enabling cache recovery

此时 rowcache 中出现唯一的一个 dc_objects 对象
select parameter,count,gets from v$rowcache where count!=0;

PARAMETER                             COUNT       GETS
-------------------------------- ---------- ----------
dc_objects                                1          1
这个对象是什么呢?也许你已经猜到了,我们做一个 rowcache dump 来看一下:
SQL> ALTER SESSION SET EVENTS 'immediate trace name row_cache level 10';

================row_cache trace===================

BUCKET 43170:
row cache parent object: address=0x92326060 cid=8(dc_objects)
hash=f3d1a8a1 typ=11 transaction=(nil) flags=00000001
own=0x92326130[0x9230f628,0x9230f628] wat=0x92326140[0x92326140,0x92326140]
mode=S
status=EMPTY/-/-/-/-/-/-/-/-
set=0, complete=FALSE
data=
00000000 4f42000a 5453544f 24504152 00000000 00000000 00000000 00000000
00000000 00000001 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
BUCKET 43170 total object count=1

可以看到上述 dc_objects 尚未完成加载(status=EMPTY & complete=FALSE ),那
么这是一个什么 object 呢?

4f42000a 5453544f 24504152 => 转换为文本即:OB TSTO$PAR 也就是
BOOTSTRAP$

换而言之在 cache recovery 时第一个恢复的字典缓存对象是 BOOTSTRAP$,这并不出乎
我们的意料。

启动实例的 LOCAL 进程的等待事件为 instance state change,这是常规情况下我们观
察不到得
SQL> select event,p1text,p1 from v$session where wait_class!='Idle';

EVENT                                    P1TEXT
P1
----------------------------------------
---------------------------------------- ----------
instance state change                    layer
2

在 gdb 界面下再次 continue,将载入更多的 rowcache 对象
(gdb) c
Continuing.

Breakpoint 2, 0x0000000001ac5e8c in kqlobjlod ()

BUCKET 37:
row cache parent object: address=0x916cd980 cid=3(dc_rollback_segments)
hash=5fed2a24 typ=9 transaction=(nil) flags=000000a6
own=0x916cda50[0x916cda50,0x916cda50] wat=0x916cda60[0x916cda60,0x916cda60]
mode=N
status=VALID/INSERT/-/FIXED/-/-/-/-/-
data=
00000000 00000000 00000001 00000009 59530006 4d455453 00000000 00000000
00000000 00000000 00000000 00000000 00000003 00000000 00000000 00000000
00000000 00000000 00000000 00000000
BUCKET 37 total object count=1

595300064d455453 -> SYSTEM 属于 dc_rollback_segments 也就是著名的
system 回滚段
BUCKET 55556:
row cache parent object: address=0x916d8cd0 cid=8(dc_objects)
hash=ce89d903 typ=11 transaction=(nil) flags=00000001
own=0x916d8da0[0x9230f628,0x9230f628] wat=0x916d8db0[0x916d8db0,0x916d8db0]
mode=S
status=EMPTY/-/-/-/-/-/-/-/-
set=0, complete=FALSE
data=
00000000 5f430006 234a424f 00000000 00000000 00000000 00000000 00000000
00000000 00000005 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
BUCKET 55556 total object count=1

5f430006 234a424f -> C_OBJ# 是著名的 bootstrap 对象之一,可以从
$ORACLE_HOME/rdbms/admin/sql.bsq 中找到它
create rollback segment SYSTEM tablespace SYSTEM
storage (initial 50K next 50K)
/
create cluster c_obj# (obj# number)
pctfree 5 size 800                           /* don't waste too much space */
/* A table of 32 cols, 2 index, 2 col per index requires about 2K.
* A table of 10 cols, 2 index, 2 col per index requires about 750.
*/
storage (initial 130K next 200k maxextents unlimited pctincrease 0)
/* avoid space management during IOR I */
/

我们还可以通过 v$rowcache_parent 视图来了解 dictionary cache 的情况
SQL>   col cache_name for a20
SQL>   col keystr for a31
SQL>   set linesize 200
SQL>   select address,cache_name,existent,lock_mode,saddr,substr(key,1,30) keystr
from   v$rowcache_parent;

ADDRESS          CACHE_NAME             E LOCK_MODE SADDR             KEYSTR
---------------- --------------------   - ---------- ----------------
-------------------------------
00000000916CCE20 dc_tablespaces         N          0 00
000000000000000000000000000000
00000000916CD980 dc_rollback_segments   Y          0 00
000000000000000000000000000000
0000000092326060 dc_objects           Y          0 00
000000000A00424F4F545354524150
00000000916D8CD0 dc_objects           N          3 000000009BD91328
000000000600435F4F424A23000000
00000000916DA830 dc_object_ids        Y          0 00
380000000000000000000000000000

可以看到持有 row cache lock 的会话是'000000009BD91328',
且该 dc_objects 对象还处于 non-existent 状态,
换而言之真正装载 rowcache 的是启动实例的 LOCAL 服务进程

SQL> select sid,program,event,p1,p2,p3 from v$session where
saddr='000000009BD91328';

SID PROGRAM                                          EVENT
P1   P2 P3
----- ------------------------------------------------
---------------------------------------- -- ---- --
3294 sqlplus@rh2.oracle.com (TNS V1-V3)                db file scattered read
1 378 3

该进程正在等待 db file scattered read,fileid->1,block-378,这些块属于
BOOTSTRAP$表

BOOTSTRAP$对象已从 rowcache 被载入到 library cache 中
SQL> select kglhdadr,kglnaobj from x$kglob where kglobtyp=2 and kglnaobj not
like 'X$%';

KGLHDADR             KGLNAOBJ
-------------------- --------------------
0000000092326990     BOOTSTRAP$

SQL> select owner||'.'||Name from v$db_object_cache where type='TABLE' and name
not like 'X$%';

OWNER||'.'||NAME
--------------------------------------------------------------------------------
SYS.BOOTSTRAP$


初步总结:

   1. 在数据库正式 open 前需要恢复字典缓存,这个步骤被称为 cache recovery,其实是
     row cache recovery。与官方文档中描述的”cache recovery”不同,row cache recovery
     应当是 Oracle Internal 的叫法。
   2. 实际执行 row cache recovery 的不是 SMON 进程,而是启动实例的服务进程

More Related Content

PDF
Oracle 11g R2 RAC setup on rhel 5.0
PDF
Beginbackup
PDF
Upgrade 11.2.0.1 rac db to 11.2.0.2 in linux
PPT
Oracle Golden Gate
PDF
Upgrade 11.2.0.1 gi crs to 11.2.0.2 in linux
PPT
Oracle 10g Performance: chapter 00 statspack
PDF
Redo internals ppt
DOC
Oracle applications 11i hot backup cloning with rapid clone
Oracle 11g R2 RAC setup on rhel 5.0
Beginbackup
Upgrade 11.2.0.1 rac db to 11.2.0.2 in linux
Oracle Golden Gate
Upgrade 11.2.0.1 gi crs to 11.2.0.2 in linux
Oracle 10g Performance: chapter 00 statspack
Redo internals ppt
Oracle applications 11i hot backup cloning with rapid clone

What's hot (20)

PDF
Oracle applications 11i hot backup cloning with rapid clone
PDF
Oracle goldengate 11g schema replication from standby database
PDF
Advanced rac troubleshooting
DOCX
Rac questions
PPT
Upgrade 11gR2 to 12cR1 Clusterware
PPT
Oracle 10g Performance: chapter 09 enqueues
PDF
你所不知道的Oracle后台进程Smon功能
PDF
配置Golden gate同步ddl语句
PDF
MySQL as a Document Store
PDF
MySQL Replication Update -- Zendcon 2016
PDF
MySQL Replication Basics -Ohio Linux Fest 2016
PPT
UKOUG, Oracle Transaction Locks
PPT
Oracle12c Pluggable Database Hands On - TROUG 2014
PDF
A kind and gentle introducton to rac
DOC
Upgrade 10204-to-10205 on-2-node_rac_linux_x86_64_detail-steps_v0.1
PPSX
RAC - The Savior of DBA
PDF
The first bug on Oracle Database 12c: how to create a pdb by cloning a remote...
PPSX
Oracle 11g R2 RAC implementation and concept
PPT
Oracle 10g Performance: chapter 00 sampling
PDF
Oracle Database Management Basic 1
Oracle applications 11i hot backup cloning with rapid clone
Oracle goldengate 11g schema replication from standby database
Advanced rac troubleshooting
Rac questions
Upgrade 11gR2 to 12cR1 Clusterware
Oracle 10g Performance: chapter 09 enqueues
你所不知道的Oracle后台进程Smon功能
配置Golden gate同步ddl语句
MySQL as a Document Store
MySQL Replication Update -- Zendcon 2016
MySQL Replication Basics -Ohio Linux Fest 2016
UKOUG, Oracle Transaction Locks
Oracle12c Pluggable Database Hands On - TROUG 2014
A kind and gentle introducton to rac
Upgrade 10204-to-10205 on-2-node_rac_linux_x86_64_detail-steps_v0.1
RAC - The Savior of DBA
The first bug on Oracle Database 12c: how to create a pdb by cloning a remote...
Oracle 11g R2 RAC implementation and concept
Oracle 10g Performance: chapter 00 sampling
Oracle Database Management Basic 1
Ad

Viewers also liked (20)

PPT
Workflow, Revisioning and Rules in Drupal
PDF
Diverse recruitment
PPT
Evaluating my magazine
PPTX
Leadership for Justice Peace Safety and Security
PDF
04. b. salinan lampiran permendikbud no. 66 th 2013 tentang standar penilaian
PDF
Permen tahun2013 nomor81a_lampiran1
PPTX
ETL 523 Presentation: The Digital Divide
PDF
Oracle prm数据库恢复工具与asm
PDF
Kisi-kisi Materi PLPG IPA SMP
PDF
What if I can design my care?
PDF
CSS3
PPTX
Aditya meshram Bday PPT
PPTX
Que hago y_como_vivo
PPTX
2 clasificación de los ángulos
PPTX
20151116ケアワークアカデミー資料
PDF
04. a. salinan permendikbud no. 66 th 2013 ttg standar penilaian
PPT
Cross-sectoral innovation in Smart Homes
PDF
了解真实的Oracle unbreakable database appliance
PPT
Internet Librarian :: Libraries, Ebooks & Econtent
PDF
03. b. salinan lampiran permendikbud no. 65 th 2013 ttg standar proses
Workflow, Revisioning and Rules in Drupal
Diverse recruitment
Evaluating my magazine
Leadership for Justice Peace Safety and Security
04. b. salinan lampiran permendikbud no. 66 th 2013 tentang standar penilaian
Permen tahun2013 nomor81a_lampiran1
ETL 523 Presentation: The Digital Divide
Oracle prm数据库恢复工具与asm
Kisi-kisi Materi PLPG IPA SMP
What if I can design my care?
CSS3
Aditya meshram Bday PPT
Que hago y_como_vivo
2 clasificación de los ángulos
20151116ケアワークアカデミー資料
04. a. salinan permendikbud no. 66 th 2013 ttg standar penilaian
Cross-sectoral innovation in Smart Homes
了解真实的Oracle unbreakable database appliance
Internet Librarian :: Libraries, Ebooks & Econtent
03. b. salinan lampiran permendikbud no. 65 th 2013 ttg standar proses
Ad

Similar to 还原Oracle中真实的cache recovery (20)

DOC
br_test_lossof-datafile_10g.doc
DOCX
Backup and Restore of database on 2-Node RAC
DOCX
Backup and Recovery
PDF
Completerecovery
PDF
576 oracle-dba-interview-questions
TXT
oracle dba
PDF
Backup andrecoverychecklist
PDF
Backup andrecoverychecklist
TXT
Oracle ORA Errors
PDF
Hotsos 2017 - Protect or Perform by Paul G. Matuszyk
DOCX
Rman cloning when both directory and db name are same.
DOCX
Rman cloning when both directory and db name are same.
DOCX
Oracle dba interview questions with answer
PDF
DB2 LUW - Backup and Recovery
PPT
Les 06 Perform Rec
PDF
Rman workshop short
PDF
2008 Collaborate IOUG Presentation
DOCX
Oracle 19c initialization parameters
PDF
Oracle-DBA-Interview-Question- For experience DBA
PDF
Profiling of Oracle Function Calls
br_test_lossof-datafile_10g.doc
Backup and Restore of database on 2-Node RAC
Backup and Recovery
Completerecovery
576 oracle-dba-interview-questions
oracle dba
Backup andrecoverychecklist
Backup andrecoverychecklist
Oracle ORA Errors
Hotsos 2017 - Protect or Perform by Paul G. Matuszyk
Rman cloning when both directory and db name are same.
Rman cloning when both directory and db name are same.
Oracle dba interview questions with answer
DB2 LUW - Backup and Recovery
Les 06 Perform Rec
Rman workshop short
2008 Collaborate IOUG Presentation
Oracle 19c initialization parameters
Oracle-DBA-Interview-Question- For experience DBA
Profiling of Oracle Function Calls

More from maclean liu (20)

PDF
Mysql企业备份发展及实践
PDF
Oracle専用データ復旧ソフトウェアprm dulユーザーズ・マニュアル
PDF
【诗檀软件 郭兆伟-技术报告】跨国企业级Oracle数据库备份策略
PDF
基于Oracle 12c data guard & far sync的低资源消耗两地三数据中心容灾方案
PDF
TomCat迁移步骤简述以及案例
PDF
PRM DUL Oracle Database Health Check
PDF
dbdao.com 汪伟华 my-sql-replication复制高可用配置方案
DOCX
Vbox virtual box在oracle linux 5 - shoug 梁洪响
PDF
【诗檀软件】Mysql高可用方案
PPTX
Shoug at apouc2015 4min pitch_biotwang_v2
PPTX
Apouc 4min pitch_biotwang_v2
PDF
使用Oracle osw analyzer工具分析oswbb日志,并绘制系统性能走势图1
PDF
诗檀软件 Oracle开发优化基础
PDF
Orclrecove 1 pd-prm-dul testing for oracle database recovery_20141030_biot_wang
PDF
诗檀软件 – Oracle数据库修复专家 oracle数据块损坏知识2014-10-24
PDF
追求Jdbc on oracle最佳性能?如何才好?
PDF
使用Virtual box在oracle linux 5.7上安装oracle database 11g release 2 rac的最佳实践
PDF
Prm dul is an oracle database recovery tool database
PDF
Oracle prm dul, jvm and os
PDF
Oracle dba必备技能 使用os watcher工具监控系统性能负载
Mysql企业备份发展及实践
Oracle専用データ復旧ソフトウェアprm dulユーザーズ・マニュアル
【诗檀软件 郭兆伟-技术报告】跨国企业级Oracle数据库备份策略
基于Oracle 12c data guard & far sync的低资源消耗两地三数据中心容灾方案
TomCat迁移步骤简述以及案例
PRM DUL Oracle Database Health Check
dbdao.com 汪伟华 my-sql-replication复制高可用配置方案
Vbox virtual box在oracle linux 5 - shoug 梁洪响
【诗檀软件】Mysql高可用方案
Shoug at apouc2015 4min pitch_biotwang_v2
Apouc 4min pitch_biotwang_v2
使用Oracle osw analyzer工具分析oswbb日志,并绘制系统性能走势图1
诗檀软件 Oracle开发优化基础
Orclrecove 1 pd-prm-dul testing for oracle database recovery_20141030_biot_wang
诗檀软件 – Oracle数据库修复专家 oracle数据块损坏知识2014-10-24
追求Jdbc on oracle最佳性能?如何才好?
使用Virtual box在oracle linux 5.7上安装oracle database 11g release 2 rac的最佳实践
Prm dul is an oracle database recovery tool database
Oracle prm dul, jvm and os
Oracle dba必备技能 使用os watcher工具监控系统性能负载

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PPTX
A Presentation on Artificial Intelligence
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Big Data Technologies - Introduction.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
A Presentation on Artificial Intelligence
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Big Data Technologies - Introduction.pptx
Approach and Philosophy of On baking technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Per capita expenditure prediction using model stacking based on satellite ima...

还原Oracle中真实的cache recovery

  • 1. 还原 Oracle 中真实的 Cache Recovery by Maclean.liu liu.maclean@gmail.com www.oracledatabase12g.com
  • 2. About Me l Email:liu.maclean@gmail.com l Blog:www.oracledatabase12g.com l Oracle Certified Database Administrator Master 10g and 11g l Over 6 years experience with Oracle DBA technology l Over 7 years experience with Linux technology l Member Independent Oracle Users Group l Member All China Users Group l Presents for advanced Oracle topics: RAC, DataGuard, Performance Tuning and Oracle Internal.
  • 3. 我们在学习 Oracle 基础知识的时候会了解到实例恢复(Instance Recovery)或者说崩溃恢复 (Crash recovery)的概念,有时候甚至于这 2 个名词在我们日常的语言中表达同样的意思。实 际上 Instance Recovery 与 Crash Recovery 是存在区别的:针对单实例(single instance)或者 RAC 中所有节点全部崩溃后的恢复,我们称之为 Crash Recovery。而对于 RAC 中的某一个 节点失败,存活节点(surviving instance)试图对失败节点线程上 redo 做应用的情况,我们称之 为 Instance Recovery。 不管是 Instance Recovery 还是 Crash Recovery,都由 2 个部分组成:cache recovery 继以 transaction recovery。 根据官方文档的 介绍,Cache Recovery 也叫 Rolling Forward,就是我们常说的前滚;而 Transaction Recovery 也叫 Rolling Back,就是我们常说的回滚。前滚和回滚贯穿 Oracle 恢复 的基本概念,是我们入门必要学习的知识,在次不多介绍。 有文事者,必济之以武略。理论学得再好,不实践也无用。所幸 Crash Recovery 是很容易做 成的实验,我们不妨来看一看: SQL> shutdown abort; ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 1065353216 bytes Fixed Size 2089336 bytes Variable Size 486542984 bytes Database Buffers 570425344 bytes Redo Buffers 6295552 bytes Database mounted. SQL> alter database open; Crash Recovery 将从 alter database open 开始,我们来观察其日志 ==================alert.log==================== alter database open Tue Jun 14 18:19:53 2011 Beginning crash recovery of 1 threads parallel recovery started with 2 processes Tue Jun 14 18:19:53 2011 Started redo scan Tue Jun 14 18:19:53 2011 Completed redo scan 0 redo blocks read, 0 data blocks need recovery Tue Jun 14 18:19:53 2011 Started redo application at Thread 1: logseq 1004, block 1124, scn 17136185
  • 4. Tue Jun 14 18:19:53 2011 Recovery of Online Redo Log: Thread 1 Group 2 Seq 1004 Reading mem 0 Mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_2_6v34jokt_.log Mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_2_6v34jotq_.log Tue Jun 14 18:19:53 2011 Completed redo application Tue Jun 14 18:19:53 2011 Completed crash recovery at Thread 1: logseq 1004, block 1124, scn 17156186 0 data blocks read, 0 data blocks written, 0 redo blocks read Tue Jun 14 18:19:53 2011 LGWR: STARTING ARCH PROCESSES ARC0: Archival started LGWR: STARTING ARCH PROCESSES COMPLETE ARC0 started with pid=16, OS id=7829 Tue Jun 14 18:19:53 2011 Thread 1 advanced to log sequence 1005 (thread open) Thread 1 opened at log sequence 1005 Current log# 3 seq# 1005 mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_3_6v34jpmp_.log Current log# 3 seq# 1005 mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_3_6v34jpyn_.log Successful open of redo thread 1 Tue Jun 14 18:19:53 2011 ARC0: Becoming the 'no FAL' ARCH ARC0: Becoming the 'no SRL' ARCH ARC0: Becoming the heartbeat ARCH Tue Jun 14 18:19:53 2011 SMON: enabling cache recovery Tue Jun 14 18:19:53 2011 db_recovery_file_dest_size of 204800 MB is 6.81% used. This is a user-specified limit on the amount of space that will be used by this database for recovery-related files, and does not reflect the amount of space available in the underlying filesystem or ASM diskgroup. Tue Jun 14 18:19:54 2011 Successfully onlined Undo Tablespace 1. Tue Jun 14 18:19:54 2011 SMON: enabling tx recovery Database Characterset is UTF8 Opening with internal Resource Manager plan where NUMA PG = 1, CPUs = 2 replication_dependency_tracking turned off (no async multimaster replication found) Starting background process QMNC QMNC started with pid=17, OS id=7831 Tue Jun 14 18:19:55 2011 Completed: alter database open
  • 5. 注意上述单实例 Crash Recovery 到数据库打开的整个过程: • alter database open • Beginning crash recovery of 1 threads • Started redo scan • Completed redo scan • Started redo application at • Completed redo application • Completed crash recovery at • SMON: enabling cache recovery • Successfully onlined Undo Tablespace 1 • SMON: enabling tx recovery • Completed: alter database open 从上述步骤中我们可以看到三种恢复名词,即: • crash recovery • cache recovery • tx recovery 这和官方文档所描述的 Crash Recovery 概念是不一致的,我们现在来理清这几种 recovery。 crash recovery 包含对 redo 的 scan 和 application,显然其完成的是 Rolling Forward 前滚的工 作,告警日志中出现的 crash recovery 等同于官方文档中介绍的”cache recovery”,我们可以 将” Completed crash recovery”看做前滚完成的标志。而 tx recovery 从字面就可以看出实际上 是 Transaction Recovery,tx recovery 发生在 Undo Tablespace online 之后(回滚事务的前提是 Undo 可用),数据完成打开操作之前(“Completed: alter database open”)。注意 tx recovery 并不 要求数据库打开前完成,仅仅是在数据库打开之前由 smon 启动(“SMON: enabling tx recovery”)。 剩下的唯一的问题是,这里的 cache recovery 是什么?显然它不是官方文档中所描述的”cache recovery”,几乎没有任何文档介绍存在这样一个 recovery 操作,这也是本文重点要介绍的。
  • 6. 我们来看另一个演示,这个演示用以说明 cache recovery 还存在于最普通的不包含 Crash Recovery 的数据库打开过程中: SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 1065353216 bytes Fixed Size 2089336 bytes Variable Size 486542984 bytes Database Buffers 570425344 bytes Redo Buffers 6295552 bytes Database mounted. SQL> alter database open; Database altered. SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Linux: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production SQL> select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- www.oracledatabase12g.com ==================alert.log==================== alter database open Tue Jun 14 18:43:52 2011 LGWR: STARTING ARCH PROCESSES ARC0: Archival started LGWR: STARTING ARCH PROCESSES COMPLETE ARC0 started with pid=14, OS id=8133 Tue Jun 14 18:43:52 2011 Thread 1 opened at log sequence 1005 Current log# 3 seq# 1005 mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_3_6v34jpmp_.log Current log# 3 seq# 1005 mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_3_6v34jpyn_.log Successful open of redo thread 1 Tue Jun 14 18:43:52 2011 ARC0: Becoming the 'no FAL' ARCH ARC0: Becoming the 'no SRL' ARCH ARC0: Becoming the heartbeat ARCH Tue Jun 14 18:43:52 2011 SMON: enabling cache recovery Tue Jun 14 18:43:53 2011 Successfully onlined Undo Tablespace 1. Tue Jun 14 18:43:53 2011 SMON: enabling tx recovery
  • 7. Database Characterset is UTF8 Opening with internal Resource Manager plan where NUMA PG = 1, CPUs = 2 replication_dependency_tracking turned off (no async multimaster replication found) Tue Jun 14 18:43:53 2011 Incremental checkpoint up to RBA [0x3ed.624.0], current log tail at RBA [0x3ed.944.0] Tue Jun 14 18:43:53 2011 Starting background process QMNC QMNC started with pid=15, OS id=8135 Tue Jun 14 18:43:53 2011 Completed: alter database open 因为是 clean shutdown,所以这里不存在 crash recovery。但这里同样出现了”SMON: enabling cache recovery”,可见 cache recovery 是每次实例启动 instance startup 必要执行的一种恢复操 作。但问题是,这个恢复操作到底针对何种对象? 实际上 cache recovery 所要恢复的是 rowcache,也就是我们常说的字典缓存(dictionary cache)。关于这个结论,肯定有很多人要问我这样说的依据是什么,对应于这个”cache recovery”的问题,我们很难从 google 中得到一些启示,因为它和官方文档所描述的”cache recovery-rolling forward”存在重名的关系。 为了证明 cache recovery 所恢复的是 rowcache,我们需要一个实证,从正式的系统中得到验 证。要做到这一点是比较困难的,我们需要 Oracle 愿意把整个 database open 的过程变成慢 动作来供我们参考,验证要用到一些调试工具,例如 gdb 或者 dbx。 我们首先将实例启动到 mount 状态,并对执行 startup 的 LOCAL 进程做 gdb 的 breakpoint 断 点调试: SQL> shutdown abort; ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 1065353216 bytes Fixed Size 2089336 bytes Variable Size 486542984 bytes Database Buffers 570425344 bytes Redo Buffers 6295552 bytes Database mounted. 找出 LOCAL 进程的系统进程号 SPID SQL> select spid from v$process 2 where addr in ( 3 select paddr from v$session 4 where sid=(select distinct sid from v$mystat)) 5 / SPID
  • 8. ------------ 8326 在实例 startup nomount/mount 后共享池的 library cache 就是可用的 SQL> select namespace from v$librarycache where gets!=0; NAMESPACE --------------- SQL AREA TABLE/PROCEDURE 而 rowcache 则尚未被填充,因为字典缓存来源于自举对象(bootstrap$)和字典基表 SQL> select parameter,count,gets from v$rowcache where count!=0; no rows selected 另开一个 terminal 窗口,并执行对 LOCAL 进程 8326 的 gdb breakpoint 调试 [oracle@rh2 ~]$ gdb $ORACLE_HOME/bin/oracle 8326 GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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". For bug reporting instructions, please see: ... Reading symbols from /s01/db_1/bin/oracle...(no debugging symbols found)...done. Attaching to program: /s01/db_1/bin/oracle, process 8326 Reading symbols from /s01/db_1/lib/libskgxp10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libskgxp10.so Reading symbols from /s01/db_1/lib/libhasgen10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libhasgen10.so Reading symbols from /s01/db_1/lib/libskgxn2.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libskgxn2.so Reading symbols from /s01/db_1/lib/libocr10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libocr10.so Reading symbols from /s01/db_1/lib/libocrb10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libocrb10.so Reading symbols from /s01/db_1/lib/libocrutl10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libocrutl10.so Reading symbols from /s01/db_1/lib/libjox10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libjox10.so Reading symbols from /s01/db_1/lib/libclsra10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libclsra10.so Reading symbols from /s01/db_1/lib/libdbcfg10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libdbcfg10.so Reading symbols from /s01/db_1/lib/libnnz10.so...(no debugging symbols found)...done. Loaded symbols for /s01/db_1/lib/libnnz10.so Reading symbols from /usr/lib64/libaio.so.1...(no debugging symbols
  • 9. found)...done. Loaded symbols for /usr/lib64/libaio.so.1 Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done. Loaded symbols for /lib64/libdl.so.2 Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done. Loaded symbols for /lib64/libm.so.6 Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done. [Thread debugging using libthread_db enabled] Loaded symbols for /lib64/libpthread.so.0 Reading symbols from /lib64/libnsl.so.1...(no debugging symbols found)...done. Loaded symbols for /lib64/libnsl.so.1 Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done. Loaded symbols for /lib64/libc.so.6 Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done. Loaded symbols for /lib64/libnss_files.so.2 0x0000003181a0d8e0 in __read_nocancel () from /lib64/libpthread.so.0 输入断点 kcrf_commit_force 和 kqlobjlod (gdb) break kcrf_commit_force Breakpoint 1 at 0x2724b6c (gdb) break kqlobjlod Breakpoint 2 at 0x1ac5e8c 在之前的 terminal 中执行数据库打开操作,因为 breakpoint 的关系这个 open 操作会 hang 住, 这时我们通过观察告警日志来了解恢复进度 SQL> alter database open; --这里会 hang 住 在 gdb 下输入 continue, (gdb) c Continuing. Breakpoint 1, 0x0000000002724b6c in kcrf_commit_force () 观察告警日志可以发现 redo application 已经完成,但还未进入 cache recovery 阶 段 alter database open Tue Jun 14 19:14:33 2011 Beginning crash recovery of 1 threads parallel recovery started with 2 processes Tue Jun 14 19:14:33 2011 Started redo scan Tue Jun 14 19:14:33 2011 Completed redo scan 39 redo blocks read, 74 data blocks need recovery Tue Jun 14 19:14:33 2011 Started redo application at Thread 1: logseq 1006, block 1155 Tue Jun 14 19:14:33 2011 Recovery of Online Redo Log: Thread 1 Group 1 Seq 1006 Reading mem 0 Mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_1_6v34jnkn_.log
  • 10. Mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_1_6v34jnst_.log Tue Jun 14 19:14:33 2011 Completed redo application Tue Jun 14 19:14:33 2011 Completed crash recovery at Thread 1: logseq 1006, block 1194, scn 17200193 74 data blocks read, 74 data blocks written, 39 redo blocks read Tue Jun 14 19:14:33 2011 LGWR: STARTING ARCH PROCESSES ARC0: Archival started LGWR: STARTING ARCH PROCESSES COMPLETE ARC0 started with pid=17, OS id=8656 Tue Jun 14 19:14:33 2011 Thread 1 advanced to log sequence 1007 (thread open) Thread 1 opened at log sequence 1007 Current log# 2 seq# 1007 mem# 0: /flashcard/oradata/G10R2/onlinelog/o1_mf_2_6v34jokt_.log Current log# 2 seq# 1007 mem# 1: /s01/flash_recovery_area/G10R2/onlinelog/o1_mf_2_6v34jotq_.log Successful open of redo thread 1 Tue Jun 14 19:14:33 2011 ARC0: Becoming the 'no FAL' ARCH ARC0: Becoming the 'no SRL' ARCH ARC0: Becoming the heartbeat ARCH db_recovery_file_dest_size of 204800 MB is 6.81% used. This is a user-specified limit on the amount of space that will be used by this database for recovery-related files, and does not reflect the amount of space available in the underlying filesystem or ASM diskgroup. Tue Jun 14 19:14:37 2011 Incremental checkpoint up to RBA [0x3ef.3.0], current log tail at RBA [0x3ef.3.0] 且此时 rowcache 仍未被填充 SQL> select parameter,count,gets from v$rowcache where count!=0; no rows selected 在 gdb 界面下再次执行 continue 2 次 (gdb) c Continuing. Breakpoint 1, 0x0000000002724b6c in kcrf_commit_force () (gdb) c Continuing. Breakpoint 2, 0x0000000001ac5e8c in kqlobjlod () 观察告警日志可以发现已开始 cache recovery,但也卡陷在 cache recovery 上,这保 证我们的演示不受骚扰 Tue Jun 14 19:16:44 2011 SMON: enabling cache recovery 此时 rowcache 中出现唯一的一个 dc_objects 对象 select parameter,count,gets from v$rowcache where count!=0; PARAMETER COUNT GETS -------------------------------- ---------- ---------- dc_objects 1 1
  • 11. 这个对象是什么呢?也许你已经猜到了,我们做一个 rowcache dump 来看一下: SQL> ALTER SESSION SET EVENTS 'immediate trace name row_cache level 10'; ================row_cache trace=================== BUCKET 43170: row cache parent object: address=0x92326060 cid=8(dc_objects) hash=f3d1a8a1 typ=11 transaction=(nil) flags=00000001 own=0x92326130[0x9230f628,0x9230f628] wat=0x92326140[0x92326140,0x92326140] mode=S status=EMPTY/-/-/-/-/-/-/-/- set=0, complete=FALSE data= 00000000 4f42000a 5453544f 24504152 00000000 00000000 00000000 00000000 00000000 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 BUCKET 43170 total object count=1 可以看到上述 dc_objects 尚未完成加载(status=EMPTY & complete=FALSE ),那 么这是一个什么 object 呢? 4f42000a 5453544f 24504152 => 转换为文本即:OB TSTO$PAR 也就是 BOOTSTRAP$ 换而言之在 cache recovery 时第一个恢复的字典缓存对象是 BOOTSTRAP$,这并不出乎 我们的意料。 启动实例的 LOCAL 进程的等待事件为 instance state change,这是常规情况下我们观 察不到得 SQL> select event,p1text,p1 from v$session where wait_class!='Idle'; EVENT P1TEXT P1 ---------------------------------------- ---------------------------------------- ---------- instance state change layer 2 在 gdb 界面下再次 continue,将载入更多的 rowcache 对象 (gdb) c Continuing. Breakpoint 2, 0x0000000001ac5e8c in kqlobjlod () BUCKET 37: row cache parent object: address=0x916cd980 cid=3(dc_rollback_segments) hash=5fed2a24 typ=9 transaction=(nil) flags=000000a6 own=0x916cda50[0x916cda50,0x916cda50] wat=0x916cda60[0x916cda60,0x916cda60]
  • 12. mode=N status=VALID/INSERT/-/FIXED/-/-/-/-/- data= 00000000 00000000 00000001 00000009 59530006 4d455453 00000000 00000000 00000000 00000000 00000000 00000000 00000003 00000000 00000000 00000000 00000000 00000000 00000000 00000000 BUCKET 37 total object count=1 595300064d455453 -> SYSTEM 属于 dc_rollback_segments 也就是著名的 system 回滚段 BUCKET 55556: row cache parent object: address=0x916d8cd0 cid=8(dc_objects) hash=ce89d903 typ=11 transaction=(nil) flags=00000001 own=0x916d8da0[0x9230f628,0x9230f628] wat=0x916d8db0[0x916d8db0,0x916d8db0] mode=S status=EMPTY/-/-/-/-/-/-/-/- set=0, complete=FALSE data= 00000000 5f430006 234a424f 00000000 00000000 00000000 00000000 00000000 00000000 00000005 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 BUCKET 55556 total object count=1 5f430006 234a424f -> C_OBJ# 是著名的 bootstrap 对象之一,可以从 $ORACLE_HOME/rdbms/admin/sql.bsq 中找到它 create rollback segment SYSTEM tablespace SYSTEM storage (initial 50K next 50K) / create cluster c_obj# (obj# number) pctfree 5 size 800 /* don't waste too much space */ /* A table of 32 cols, 2 index, 2 col per index requires about 2K. * A table of 10 cols, 2 index, 2 col per index requires about 750. */ storage (initial 130K next 200k maxextents unlimited pctincrease 0) /* avoid space management during IOR I */ / 我们还可以通过 v$rowcache_parent 视图来了解 dictionary cache 的情况 SQL> col cache_name for a20 SQL> col keystr for a31 SQL> set linesize 200 SQL> select address,cache_name,existent,lock_mode,saddr,substr(key,1,30) keystr from v$rowcache_parent; ADDRESS CACHE_NAME E LOCK_MODE SADDR KEYSTR ---------------- -------------------- - ---------- ---------------- ------------------------------- 00000000916CCE20 dc_tablespaces N 0 00 000000000000000000000000000000 00000000916CD980 dc_rollback_segments Y 0 00 000000000000000000000000000000
  • 13. 0000000092326060 dc_objects Y 0 00 000000000A00424F4F545354524150 00000000916D8CD0 dc_objects N 3 000000009BD91328 000000000600435F4F424A23000000 00000000916DA830 dc_object_ids Y 0 00 380000000000000000000000000000 可以看到持有 row cache lock 的会话是'000000009BD91328', 且该 dc_objects 对象还处于 non-existent 状态, 换而言之真正装载 rowcache 的是启动实例的 LOCAL 服务进程 SQL> select sid,program,event,p1,p2,p3 from v$session where saddr='000000009BD91328'; SID PROGRAM EVENT P1 P2 P3 ----- ------------------------------------------------ ---------------------------------------- -- ---- -- 3294 sqlplus@rh2.oracle.com (TNS V1-V3) db file scattered read 1 378 3 该进程正在等待 db file scattered read,fileid->1,block-378,这些块属于 BOOTSTRAP$表 BOOTSTRAP$对象已从 rowcache 被载入到 library cache 中 SQL> select kglhdadr,kglnaobj from x$kglob where kglobtyp=2 and kglnaobj not like 'X$%'; KGLHDADR KGLNAOBJ -------------------- -------------------- 0000000092326990 BOOTSTRAP$ SQL> select owner||'.'||Name from v$db_object_cache where type='TABLE' and name not like 'X$%'; OWNER||'.'||NAME -------------------------------------------------------------------------------- SYS.BOOTSTRAP$ 初步总结: 1. 在数据库正式 open 前需要恢复字典缓存,这个步骤被称为 cache recovery,其实是 row cache recovery。与官方文档中描述的”cache recovery”不同,row cache recovery 应当是 Oracle Internal 的叫法。 2. 实际执行 row cache recovery 的不是 SMON 进程,而是启动实例的服务进程