【ORACLE】正常关闭时ORACLE如何根据SCN对数据库进行一致性判断

SCN号在ORACLE中起着保证数据库一致性的作用,在ORACLE数据库的控制文件和数据文件头部,对于每一个数据文件都有2个SCN号,分别是:

Checkpoint SCNStop SCN

ORACLE通过比较两个SCN的值来确定控制文件和数据库文件是否保持一致,是否需要进行恢复。
实验如下:
1、正常关闭数据库

[oracle@db1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 15 21:23:54 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@oradb3> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2、启动到mount状态后转储获取控制文件内容

SYS@oradb3> startup mount
ORACLE instance started.

Total System Global Area 1553305600 bytes
Fixed Size          2253544 bytes
Variable Size         469765400 bytes
Database Buffers     1073741824 bytes
Redo Buffers            7544832 bytes
Database mounted.
SYS@oradb3> alter session set events 'immediate trace name controlf level 12';

Session altered.
SYS@oradb3> select VALUE from v$diag_info where NAME='Default Trace File';

VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/oradb3/oradb3/trace/oradb3_ora_109658.trc

3、打开转储的控制文件查看详细内容

[oracle@db1 ~]$ ll /u01/app/oracle/diag/rdbms/oradb3/oradb3/trace/oradb3_ora_109658.trc
-rw-r-----. 1 oracle oinstall 44185 Sep 15 21:25 /u01/app/oracle/diag/rdbms/oradb3/oradb3/trace/oradb3_ora_109658.trc

数据库的SCN信息

***************************************************************************
DATABASE ENTRY
***************************************************************************
 (size = 316, compat size = 316, section max = 1, section in-use = 1,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 1, numrecs = 1)
 09/15/2017 14:42:25
 DB Name "ORADB3"
 Database flags = 0x00404000 0x00001000
 Controlfile Creation Timestamp  09/15/2017 14:42:25
 Incmplt recovery scn: 0x0000.00000000
 Resetlogs scn: 0x0000.000e2006 Resetlogs Timestamp  09/15/2017 14:42:27
 Prior resetlogs scn: 0x0000.00000001 Prior resetlogs Timestamp  08/24/2013 11:37:30
 Redo Version: compatible=0xb200400
 #Data files = 5, #Online files = 5
 Database checkpoint: Thread=1 scn: 0x0000.000f56cc  ——>此处为Checkpoint SCN
 Threads: #Enabled=1, #Open=0, Head=0, Tail=0

Database checkpoint: Thread=1 scn: 0x0000.000f56cc ——>此处为Checkpoint SCN

REDO SCN信息

***************************************************************************
REDO THREAD RECORDS
***************************************************************************
 (size = 256, compat size = 256, section max = 8, section in-use = 1,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 9, numrecs = 8)
THREAD #1 - status:0xe thread links forward:0 back:0
 #logs:3 first:1 last:3 current:3 last used seq#:0x6
 enabled at scn: 0x0000.000e2006 09/15/2017 14:42:27
 disabled at scn: 0x0000.00000000 01/01/1988 00:00:00
 opened at 09/15/2017 14:45:14 by instance oradb3
Checkpointed at scn:  0x0000.000f56cc 09/15/2017 21:24:36 ——>此处为Checkpoint SCN
 thread:1 rba:(0x6.e7f3.10)
Checkpointed at scn: 0x0000.000f56cc 09/15/2017 21:24:36 ——>此处为Checkpoint SCN

数据文件SCN信息

***************************************************************************
DATA FILE RECORDS
***************************************************************************
 (size = 520, compat size = 520, section max = 100, section in-use = 5,
  last-recid= 30, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 11, numrecs = 100)
DATA FILE #1:
  name #7: /u01/app/oracle/oradata/oradb3/system01.dbf
creation size=0 block size=8192 status=0xe head=7 tail=7 dup=1
 tablespace 0, index=1 krfil=1 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:95 scn: 0x0000.000f56cc 09/15/2017 21:24:36  ——>此处为Checkpoint SCN
 Stop scn: 0x0000.000f56cc 09/15/2017 21:24:36               ——>此处为Stop SCN

 DATA FILE #2:
  name #6: /u01/app/oracle/oradata/oradb3/sysaux01.dbf
creation size=0 block size=8192 status=0xe head=6 tail=6 dup=1
 tablespace 1, index=2 krfil=2 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:95 scn: 0x0000.000f56cc 09/15/2017 21:24:36  ——>此处为Checkpoint SCN
 Stop scn: 0x0000.000f56cc 09/15/2017 21:24:36               ——>此处为Stop SCN

DATA FILE #3:
  name #5: /u01/app/oracle/oradata/oradb3/undotbs01.dbf
creation size=0 block size=8192 status=0xe head=5 tail=5 dup=1
 tablespace 2, index=3 krfil=3 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:16 scn: 0x0000.000f56cc 09/15/2017 21:24:36   ——>此处为Checkpoint SCN
 Stop scn: 0x0000.000f56cc 09/15/2017 21:24:36                ——>此处为Stop SCN

DATA FILE #4:
  name #4: /u01/app/oracle/oradata/oradb3/users01.dbf
creation size=0 block size=8192 status=0xe head=4 tail=4 dup=1
 tablespace 4, index=4 krfil=4 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:94 scn: 0x0000.000f56cc 09/15/2017 21:24:36   ——>此处为Checkpoint SCN
 Stop scn: 0x0000.000f56cc 09/15/2017 21:24:36                ——>此处为Stop SCN
Checkpoint cnt:94 scn: 0x0000.000f56cc 09/15/2017 21:24:36 ——>此处为Checkpoint SCN
Stop scn: 0x0000.000f56cc 09/15/2017 21:24:36 ——>此处为Stop SCN

4、由于数据库正常关闭,执行了完全检查点,此时数据库、REDO、数据文件2个SCN全部相等,表明数据库处于一致状态,在下次启动时就能顺利通过验证,正常启动。

Checkpoint SCNStop SCN
0x0000.000f56cc0x0000.000f56cc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值