假设数据文件顺序被打乱,你有办法找回正确的文件把数据库打开吗
一种非常应用很广泛的架构:HACMP+RAC+RAW。这种架构采用裸设备作为数据文件。今天演示一种恢复场景:数据库异常宕机,数据文件顺序错乱,数据库无法启动。 下面通过实验逐步演示,如果把数据文件的正确顺序找出来: SQL select * from v$version;BANNER----
一种非常应用很广泛的架构:HACMP+RAC+RAW。这种架构采用裸设备作为数据文件。今天演示一种恢复场景:数据库异常宕机,数据文件顺序错乱,数据库无法启动。
下面通过实验逐步演示,如果把数据文件的正确顺序找出来:
SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production PL/SQL Release 11.2.0.4.0 - Production CORE 11.2.0.4.0 Production TNS for Linux: Version 11.2.0.4.0 - Production NLSRTL Version 11.2.0.4.0 - Production
展示表空间、数据文件的简要情况
SQL> select ts#,name from v$tablespace;
TS# NAME
---------- --------------------
0 SYSTEM
1 SYSAUX
2 UNDOTBS1
3 TEMP
4 USERS
SQL> select file#,name from v$datafile;
FILE# NAME
---------- ---------------------------------------------------------------------
1 /u01/app/oracle/oradata/primary/system01.dbf
2 /u01/app/oracle/oradata/primary/sysaux01.dbf
3 /u01/app/oracle/oradata/primary/undotbs01.dbf
4 /u01/app/oracle/oradata/primary/users01.dbf
“断电”式快速强制停库
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 700452408 bytes
Database Buffers 79691776 bytes
Redo Buffers 2596864 bytes
Database mounted.
搞破坏,将system01.dbf和sysaux01.dbf两个数据文件相互替换名字
mv /u01/app/oracle/oradata/primary/system01.dbf /u01/app/oracle/oradata/primary/a
mv /u01/app/oracle/oradata/primary/sysaux01.dbf /u01/app/oracle/oradata/primary/system01.dbf
mv /u01/app/oracle/oradata/primary/a /u01/app/oracle/oradata/primary/sysaux01.dbf
尝试启库,但会报错
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/app/oracle/oradata/primary/system01.dbf'
ORA-01210: data file header is media corrupt
细心的朋友可能会顺便查询一下视图v$datafile_header
v$datafile是从控制文件里读取信息,而v$datafile_header是从数据文件头部读取信息。
其实到这里,已经能从FILE#,ERROR,RFILE#的值就可以看出,system01.dbf与sysaux01.dbf到换了,可以改名直接将数据库打开。我们不妨通过其他方法去修复破坏
以下已经提示system01.dbf数据文件头部损坏,我们dump部分数据文件瞧瞧:
DUMP数据文件头部
SQL> alter system dump datafile '/u01/app/oracle/oradata/primary/system01.dbf' block 2;
System altered.
SQL> alter system dump datafile '/u01/app/oracle/oradata/primary/sysaux01.dbf' block 2;
System altered.
以上可以看出,system01.dbf的头部记录着自身其实是2号数据文件
从以上可以看出,sysaux01.dbf头部记录着自身其实是1号数据文件
至此,可以判断,system01.dbf其实是SYSAUX表空间的数据文件,sysaux01.dbf其实是SYSTEM的数据文件,对照v$datafile视图的输出将数据文件重命名:
重命名数据文件,修复破坏
mv /u01/app/oracle/oradata/primary/system01.dbf /u01/app/oracle/oradata/primary/b
mv /u01/app/oracle/oradata/primary/sysaux01.dbf /u01/app/oracle/oradata/primary/system01.dbf
mv /u01/app/oracle/oradata/primary/b /u01/app/oracle/oradata/primary/sysaux01.dbf
再次尝试打开数据库:
SQL> alter database open;
Database altered.
SQL> select * from dual;
DUM
---
X
经过以上实验的演示将数据文件重新对应,最终得以顺利打开数据库。
启示:
数据文件头部记录都记录着DBID,DB_NAME,File Number,Blsize等信息,同时数据块也通过rdba标识着该数据块的物理位置(数据文件+数据块),因此可以通过这些信息与控制文件的信息做对照。
-------------------------------------------------------------------------------------------------
本文来自于我的技术博客 http://blog.csdn.net/robo23
转载请标注源文链接,否则追究法律责任!

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











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

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

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 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())

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

The expansion of the virtual market is inseparable from the circulation of virtual currency, and naturally it is also inseparable from the issue of virtual currency transfers. A common transfer error is the address copy error, and another error is the chain selection error. The transfer of virtual currency to the wrong chain is still a thorny problem, but due to the inexperience of transfer operations, novices often transfer the wrong chain. So how to recover the wrong chain of virtual currency? The wrong link can be retrieved through a third-party platform, but it may not be successful. Next, the editor will tell you in detail to help you better take care of your virtual assets. How to retrieve the wrong chain of virtual currency? The process of retrieving virtual currency transferred to the wrong chain may be complicated and challenging, but by confirming the transfer details, contacting the exchange or wallet provider, importing the private key to a compatible wallet, and using the cross-chain bridge tool

According to news on June 26, at the opening ceremony of the 2024 World Mobile Communications Conference Shanghai (MWC Shanghai), China Mobile Chairman Yang Jie delivered a speech. He said that currently, human society is entering the fourth industrial revolution, which is dominated by information and deeply integrated with information and energy, that is, the "digital intelligence revolution", and the formation of new productive forces is accelerating. Yang Jie believes that from the "mechanization revolution" driven by steam engines, to the "electrification revolution" driven by electricity, internal combustion engines, etc., to the "information revolution" driven by computers and the Internet, each round of industrial revolution is based on "information and "Energy" is the main line, bringing productivity development

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.
