Oracle 資料庫類比資料檔案損壞恢複

來源:互聯網
上載者:User

資料檔案有時候因為某種原因會導致損壞而導致無法啟動資料庫,那如何恢複呢?

下面是一次類比實驗,如下

1. 首先建立一個資料表空間TEST,在建立一個表test在資料表空間test上

SQL> create tablespace test datafile '/u01/app/oracle/oradata/lhz/test01.dbf' size 10M;


SQL>  create table test as  select * from dba_objects;

Table created

SQL> alter table test move tablespace test;

Table altered

SQL> select count(*) from test;


 COUNT(*)

----------

    50881


2. 然後用vi編輯資料檔案

[oracle@odb1 ~]$ vi /u01/app/oracle/oradata/lhz/test01.dbf

3.隨便輸入什麼字元,儲存

4.關閉資料庫執行個體

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

5.啟動執行個體

SQL> startup

ORACLE instance started.


Total System Global Area  599785472 bytes

Fixed Size                  2098112 bytes

Variable Size             243272768 bytes

Database Buffers          348127232 bytes

Redo Buffers                6287360 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 9 - see DBWR trace file

ORA-01110: data file 9: '/u01/app/oracle/oradata/lhz/test01.dbf'


看到報錯資訊資料檔案不能驗證或鎖定資料檔案

6. 先將損壞資料檔案offline,並開啟資料庫執行個體

SQL> alter database datafile '/u01/app/oracle/oradata/lhz/test01.dbf' offline;

Database altered.

SQL> alter database open;

Database altered.

7. 添加相同的資料表空間test

SQL> alter database create datafile '/u01/app/oracle/oradata/lhz/test01.dbf';

Database altered.

SQL> recover datafile 9;

Media recovery complete.

SQL> alter database datafile 9 online;

Database altered.

8.驗證恢複結果:


SQL> select count(*) from andylhz.test;


 COUNT(*)

----------

    50881


恢複完成!

本文出自 “影子騎士” 部落格,請務必保留此出處http://andylhz2009.blog.51cto.com/728703/1197954

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.