SCN与数据恢复关联
一、各种SCN简介:如图,控制文件中有系统SCN号,针对每个数据文件还有文件SCN号、结束SCN号(如四个数据文件就有4个对应的文件SCN号、结束SCN号)数据文件头部
一、各种SCN简介:
如图,控制文件中有系统SCN号,针对每个数据文件还有文件SCN号、结束SCN号(如四个数据文件就有4个对应的文件SCN号、结束SCN号)
数据文件头部有开始SCN号。都是为了保证数据文件的一致性
正常情况下:系统SCN、文件SCN、文件头部的开始SCN应该一样,结束SCN为null
系统SCN:
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
617242
文件SCN:
SQL> select name,checkpoint_change# from v$datafile;
NAME CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/u01/app/oracle/oradata/jiagulun/system01.dbf 617242
/u01/app/oracle/oradata/jiagulun/undotbs01.dbf 617242
/u01/app/oracle/oradata/jiagulun/sysaux01.dbf 617242
/u01/app/oracle/oradata/jiagulun/users01.dbf 617242
/u01/app/oracle/oradata/jiagulun/example01.dbf 617242
/u01/app/oracle/oradata/jiagulun/data1_01_dbf 617242
结束SCN:
SQL> select name,last_change# from v$datafile;
NAME LAST_CHANGE#
-------------------------------------------------- ------------
/u01/app/oracle/oradata/jiagulun/system01.dbf
/u01/app/oracle/oradata/jiagulun/undotbs01.dbf
/u01/app/oracle/oradata/jiagulun/sysaux01.dbf
/u01/app/oracle/oradata/jiagulun/users01.dbf
/u01/app/oracle/oradata/jiagulun/example01.dbf
/u01/app/oracle/oradata/jiagulun/data1_01_dbf
数据文件头部开始SCN:
SQL> select name,checkpoint_change# from v$datafile_header;
NAME CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/u01/app/oracle/oradata/jiagulun/system01.dbf 617242
/u01/app/oracle/oradata/jiagulun/undotbs01.dbf 617242
/u01/app/oracle/oradata/jiagulun/sysaux01.dbf 617242
/u01/app/oracle/oradata/jiagulun/users01.dbf 617242
/u01/app/oracle/oradata/jiagulun/example01.dbf 617242
/u01/app/oracle/oradata/jiagulun/data1_01_dbf 617242
每一条日志都有SCN,每个日志组文件的头部有两个SCN first SCN和next SCN
first SCN:即这个文件组中第一条日志的SCN,等于上一组的next SCN。
next SCN:即这个文件组中最后一条日志的SCN,等于下一组的first SCN。
二、SCN如何保证数据库文件一致性(如何确认需要恢复)?
正常关闭:将所有buffer cache脏块写到磁盘,同时更新系统SCN、文件SCN,,数据头部开始SCN,同时结束SCN写上与系统SCN、文件SCN、数据头部开始SCN都一样的时间点(关闭时间)
非正常关闭:结束SCN为null,未正常写上。开启数据库时检测到结束SCN为null,则需要实例恢复。
数据文件丢失:例如当1号DBF文件丢失了,从备份中拷贝一个备份的1号DBF文件过来,此时文件头部的SCN比较旧,与控制文件系统SCN号对比,oracle则发现需要做恢复。则用跑日志将其SCN跑到与控制文件中文件SCN一样。
控制文件丢失:控制文件和数据文件都换成旧的,此时光对比控制文件中的SCN号和数据文件头部的SCN号还不能确认需不需要恢复,oracle还要对比on disk rba scn,如果on disk rba scn比控制文件中的SCN号和数据文件头部的SCN号都新,则要实例恢复。
用SCN号确认使用哪些日志组来恢复实例:
目前系统SCN号为617242:
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
617242
此时日志组1first SCN为617242,则需要日志组1恢复即可;
试着经过两次日志组切换:
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
此时系统当前最新的文件SCN仍然是617242
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
617242
那么这时候数据库实例崩溃使用哪些日志组恢复呢?
此时617242在日志组1,按照序列号8-10,日志组3是最新日志,此时需要日志组1、2、3恢复。
日志中active代表组中存在日志对应的脏块还没有写到磁盘中。
执行
SQL> alter system flush buffer_cache;
System altered.
后,日志组active变为inactive:
而此时控制文件中的SCN也更新为:
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
628825
此时如果数据库实例非正常关闭,则需要日志组3来恢复。
三、总结:
控制文件中系统SCN,文件SCN等于最旧的active日志文件组的first SCN,实例恢复需要active和current日志组。
控制文件中的系统SCN,文件SCN用于确认数据恢复的所需要的重做日志文件组。
确认文件组后根据控制文件中的LRBA地址去跑日志跑到on disk rba地址。
CKPT进程只是将LRBA地址写到控制文件中,而控制文件中的系统SCN,文件SCN和数据头部SCN的更新是当一个日志组由active变为inactive时更新的,结束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



Windows 7 users encounter the phenomenon that the system registry file is missing or damaged when starting up. How to solve this situation? You first force restart the computer, then press the F8 key, select safe mode in the opened page, then find the command prompt in the menu bar to open, enter the SFC/SCANNOW command and press Enter, then the system will automatically start the computer Repair missing or corrupted installation files. What to do if the Windows 7 system registry file is lost or damaged 1. After the first power-on self-test, immediately hold down the F8 key, use the arrow keys to select safe mode, and hit Enter. 2. Then click the Start button, select Command Prompt, and run as an administrator. 3. Finally, enter SFC/ in the pop-up prompt.

1. Binlog Binlog is used to record write operations (excluding queries) information performed by the database and save it on the disk in binary form. Binlog is the logical log of mysql and is recorded by the server layer. Mysql databases using any storage engine will record binlog logs. Logical log: can be simply understood as a sql statement; physical log: data in MySQL is stored in the data page, and the physical log records changes on the data page; insert the code piece here and the binlog is written by appending Input, you can set the size of each binlog file through the max_binlog_size parameter. When the file size reaches the given value

Many friends don’t know how to recover diskgenius data, so the editor will share the relevant tutorials on diskgenius data recovery. Let’s take a look. I believe it will be helpful to everyone. First, in the hard disk partition diagram above the main interface of DiskGenius, you can directly select the target partition and right-click. Then, in the shortcut menu that pops up, find and click the "Deleted or formatted file recovery" menu item, as shown in the figure. In the second step, the recovery options window pops up and make sure to check the three options of "Recover Deleted Files", "Complete Recovery" and "Extra Scan for Known File Types". Step 3: Click the "Select File Type" button on the right and specify the files you need to recover in the pop-up window

Solution to the problem of PHP parameter loss In the process of developing PHP programs, we often encounter the problem of parameter loss. This may be caused by incomplete parameters passed by the front end or incorrect way of receiving parameters by the back end. In this article, we will provide some solutions to the problem of missing parameters in PHP, along with specific code examples. 1. Front-end parameter passing problem Use the GET method to pass parameters. When using the GET method to pass parameters, the parameters will be appended to the requested URL in the form of URL parameters. When receiving parameters in the backend

ThinkPHP6 data backup and recovery: ensuring data security With the rapid development of the Internet, data has become an extremely important asset. Therefore, the security of data is of great concern. In web application development, data backup and recovery are an important part of ensuring data security. In this article, we will introduce how to use the ThinkPHP6 framework for data backup and recovery to ensure data security. 1. Data backup Data backup refers to copying or storing the data in the database in some way. This way even if the data

Preface There are six types of log files in MySQL, namely: redo log (redolog), rollback log (undolog), binary log (binlog), error log (errorlog), slow query log (slowquerylog), general query log (generallog) ), relay log (relaylog). 1. What is redolog? Redolog, also known as redo log file, is used to record changes in transaction operations. It records the value after data modification. It will be recorded regardless of whether the transaction is submitted or not. Redolog files can come in handy when instances and media fail (mediafailure), such as database power outage, Inn

Laravel is a popular PHP web application framework that provides many fast and easy ways to build efficient, secure and scalable web applications. When developing Laravel applications, we often need to consider the issue of data recovery, that is, how to recover data and ensure the normal operation of the application in the event of data loss or damage. In this article, we will introduce how to use Laravel middleware to implement data recovery functions and provide specific code examples. 1. What is Lara?

How to solve a broken hard disk sector? A broken hard disk sector is a common hardware failure, which may cause data loss and affect computer performance. It is very important to understand and solve the problem of bad hard drive sectors. This article will introduce the concept of hard disk sectors, discuss common causes of bad hard disk sectors and solutions. 1. What are hard disk sectors? Before introducing how to solve the problem of bad hard disk sectors, let’s first understand what hard disk sectors are. A hard disk sector is the smallest readable and writable unit on a hard drive. It is a small section of space on a hard drive. It is
