溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫中數(shù)據(jù)文件不一致如何恢復

發(fā)布時間:2021-11-10 13:42:00 來源:億速云 閱讀:300 作者:小新 欄目:關(guān)系型數(shù)據(jù)庫

小編給大家分享一下數(shù)據(jù)庫中數(shù)據(jù)文件不一致如何恢復,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

還原數(shù)據(jù)文件無法recover 成功的場景:

1、數(shù)據(jù)庫時在非歸檔的模式下運行:

SQL> archive log list

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            /u01/archivelog

Oldest online log sequence     1

Current log sequence           2

2、移動其中的一個數(shù)據(jù)文件,然后將其 offline,具體操作如下:

col file_name for a50;

select file_name,ONLINE_STATUS  from dba_data_files;

SQL> col file_name for a50;

SQL> select file_name,ONLINE_STATUS  from dba_data_files;

FILE_NAME                                          ONLINE_

-------------------------------------------------- -------

/u01/app/oradata/orclpri/users01.dbf               ONLINE

/u01/app/oradata/orclpri/undotbs01.dbf             ONLINE

/u01/app/oradata/orclpri/sysaux01.dbf              ONLINE

/u01/app/oradata/orclpri/system01.dbf              SYSTEM

/u01/app/oradata/orclpri/datafileep_scs_idx.dbf    ONLINE

/u01/app/oradata/orclpri/bpep_scs.dbf              ONLINE

/u01/bpep_caweb.dbf                                ONLINE

/u01/app/oradata/orclpri/bpep_caweb_idx.dbf        ONLINE

/u01/app/oradata/orclpri/readonly01.dbf            ONLINE

/u01/app/oradata/orclpri/readwrite01.dbf           ONLINE

/u01/test.dbf                                      ONLINE

FILE_NAME                                          ONLINE_

-------------------------------------------------- -------

/u01/app/oradata/orclpri/test2.dbf                 ONLINE

/u01/app/oradata/orclpri/test3.dbf                 ONLINE

我們還是以 test數(shù)據(jù)文件來做實驗。

先做 一個MV操作:

SQL> !mv /u01/test.dbf  /u02/

然后將MV過之后的數(shù)據(jù)文件 offline 

SQL> alter database datafile  '/u01/test.dbf' offline drop;

Database altered.

切換日志文件:

SQL> alter system switch logfile;

System altered.

多切換幾次日志文件。

關(guān)閉數(shù)據(jù)庫:

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

將數(shù)據(jù)庫啟動到mount 狀態(tài):

SQL> startup mount;

ORACLE instance started.

Total System Global Area  849530880 bytes

Fixed Size                  1339824 bytes

Variable Size             566234704 bytes

Database Buffers          276824064 bytes

Redo Buffers                5132288 bytes

Database mounted.

將MV過的數(shù)據(jù)文件做rename 操作:

SQL> alter database rename file  '/u01/test.dbf' to '/u02/test.dbf'; 

Database altered.

將數(shù)據(jù)庫打開:

SQL> alter database open;

查看各個數(shù)據(jù)文件的狀態(tài):

SQL> select file_name,ONLINE_STATUS  from dba_data_files;

FILE_NAME                                          ONLINE_

-------------------------------------------------- -------

/u01/app/oradata/orclpri/users01.dbf               ONLINE

/u01/app/oradata/orclpri/undotbs01.dbf             ONLINE

/u01/app/oradata/orclpri/sysaux01.dbf              ONLINE

/u01/app/oradata/orclpri/system01.dbf              SYSTEM

/u01/app/oradata/orclpri/datafileep_scs_idx.dbf    ONLINE

/u01/app/oradata/orclpri/bpep_scs.dbf              ONLINE

/u01/bpep_caweb.dbf                                ONLINE

/u01/app/oradata/orclpri/bpep_caweb_idx.dbf        ONLINE

/u01/app/oradata/orclpri/readonly01.dbf            ONLINE

/u01/app/oradata/orclpri/readwrite01.dbf           ONLINE

/u02/test.dbf                                      RECOVER

FILE_NAME                                          ONLINE_

-------------------------------------------------- -------

/u01/app/oradata/orclpri/test2.dbf                 ONLINE

/u01/app/oradata/orclpri/test3.dbf                 ONLINE

