Oracle数据恢复
今天有客户的数据库意外被删除了整个目录中的数据文件,操作系统级别的删除,然而幸运的是这个数据库没有崩溃,仍然处于open状态
今天有客户的数据库意外被删除了整个目录中的数据文件,操作系统级别的删除,然而幸运的是这个数据库没有崩溃,,仍然处于open状态的时候,客户就发现了问题,求助到我们,最终完整地恢复了所有数据文件。
在Linux下大致重新演示一下恢复的过程,恢复的步骤与数据库版本没有太大关系,与操作系统的不同会有所不同。
1. 在数据库open的时候,直接删除users表空间中的数据文件。
SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /app/Oracle/oradata/ORCL/datafile/o1_mf_system_555wqbnk_.dbf /app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_555wqxgl_.dbf /app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_555wr5p6_.dbf /app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf SQL> host rm /app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf
2. 尝试在users表空间中创建表,开始报错。
SQL> create table t tablespace users as select * from dual; create table t tablespace users as select * from dual * ERROR at line 1: ORA-01116: error in opening database file 4 ORA-01110: data file 4: '/app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3
在告警日志中,同样也可以看到类似信息。
Mon Dec 19 21:48:17 CST 2011 Errors in file /app/oracle/admin/orcl/bdump/orcl_m000_3897.trc: ORA-01116: error in opening database file 4 ORA-01110: data file 4: '/app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3
3. 检查dbwr的进程PID
$ ps -ef|grep dbw0|grep -v grep oracle 2879 1 0 21:38 ? 00:00:00 ora_dbw0_orcl
4. dbwr会打开所有数据文件的句柄。在proc目录中可以查到,目录名是进程PID,fd表示文件描述符。
$ cd /proc/2879/fd $ ls -l total 0 lr-x------ 1 oracle dba 64 Dec 19 21:50 0 -> /dev/null lr-x------ 1 oracle dba 64 Dec 19 21:50 1 -> /dev/null lr-x------ 1 oracle dba 64 Dec 19 21:50 10 -> /dev/zero lr-x------ 1 oracle dba 64 Dec 19 21:50 11 -> /dev/zero lr-x------ 1 oracle dba 64 Dec 19 21:50 12 -> /app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb lrwx------ 1 oracle dba 64 Dec 19 21:50 13 -> /app/oracle/product/10.2.0/db_1/dbs/hc_orcl.dat lrwx------ 1 oracle dba 64 Dec 19 21:50 14 -> /app/oracle/product/10.2.0/db_1/dbs/lkORCL lrwx------ 1 oracle dba 64 Dec 19 21:50 15 -> /app/oracle/oradata/ORCL/controlfile/o1_mf_555wq3ng_.ctl lrwx------ 1 oracle dba 64 Dec 19 21:50 16 -> /app/oracle/oradata/ORCL/datafile/o1_mf_system_555wqbnk_.dbf lrwx------ 1 oracle dba 64 Dec 19 21:50 17 -> /app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_555wqxgl_.dbf lrwx------ 1 oracle dba 64 Dec 19 21:50 18 -> /app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_555wr5p6_.dbf lrwx------ 1 oracle dba 64 Dec 19 21:50 19 -> /app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf (deleted) lr-x------ 1 oracle dba 64 Dec 19 21:50 2 -> /dev/null lrwx------ 1 oracle dba 64 Dec 19 21:50 20 -> /app/oracle/oradata/ORCL/datafile/o1_mf_temp_555wrbnz_.tmp lr-x------ 1 oracle dba 64 Dec 19 21:50 21 -> /app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb lr-x------ 1 oracle dba 64 Dec 19 21:50 3 -> /dev/null lr-x------ 1 oracle dba 64 Dec 19 21:50 4 -> /dev/null l-wx------ 1 oracle dba 64 Dec 19 21:50 5 -> /app/oracle/admin/orcl/udump/orcl_ora_2871.trc l-wx------ 1 oracle dba 64 Dec 19 21:50 6 -> /app/oracle/admin/orcl/bdump/alert_orcl.log lrwx------ 1 oracle dba 64 Dec 19 21:50 7 -> /app/oracle/product/10.2.0/db_1/dbs/lkinstorcl (deleted)
注意其中"/app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf (deleted)"字样,表示该文件已经被删除,如果是Solaris操作系统,ls命令不会有如此清晰的显示,为了在Solaris系统中确认哪个句 柄对应哪个文件,则需要使用lsof程序。
5. 直接cp该句柄文件名回原位置。
cp 19 /app/oracle/oradata/ORCL/datafile/o1_mf_users_555wrj4o_.dbf
6. 进行数据文件recover
SQL> alter database datafile 4 offline; Database altered. SQL> recover datafile 4; Media recovery complete. SQL> alter database datafile 4 online; Database altered.
完成数据文件恢复。
恢复的原理是,在Linux操作系统中,如果文件从操作系统级别被rm掉,之前打开该文件的进程仍然持有相应的文件句柄,所指向的文件仍然可以读 写,并且该文件的文件描述符可以从/proc目录中获得。但是要注意的是,此时如果关闭数据库,则此句柄会消失,那么除了扫描磁盘进行文件恢复之外就没有 其它方法了,因此在数据库出现问题的时候,如果不确认情况的复杂程度,千万不要随便关闭数据库。重启数据库往往是没有意义的,甚至是致命的。
当然,客户的操作系统是Solaris,并且客户删除的文件还包括current online redo log,因此还有其它更复杂的操作,不在这里描述。

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



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.
