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

来源:互联网 发布:php管理系统 编辑:程序博客网 时间:2024/06/06 09:35

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

Checkpoint SCN Stop SCN

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

[oracle@db1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 15 21:23:54 2017Copyright (c) 1982, 2013, Oracle.  All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSYS@oradb3> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.

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

SYS@oradb3> startup mountORACLE instance started.Total System Global Area 1553305600 bytesFixed Size          2253544 bytesVariable Size         469765400 bytesDatabase Buffers     1073741824 bytesRedo Buffers            7544832 bytesDatabase 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 oradb3Checkpointed 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.dbfcreation 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.dbfcreation 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 SCNDATA FILE #3:  name #5: /u01/app/oracle/oradata/oradb3/undotbs01.dbfcreation 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 SCNDATA FILE #4:  name #4: /u01/app/oracle/oradata/oradb3/users01.dbfcreation 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 SCNStop scn: 0x0000.000f56cc 09/15/2017 21:24:36 ——>此处为Stop SCN

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

Checkpoint SCN Stop SCN 0x0000.000f56cc 0x0000.000f56cc
原创粉丝点击