oracle的resetlogs机制浅析
oracle的resetlogs机制浅析 重置日志的最主要的作用就是丢弃不完全恢复中没有使用的重做日志并保证后续的恢复不再需要。为此,重置日志选项将所有联机日志和归档日志都做废掉。副作用就是此前的所有备份对将来的恢复都没有用了。 重做日志选项还初始化了控制
oracle的resetlogs机制浅析
重置日志的最主要的作用就是丢弃不完全恢复中没有使用的重做日志并保证后续的恢复不再需要。为此,重置日志选项将所有联机日志和归档日志都做废掉。副作用就是此前的所有备份对将来的恢复都没有用了。
重做日志选项还初始化了控制文件中关于联机日志和重做线程的内容,清除了当前存在的联机重做日志的内容,如果联机日志文件不存在就创建,并重置了所有线程的日志序号。
alter database open resetlogs 这个命令我想大家都很熟悉了,那有没有想过这个resetlogs选项为什么要用?什么时候用?
它的原理机制是什么?他都起哪些作用?
我们都知道数据在启动时候是要做一致性检查的,oracle在open阶段要做两次检查
1. 检查数据文件头的检查点计数(checkpoint cnt)是否和控制文件的检查点计数(checkpoint cnt)一致。目的是确认数据文件
是否来自同一版本,而不是从备份中恢复的。如果这一步检查通过,就进行第二步检查
2. 检查数据文件头的开始scn和控制文件中记录该文件的结束scn是否一致。如果数据文件头的开始scn和控制文件中该文件的结束scn
相等,那说明这个数据文件就不需要恢复,否则就要恢复文件
如果以上两步检查都通过,那就可以正常打开数据库,锁定数据文件,同时将控制文件中每个数据文件的结束scn设置无穷大。
我们在某些条件下打开数据,会提示让用resetlogs选项open数据库,为什么要用resetlogs呢?它是干嘛用的呢?问号一大堆了吧,
下面来具体分析下。
resetlogs的作用
防止陈旧的数据进入数据库(保证数据库的一致性),这也就是为什么在用resetlogs打开数据库,一定要立即对数据库做个全备。
在控制文件,data file header,redo log header里存储”resetlogs data“,当open resetlogs被执行时,可以通过这些内容检查一致性。
什么时候用resetlogs
1. 不完全恢复
2. 用备份的控制文件恢复
3. 新创建的控制文件来恢复
resetlogs的原理机制
resetlogs是如何来保证打开数据库是一致的呢?
1)在open resetlogs时,oracle要对比检查控制文件和数据字典file$,如果一个数据文件在file$中存在,但在控制文件中不存在,
那在控制文件中将创建一个这个文件条目(MISSINGnnn ‘nnn’是十进制的file_id),同时这个文件被标记为离线并需要恢复。如果
实际中这个文件存在的话,可以通过如下sql更改到正确的文件名。
sql> alter database rename file 'MISSINGnnn' to '
然后数据文件被恢复,online。
2)如果一个数据文件存在控制文件中,而不在数据字典file$中,那么直接把控制文件中这个文件的记录条目删除(oracle认为file$文
件是正确的,要以它为准)
3)当用旧的备份控制文件恢复的时候,如果有数据文件不在控制文件中注册(会提示控制文件比较旧的错误),那就不得不重建数据文件
,以使数据文件注册到控制文件中,然后系统会自动利用redo/archivelog恢复这个数据文件。
在保证控制文件和file$文件内容一致之后,oracle还有做如下检查才能open resetlogs
4)数据文件的版本要小于当前数据库的版本(counter)
5)offline的数据文件必须被online或者直接drop
6)所有的数据文件不能设置fuzzy bit,所有的数据文件要有相同的检查点(checkpoint SCN)
到目前为止,open resetlogs的前提条件都已经满足,resetlogs究竟做了哪些工作呢?(重新使用redo log)
1)所有的online logfile 的信息重新被放置在控制文件中。并且还要为有效的thread挑选一个logfile文件作为current logfile
2)log header被更新为log seq#
3)所有的online的数据文件头被新的checkpoint和新的‘resetlogs data’更新,offline的数据文件被标记为需要媒体恢复。
resetlogs data:当前的scn和counter被称作”resetlogs data“
如果oracle数据库一致性检查失败的,那数据库是不允许被open的,即 open resetlogs不成功。但也不是绝对不能open,可以通过隐含参数“_allow_resetlogs_curruption”,绕过oracle的一致性检查,但这样会引起数据库的不一致(文件可能有不同的scn或有fuzzy bit设置),如果open后,数据库一定要rebuild (建议ANALYZE TABLE ...VALIDATE STRUCTURE
CASCADE;或者imp/exp )

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node
