数据库控制文件中的SCN详解
在的启动和关闭数据库的时候控制文件起着重要的作用,从官方文档中我们可以知道控制文件中保存着下列的信息: 数据库的名称及数据库创建时间等 所有的数据文件、重做日志文件的名称和位置信息。 表空间的信息。 Offline 数据文件的信息。 重做日志及归档日志
在的启动和关闭数据库的时候控制文件起着重要的作用,从官方文档中我们可以知道控制 文件中保存着下列的信息:
数据库的名称及数据库创建时间等
所有的数据文件、重做日志文件的名称和位置信息。
表空间的信息。
Offline数据文件的信息。
重做日志及归档日志的信息。
备份集及备份文件的信息
检查点及SCN信息等。
正常关闭数据库时,控制文件中的SCN值
在控制文件的数据文件信息部分,对于每一个数据文件都有一个Checkpoint SCN 和 Stop SCN,在数据库启动时要对其进行校验。
我们知道数据库在一致性关闭的时候控制文件中的SCN是怎样的呢?
1.一致性关闭数据库。Dump控制文件
SYS@ENMOEDU > shutdown immediate
SYS@ENMOEDU > startup mount
Database mounted.
SYS@ENMOEDU > oradebug setmypid;
Statement processed.
SYS@ENMOEDU > oradebug dump controlf 3;
Statement processed.
2.数据库的相关信息,上次数据库成功完成检查点的信息
***************************************************************************
DATABASE ENTRY
***************************************************************************
(size = 316, compat size = 316, div max = 1, div in-use = 1,
last-recid= 0, old-recno = 0, last-recno = 0)
(extent = 1, blkno = 1, numrecs = 1)
01/13/2014 16:13:27
DB Name "ENMOEDU"
Database flags = 0x00404001 0x00001000
Controlfile Creation Timestamp 01/13/2014 16:13:28
Incmplt recovery scn: 0x0000.00000000
Resetlogs scn: 0x0000.000fc451 Resetlogs Timestamp 02/05/2014 15:44:46
Prior resetlogs scn: 0x0000.000fa657 Prior resetlogs Timestamp 02/05/2014 14:15:27
Redo Version: compatible=0xb200000
#Data files = 6, #Online files = 6
Database checkpoint: Thread=1 scn: 0x0000.0011b73b
Threads: #Enabled=1, #Open=0, Head=0, Tail=0
3.检查点进程记录。Low cache rba是恢复的起点,此时是fffffff说明数据库不需要恢复。On disk rba是恢复的终点。
***************************************************************************
CHECKPOINT PROGRESS RECORDS
***************************************************************************
(size = 8180, compat size = 8180, div max = 11, div in-use = 0,
last-recid= 0, old-recno = 0, last-recno = 0)
(extent = 1, blkno = 2, numrecs = 11)
THREAD #1 - status:0x1 flags:0x0 dirty:0
low cache rba:(0xffffffff.ffffffff.ffff) on disk rba:(0x6.6f7.0)
on disk scn: 0x0000.0011b58f 02/19/2014 21:58:48
resetlogs scn: 0x0000.000fc451 02/05/2014 15:44:46
heartbeat: 839919586 mount id: 99161229
Flashback log tail log# 2 thread# 1 seq 2 block 5337 byte 0
4.Redo线程记录中记录了检查点的信息,与数据库的检查点一样
***************************************************************************
REDO THREAD RECORDS
***************************************************************************
(size = 256, compat size = 256, div max = 8, div in-use = 1,
last-recid= 0, old-recno = 0, last-recno = 0)
(extent = 1, blkno = 9, numrecs = 8)
THREAD #1 - status:0xbe thread links forward:0 back:0
#logs:3 first:1 last:3 current:3 last used seq#:0x6
enabled at scn: 0x0000.000fc451 02/05/2014 15:44:46
disabled at scn: 0x0000.00000000 01/01/1988 00:00:00
opened at 02/19/2014 21:57:43 by instance ENMOEDU
Checkpointed at scn: 0x0000.0011b73b 02/19/2014 21:58:52
5.数据文件中记录的检查点信息与DATABASE ENTRY记录的一样
***************************************************************************
DATA FILE RECORDS
***************************************************************************
DATA FILE #6:
name #13: /u01/app/oracle/oradata/ENMOEDU/sample01.dbf
creation size=12800 block size=8192 status=0xe head=13 tail=13 dup=1
tablespace 7, index=7 krfil=6 prev_file=0
unrecoverable scn: 0x0000.001143f4 02/10/2014 15:34:23
Checkpoint cnt:7 scn: 0x0000.0011b73b 02/19/2014 21:58:52
Stop scn: 0x0000.0011b73b 02/19/2014 21:58:52
Creation Checkpointed at scn: 0x0000.00111736 02/10/2014 15:28:26
thread:1 rba:(0x4.1f5.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
由于数据库是一致性关闭,数据文件中的Checkpoint scn 与Stop scn,database scn和redo中记录的scn值都一样,所以在下次启动数据库的时候可以直接启动,不用进行恢复。
数据库异常关闭的时候的SCN的值。
1.如果数据库异常关闭,则不会执行任何的检查点。通过shutdown abort可以模拟一次异常,当使用shutdown abort方式关闭数据库时,此时的SCN值是怎么样的。
SYS@ENMOEDU > shutdown abort
ORACLE instance shut down.
SYS@ENMOEDU > startup mount
Database mounted.
SYS@ENMOEDU > oradebug setmypid;
Statement processed.
SYS@ENMOEDU > oradebug dump controlf 3;
Statement processed.
2.在DATABASE ENTRY中我们可以看到数据库thread checkpoint信息。
***************************************************************************
DATABASE ENTRY
***************************************************************************
(size = 316, compat size = 316, div max = 1, div in-use = 1,
last-recid= 0, old-recno = 0, last-recno = 0)
(extent = 1, blkno = 1, numrecs = 1)
01/13/2014 16:13:27
DB Name "ENMOEDU"
Database flags = 0x00404001 0x00001200
Controlfile Creation Timestamp 01/13/2014 16:13:28
Incmplt recovery scn: 0x0000.00000000
Resetlogs scn: 0x0000.000fc451 Resetlogs Timestamp 02/05/2014 15:44:46
Prior resetlogs scn: 0x0000.000fa657 Prior resetlogs Timestamp 02/05/2014 14:15:27
Redo Version: compatible=0xb200000
#Data files = 6, #Online files = 6
Database checkpoint: Thread=1 scn: 0x0000.0011b73e
Threads: #Enabled=1, #Open=1, Head=1, Tail=1
3. 检查点信息其中包含 low chache rba 和on disk ora信息。low cache rba(recovery block address)是恢复的起点,on disk rba(确定已经写到磁盘上的重做值)是恢复的终点,
***************************************************************************
CHECKPOINT PROGRESS RECORDS
***************************************************************************
(size = 8180, compat size = 8180, div max = 11, div in-use = 0,
last-recid= 0, old-recno = 0, last-recno = 0)
(extent = 1, blkno = 2, numrecs = 11)
THREAD #1 - status:0x2 flags:0x0 dirty:510
low cache rba:(0x6.18e2.0) on disk rba:(0x6.ca99.0)
on disk scn: 0x0000.0011e785 02/19/2014 22:55:08
resetlogs scn: 0x0000.000fc451 02/05/2014 15:44:46
heartbeat: 839992040 mount id: 99202971
Flashback log tail log# 3 thread# 1 seq 3 block 2244 byte 0
4. Redo线程的记录。
***************************************************************************
REDO THREAD RECORDS
***************************************************************************
(size = 256, compat size = 256, div max = 8, div in-use = 1,
last-recid= 0, old-recno = 0, last-recno = 0)
(extent = 1, blkno = 9, numrecs = 8)
THREAD #1 - status:0xbf thread links forward:0 back:0
#logs:3 first:1 last:3 current:3 last used seq#:0x6
enabled at scn: 0x0000.000fc451 02/05/2014 15:44:46
disabled at scn: 0x0000.00000000 01/01/1988 00:00:00
opened at 02/19/2014 22:49:27 by instance ENMOEDU
Checkpointed at scn: 0x0000.0011b73e 02/19/2014 22:49:27
thread:1 rba:(0x6.9ce.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
5. 数据文件的检查点信息;
DATA FILE #6:
name #13: /u01/app/oracle/oradata/ENMOEDU/sample01.dbf
creation size=12800 block size=8192 status=0xe head=13 tail=13 dup=1
tablespace 7, index=7 krfil=6 prev_file=0
unrecoverable scn: 0x0000.001143f4 02/10/2014 15:34:23
Checkpoint cnt:8 scn: 0x0000.0011b73e 02/19/2014 22:49:27
Stop scn: 0xffff.ffffffff 02/19/2014 21:58:52
Creation Checkpointed at scn: 0x0000.00111736 02/10/2014 15:28:26
thread:1 rba:(0x4.1f5.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
可以看出由于是异常关闭数据库,数据库没有完成最后的检查点,数据库文件的stop scn仍然设定为最大的ffffffff。由以上信息可以看出,各部分的checkpoint scn 都是一样的,但是数据文件的stop scn不等于checkpoint scn,意味着数据库的上一次的关闭没有执行完全检查点,是异常关闭数据库,此时启动数据库需要进行完全恢复。
在进行恢复的时候,从检查点信息中读取low cache rba的值确定日志文件的地址。再读取日志,从最后的检查点开始,应用所有的重做记录,这个过程叫做前滚。数据库可以被打开提供访问和使用,但是此时数据库中包含已提交的和没有提交的事务,使用undo段回滚。
再对数据库进行实例恢复的时候,我们从alert日志中可以看到的信息。
alter database open
Beginning crash recovery of 1 threads
parallel recovery started with 2 processes
Started redo scan
Completed redo scan
read 22747 KB redo, 510 data blocks need recovery
Started redo application at
Thread 1: logseq 6, block 6370
Recovery of Online Redo Log: Thread 1 Group 3 Seq 6 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/ENMOEDU/redo03.log
Completed redo application of 3.07MB
Wed Feb 19 23:13:55 2014
Completed crash recovery at
Thread 1: logseq 6, block 51865, scn 1193381
510 data blocks read, 493 data blocks written, 22747 redo k-bytes read
Wed Feb 19 23:13:55 2014
在实例恢复的时候。 Alter中的logseq 6, block 6370就是日志中的检查点中记录的low cache rba:(0x6.18e2.0) 。恢复完成时的logseq 6, block 51865就是on disk rba:(0x6.ca99.0)。把十六进制的数换成十进制。
总结:当一致性关闭数据库的时候,关闭数据库之前数据库会执行一个检查点动作,每个数据文件的你Stop SCN会被设置为Checkpoint SCN。数据库不需要恢复。当数据库是异常关闭的时候,Stop SCN 来不及设置为Checkpoint SCN会是无穷大,在重启数据库的时候需要恢复

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.