將數(shù)據(jù)文件做 online 操作,會產(chǎn)生如下操作:

SQL> alter database datafile '/u02/test.dbf' online;

alter database datafile '/u02/test.dbf' online

*

ERROR at line 1:

ORA-01113: file 11 needs media recovery

ORA-01110: data file 11: '/u02/test.dbf'

嘗試 做recover數(shù)據(jù)文件操作:

SQL> recover datafile '/u02/test.dbf';

ORA-00279: change 2684134 generated at 12/04/2016 21:49:15 needed for thread 1

ORA-00289: suggestion : /u01/archivelog/1_2_929742548.dbf

ORA-00280: change 2684134 for thread 1 is in sequence #2

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00308: cannot open archived log '/u01/archivelog/1_2_929742548.dbf'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

ORA-00308: cannot open archived log '/u01/archivelog/1_2_929742548.dbf'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

發(fā)現(xiàn) 做recover操作的時候 報上面的錯誤。

這個時候 想要正常的將數(shù)據(jù)文件online,可能就需要放棄數(shù)據(jù)的一致性,需要用到 _allow_resetlogs_corruption參數(shù)。

將 _allow_resetlogs_corruption 參數(shù)設(shè)置為 true ,然后可以將數(shù)據(jù)文件online

修改這個參數(shù):

SQL> alter system set "_allow_resetlogs_corruption" =true scope=spfile;

SQL> show parameter allow

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

_allow_resetlogs_corruption          boolean     TRUE

將數(shù)據(jù)庫重啟到 mount狀態(tài),然后使用RMAN進入,查看incarnation 

RMAN> list incarnation;

List of Database Incarnations

DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1       1       ORCLPRI  1094561153       PARENT  1          13-AUG-09

2       2       ORCLPRI  1094561153       PARENT  754488     13-JUL-16

3       3       ORCLPRI  1094561153       PARENT  2663124    04-DEC-16

4       4       ORCLPRI  1094561153       PARENT  2683818    04-DEC-16

5       5       ORCLPRI  1094561153       CURRENT 2684130    04-DEC-16

我們將數(shù)據(jù)庫reset到上個還原點:

RMAN> reset database to Incarnation 4;

然后 重新將庫啟動到mount狀態(tài):

將數(shù)據(jù)文件online :

 alter database datafile '/u02/test.dbf' online;

這個時候不能直接打開數(shù)據(jù)庫:

SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-01190: control file or data file 11 is from before the last RESETLOGS

ORA-01110: data file 11: '/u02/test.dbf'

SQL> alter database open resetlogs;

alter database open resetlogs

*

ERROR at line 1:

ORA-01139: RESETLOGS option only valid after an incomplete database recovery

我們可以recover database:

使用下面的兩個命令:

SQL> recover database until cancel;

SQL> recover database  using backup controlfile until cancel;

然后可以打開數(shù)據(jù)庫:

SQL> alter database open resetlogs;

Database altered.

查看數(shù)據(jù)文件均是online 狀態(tài):

SQL> select file_name,ONLINE_STATUS  from dba_data_files;

FILE_NAME                                          ONLINE_

-------------------------------------------------- -------

/u01/app/oradata/orclpri/users01.dbf               ONLINE

/u01/app/oradata/orclpri/undotbs01.dbf             ONLINE

/u01/app/oradata/orclpri/sysaux01.dbf              ONLINE

/u01/app/oradata/orclpri/system01.dbf              SYSTEM

/u01/app/oradata/orclpri/datafileep_scs_idx.dbf    ONLINE

/u01/app/oradata/orclpri/bpep_scs.dbf              ONLINE

/u01/bpep_caweb.dbf                                ONLINE

/u01/app/oradata/orclpri/bpep_caweb_idx.dbf        ONLINE

/u01/app/oradata/orclpri/readonly01.dbf            ONLINE

/u01/app/oradata/orclpri/readwrite01.dbf           ONLINE

/u02/test.dbf                                      ONLINE

FILE_NAME                                          ONLINE_

-------------------------------------------------- -------

/u01/app/oradata/orclpri/test2.dbf                 ONLINE

/u01/app/oradata/orclpri/test3.dbf                 ONLINE

13 rows selected.

以上是“數(shù)據(jù)庫中數(shù)據(jù)文件不一致如何恢復”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI