熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

數據庫備份與恢復測試(3)

2013-11-13 15:46:35  來源: Oracle 

  ################################                                                                     
# [] 有trace活動在線日志損壞   
################################
################################                                                             
# [] 有trace活動在線日志損壞正常shutdown或是當前的數據文件  
################################
SQL> create table arch (status varchar());

  表已創建

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select no from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> select GROUP#SEQUENCE#archived STATUS from v$log;

  GROUP#  SEQUENCE# ARC STATUS

                   YES ACTIVE
                   YES ACTIVE
                   NO  CURRENT
    
SQL> shutdown  正常關閉數據庫
數據庫已經關閉
已經卸載數據庫
ORACLE 例程已經關閉

  此時模擬刪除當前在線日志組
SQL>
SQL>
SQL> startup nomount
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE testdb RESETLOGS  ARCHIVELOG
      SET STANDBY TO MAXIMIZE PERFORMANCE
        MAXLOGFILES
        MAXLOGMEMBERS
        MAXDATAFILES
        MAXINSTANCES
        MAXLOGHISTORY
    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
  STANDBY LOGFILE
  DATAFILE
    C:\ORACLE\ORADATA\testdb\SYSTEMDBF
    C:\ORACLE\ORADATA\testdb\UNDOTBSDBF
    C:\ORACLE\ORADATA\testdb\INDXDBF
    C:\ORACLE\ORADATA\testdb\TOOLSDBF
    C:\ORACLE\ORADATA\testdb\USERSDBF
  CHARACTER SET ZHSGBK
  ;

  控制文件已創建

  SQL> alter database open resetlogs;

  數據庫已更改
   
SQL> select count(*)status from arch group by status;

  COUNT(*) ST

      no
     ok

  >>沒有丟失任何數據因為你的數據都已經寫到數據文件裡了    

  #########################################                                                  
# [] 有trace活動在線日志損壞shutdown abort 或是非當前的數據文件
          當前在線日志文件損壞         
#########################################

  ####################################################
[測試] shutdown abort備份控制文件或者resetlog的trace
沒有數據文件備份采用強制打開數據庫的方法
####################################################
SQL> create table arch (status varchar());           
                                                          
表已創建                                                    

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> alter system switch logfile;
SQL> insert into arch select no from dba_objects;

  已創建

  SQL> commit;

  提交完成
SQL>  select GROUP#SEQUENCE#archived STATUS from v$log;

  GROUP#  SEQUENCE# ARC STATUS

                   YES ACTIVE
                   NO  CURRENT
                   YES INACTIVE

  SQL> insert into arch select no from dba_objects;

  已創建

  SQL> shutdown abort
ORACLE 例程已經關閉

  SQL> startup
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
數據庫裝載完畢
ORA: 無法打開日志組 (線程 ) 的成員
ORA: 聯機日志 線程 : C:\ORACLE\ORADATA\TESTDB\REDOLOG
ORA: 無法讀取文件的標題塊
OSD: ReadFile() 失敗 無法讀取文件
O/SError: (OS ) 到達文件結尾

  SQL> alter database clear logfile group ;
alter database clear logfile group
*
ERROR 位於第 行:
ORA: 線程的緊急恢復需要日志
ORA: 聯機日志 線程 : C:\ORACLE\ORADATA\TESTDB\REDOLOG

  SQL> startup nomount
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE testdb RESETLOGS  ARCHIVELOG
      SET STANDBY TO MAXIMIZE PERFORMANCE
        MAXLOGFILES
        MAXLOGMEMBERS
        MAXDATAFILES
        MAXINSTANCES
        MAXLOGHISTORY
    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
  STANDBY LOGFILE
  DATAFILE
    C:\ORACLE\ORADATA\testdb\SYSTEMDBF
    C:\ORACLE\ORADATA\testdb\UNDOTBSDBF
    C:\ORACLE\ORADATA\testdb\INDXDBF
    C:\ORACLE\ORADATA\testdb\TOOLSDBF
    C:\ORACLE\ORADATA\testdb\USERSDBF
  CHARACTER SET ZHSGBK
  ;

  控制文件已創建

  SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR 位於第 行:
ORA: ???????????????
ORA: ???? : C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF

  SQL> recover database using backup controlfile until cancel;
ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA: ??: RECOVER ??? OPEN RESETLOGS ???????
ORA: ???????????????
ORA: ???? : C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF

  ORA: ???????

  我們看到如果是abort DOWN機的話打開數據庫都需要應用在線活動日志

  這時必須加隱含參數強制打開數據庫並進行導出重建數據庫導入業務數據

  SQL> show parameter spfile                                                                               
                                                                                                         
NAME                                 TYPE        VALUE                                                   
                           
spfile                               string      %ORACLE_HOME%\DATABASE\SPFILE                           
                                                 ORACLE_SID%ORA                                         
                                                                                                         
                                                                                                         
SQL> create pfile=pfiletestora from spfile;                                                           
                                                                                                         
文件已創建                                                                                             
                                                                                                         
SQL> create pfile=c:\pfiletestora from spfile;                                                        
                                                                                                         
文件已創建                                                                                             
編輯c:\pfiletestora                                                                                     
增加三個參數                                                                                             
                                                                                                         
_allow_resetlogs_corruption=true                                                                         
_corrupted_rollback_segments=true                                                                        
_offline_rollback_segments=true                                                                          
                                                                                                         
SQL> shutdown immediate                                                                                  
ORA: 數據庫未打開                                                                                  
                                                                                                         
                                                                                                         
已經卸載數據庫                                                                                         
ORACLE 例程已經關閉                                                                                    
SQL>                                                                                                     
SQL>                                                                                                     
SQL>                                                                                                     
SQL> startup pfile=c:\pfiletestora                                                                    
ORACLE 例程已經啟動                                                                                    
                                                                                                         
Total System Global Area  bytes                                                                
Fixed Size                   bytes                                                                
Variable Size             bytes                                                                
Database Buffers           bytes                                                                
Redo Buffers                 bytes                                                                
數據庫裝載完畢                                                                                         
ORA: 要打開數據庫則必須使用 RESETLOGS 或 NORESETLOGS 選項                                          
                                                                                                         
                                                                                                         
SQL> alter database open resetlogs;                                                                      
alter database open resetlogs                                                                            
*                                                                                                        
ERROR 位於第 行:                                                                                       
ORA: ORACLE 例程終止強行斷開連接                                                                 
                                                                                                         
                                                                                                         
SQL>                                                                                                     
SQL>                                                                                                     
SQL> exit                                                                                                
從Oraclei Enterprise Edition Release Production                                             
With the Partitioning OLAP and Oracle Data Mining options                                               
JServer Release Production中斷開                                                             
                                                                                                         
C:\>sqlplus /as sysdba                                                                                 
                                                                                                         
SQL*Plus: Release Production on 星期五 ::                                  
                                                                                                         
Copyright (c) Oracle Corporation  All rights reserved                                      
                                                                                                         
已連接到空閒例程                                                                                       
                                                                                                         
SQL> startup pfile=c:\pfiletestora                                                                    
ORACLE 例程已經啟動                                                                                    
                                                                                                         
Total System Global Area  bytes                                                                
Fixed Size                   bytes                                                                
Variable Size             bytes                                                                
Database Buffers           bytes                                                                
Redo Buffers                 bytes                                                                
數據庫裝載完畢                                                                                         
數據庫已經打開                                                                                         
SQL>                                                                                                     

  ####################################################
# [測試] shutdown abortresetlog的trace
#         有數據文件備份當前在線日志損壞控制文件損壞有trace
####################################################
SQL> create table arch (status varchar()) tablespace users;

  表已創建

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> insert into arch select * from arch;

  已創建

  SQL> /

  已創建

  SQL> /

  已創建

  SQL> /

  已創建

  SQL> commit;

  提交完成

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select no from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> select GROUP#SEQUENCE#archived STATUS from v$log;

  GROUP#  SEQUENCE# ARC STATUS

                   NO  CURRENT
                   YES ACTIVE
                   NO  ACTIVE

  SQL> shutdown abort
ORACLE 例程已經關閉
SQL> startup nomount
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG

      SET STANDBY TO MAXIMIZE PERFORMANCE

        MAXLOGFILES

        MAXLOGMEMBERS

        MAXDATAFILES

        MAXINSTANCES

        MAXLOGHISTORY

    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

    STANDBY LOGFILE

    DATAFILE

      C:\ORACLE\ORADATA\testdb\SYSTEMDBF

      C:\ORACLE\ORADATA\testdb\UNDOTBSDBF

      C:\ORACLE\ORADATA\testdb\INDXDBF

      C:\ORACLE\ORADATA\testdb\TOOLSDBF

      C:\ORACLE\ORADATA\testdb\USERSDBF

    CHARACTER SET ZHSGBK

    ;
CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG
*
ERROR 位於第 行:
ORA: CREATE CONTROLFILE ??
ORA: ??????????

  ~~~~~~~~~~~~~~~~~~~~~~
如果是NORESETLOGS那麼他要檢查當前的在線日志而現在沒有了

  SQL> CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG

      SET STANDBY TO MAXIMIZE PERFORMANCE

        MAXLOGFILES

        MAXLOGMEMBERS

        MAXDATAFILES

        MAXINSTANCES

        MAXLOGHISTORY

    LOGFILE

      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

    STANDBY LOGFILE

    DATAFILE

      C:\ORACLE\ORADATA\testdb\SYSTEMDBF

      C:\ORACLE\ORADATA\testdb\UNDOTBSDBF

      C:\ORACLE\ORADATA\testdb\INDXDBF

      C:\ORACLE\ORADATA\testdb\TOOLSDBF

      C:\ORACLE\ORADATA\testdb\USERSDBF

    CHARACTER SET ZHSGBK

    ;
CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG
*
ERROR 位於第 行:
ORA: CREATE CONTROLFILE ??
ORA: ????C:\ORACLE\ORADATA\testdb\REDOLOG???  >>這個文件不在了
ORA: ??????
OSD: N^(r?*ND<~
O/SError: (OS ) OMUR;=V(DND<~!#

  SQL> CREATE CONTROLFILE REUSE DATABASE testdb RESETLOGS  ARCHIVELOG

      SET STANDBY TO MAXIMIZE PERFORMANCE

        MAXLOGFILES

        MAXLOGMEMBERS

        MAXDATAFILES

        MAXINSTANCES

        MAXLOGHISTORY

    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

    STANDBY LOGFILE

    DATAFILE

      C:\ORACLE\ORADATA\testdb\SYSTEMDBF

      C:\ORACLE\ORADATA\testdb\UNDOTBSDBF

      C:\ORACLE\ORADATA\testdb\INDXDBF

      C:\ORACLE\ORADATA\testdb\TOOLSDBF

      C:\ORACLE\ORADATA\testdb\USERSDBF

    CHARACTER SET ZHSGBK

    ;
CREATE CONTROLFILE REUSE DATABASE testdb RESETLOGS  ARCHIVELOG
*
ERROR 位於第 行:
ORA: CREATE CONTROLFILE ??
ORA: ????????
ORA: ????: C:\oracle\oradata\testdb\controlctl  這個文件不能被覆蓋刪除三個控制文件
ORA: skgfglk: ?????? ?????
OSD: N^(r?*ND<~
O/SError: (OS ) >\>xCNJ!#

  SQL> shutdown
ORA: ??????

  ORACLE 例程已經關閉
SQL> startup nomount
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE testdb RESETLOGS  ARCHIVELOG

      SET STANDBY TO MAXIMIZE PERFORMANCE

        MAXLOGFILES

        MAXLOGMEMBERS

        MAXDATAFILES

        MAXINSTANCES

        MAXLOGHISTORY

    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M

    STANDBY LOGFILE

    DATAFILE

      C:\ORACLE\ORADATA\testdb\SYSTEMDBF

      C:\ORACLE\ORADATA\testdb\UNDOTBSDBF

      C:\ORACLE\ORADATA\testdb\INDXDBF

      C:\ORACLE\ORADATA\testdb\TOOLSDBF

      C:\ORACLE\ORADATA\testdb\USERSDBF

    CHARACTER SET ZHSGBK

    ;

  控制文件已創建

  SQL> alter database open;
alter database open
*
ERROR 位於第 行:
ORA: ??????????? RESETLOGS ? NORESETLOGS ??

  SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR 位於第 行:
ORA: ?? ????????????
ORA: ???? : C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF

  SQL> recover database using backup controlfile until cancel;
ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}

  ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???
ORA: ??????????? C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}

  ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???
ORA: ??????????? C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}

  ORA: ???????? C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ??????
OSD: N^(r?*ND<~
O/SError: (OS ) OMUR;=V(DND<~!#

  SQL> recover database using backup controlfile until cancel;
ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
介質恢復已取消
SQL> alter database open resetlogs;

  數據庫已更改

  SQL> select count(*)status from arch group by status;

  COUNT(*) ST

     ok  還原了部分數據但不能還原在線日志中的數據

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
如果數據庫是abort或者老的數據文件備份那麼就涉及到控制文件和數據文件不一致需要恢復就涉及到當前被破壞的在線日志
啟動時仍然需要用在線活動日志進行恢復如果是正常的shutdown而且沒有用老的數據備份那麼控制文件和數據文件是一致的
不需要當前在線日志而在abort或者老的數據文件備份在這種情況下只能用備份的datafile和備份的controlfile來做不完
全恢復都將造成數據丟失因此多重controlfile 和 online redo log file 很重要通常情況下是在正常運行數據庫時
當前在線日志被破壞的此時馬上會數據庫不正常DOWN機也就出現的情景
我們知道如果是abort關閉的那麼有些事務是不完整的或者有些事務沒有被寫到數據文件在數據文件中有這樣的標識這樣
create controlfile noresetlogs或者resetlogs創建時讀取數據文件頭信息該文件在控制文件信息比如結束SCN設置為無窮大)
打開時就需要當前在線日志恢復
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
####################################################
# [測試] shutdown abort控制文件損壞備份控制文件
#         當前在線日志損壞有數據文件備份
####################################################

  還原原來備份的數據文件控制文件
SQL> shutdown
ORA: 數據庫未打開

  ORACLE 例程已經關閉
SQL> startup mount
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
ORA: ???????C:\oracle\ora\DATABASE\PWDtestdbORA

  SQL> recover database using backup controlfile ;
ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}

  ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???
ORA: ??????????? C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}

  ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???
ORA: ??????????? C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}

  ORA: ???????? C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ??????
OSD: N^(r?*ND<~
O/SError: (OS ) OMUR;=V(DND<~!#

  SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR 位於第 行:
ORA: ?? ??????
ORA: ???? : C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF

  SQL> select resetlogs_change# CONTROLFILE_CHANGE# from v$database;

  RESETLOGS_CHANGE# CONTROLFILE_CHANGE#

                            

  SQL> recover database using backup controlfile until cancel;
ORA: ?? (? // :: ??) ???? ????
ORA: ??: C:\ORACLE\ORADATA\TESTDB\ARCHIVE\_DBF
ORA: ?? ???? ???? # ???

  指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
介質恢復已取消
SQL> select resetlogs_change# CONTROLFILE_CHANGE# from v$database;

  RESETLOGS_CHANGE# CONTROLFILE_CHANGE#

                            

  SQL> alter database open resetlogs;

  數據庫已更改

  SQL> select count(*)status from arch group by status;

  COUNT(*) ST

     ok

  ######################################################                                               
# []  控制文件損壞如果trace不是最新的數據庫結構如少了個數據文件
######################################################   

  SQL> create table arch (status varchar());

  表已創建

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> insert into arch select ok from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> alter system switch logfile;

  系統已更改

  SQL> insert into arch select no from dba_objects;

  已創建

  SQL> commit;

  提交完成

  SQL> select GROUP#SEQUENCE#archived STATUS from v$log;

  GROUP#  SEQUENCE# ARC STATUS

                   NO  ACTIVE
                   YES ACTIVE
                   NO  CURRENT   
SQL> alter tablespace tools add datafile C:\ORACLE\ORADATA\TESTDB\TOOLSdbf
size m;

  表空間已更改

  SQL> shutdown
數據庫已經關閉
已經卸載數據庫
ORACLE 例程已經關閉

  模擬控制文件丟失

  SQL> CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG
      SET STANDBY TO MAXIMIZE PERFORMANCE
        MAXLOGFILES
        MAXLOGMEMBERS
        MAXDATAFILES
        MAXINSTANCES
        MAXLOGHISTORY
    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
  STANDBY LOGFILE
  DATAFILE
    C:\ORACLE\ORADATA\testdb\SYSTEMDBF
    C:\ORACLE\ORADATA\testdb\UNDOTBSDBF
    C:\ORACLE\ORADATA\testdb\INDXDBF
    C:\ORACLE\ORADATA\testdb\TOOLSDBF
    C:\ORACLE\ORADATA\testdb\USERSDBF
  CHARACTER SET ZHSGBK
  ;

  控制文件已創建

  SQL> alter database open;

  數據庫已更改

  SQL> select namestatus from v$datafile;

  NAME                                         STATUS
      
C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF        SYSTEM
C:\ORACLE\ORADATA\TESTDB\UNDOTBSDBF       ONLINE
C:\ORACLE\ORADATA\TESTDB\INDXDBF          ONLINE
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF         ONLINE
C:\ORACLE\ORADATA\TESTDB\USERSDBF             ONLINE
C:\ORACLE\ORA\DATABASE\MISSING        RECOVER 這個文件現在是recover狀態

  已選擇

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我們發現C:\ORACLE\ORA\DATABASE\MISSING並不存在只不過是個標記而已
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  SQL> alter database rename file MISSING to C:\ORACLE\ORADATA\TESTDB\TOOLSdbfMISSING不要加路徑

  數據庫已更改

  SQL> recover datafile C:\ORACLE\ORADATA\TESTDB\TOOLSdbf;
完成介質恢復

  SQL> alter database datafile C:\ORACLE\ORADATA\TESTDB\TOOLSdbf online;

  數據庫已更改

  ~~~~~~~~~~~~~~~~~~~~~~~~~
如果用備份控制文件且備份
控制文件少了新增加的兩個文件
恢復時會提示錯誤我們可以
用rename來解決
~~~~~~~~~~~~~~~~~~~~~~~~~
使用備份控制文件
recover AUTOMATIC   database using backup controlfile until cancel
      
ORA: recovery session canceled due to errors                  
ORA: unnamed datafile(s) added to controlfile by media recovery
ORA: data file : /oracle/dbs/dbf                         
ORA: data file : /oracle/dbs/dbf                         

  ~~~~~~~~~~~~~~~~~~~~
這是因為前滾時發現file#中
有兩個文件但控制文件沒有
我們可以在v$datafile中看到
所以恢復中斷
~~~~~~~~~~~~~~~~~~~~
SELECT FILE#NAME
FROM V$DATAFILE;

  FILE#           NAME

               /oracle/dbs/dbf
               /oracle/dbs/UNNAMED
               /oracle/dbs/UNNAMED

  這時對文件進行改名就可以了

  ALTER DATABASE RENAME FILE /db/UNNAMED TO /oracle/dbs/dbf;
ALTER DATABASE RENAME FILE /db/UNNAMED TO /oracle/dbs/dbf;

  RECOVER AUTOMATIC DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL

  ######################################################                               
# [] 控制文件損壞如果trace不是最新的數據庫結構如少了個只讀數據文件
###################################################### 

  SQL> alter tablespace tools add datafile C:\ORACLE\ORADATA\TESTDB\TOOLSdbf
size m ;

  表空間已更改                 
SQL> alter tablespace tools read only;

  表空間已更改
   
    SQL> select nameENABLED
     from v$datafile;

  NAME                                            ENABLED
            
C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF                READ WRITE
C:\ORACLE\ORADATA\TESTDB\UNDOTBSDBF                READ WRITE
C:\ORACLE\ORADATA\TESTDB\INDXDBF                READ WRITE
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF                READ ONLY
C:\ORACLE\ORADATA\TESTDB\USERSDBF                READ WRITE
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF                READ ONLY

  已選擇
SQL> startup nomount
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG
      SET STANDBY TO MAXIMIZE PERFORMANCE
        MAXLOGFILES
        MAXLOGMEMBERS
        MAXDATAFILES
        MAXINSTANCES
        MAXLOGHISTORY
    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
  STANDBY LOGFILE
  DATAFILE
    C:\ORACLE\ORADATA\testdb\SYSTEMDBF
    C:\ORACLE\ORADATA\testdb\UNDOTBSDBF
    C:\ORACLE\ORADATA\testdb\INDXDBF
    C:\ORACLE\ORADATA\testdb\TOOLSDBF
    C:\ORACLE\ORADATA\testdb\USERSDBF
  CHARACTER SET ZHSGBK
  ;

  控制文件已創建
SQL> select name from v$datafile;

  NAME

  C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF
C:\ORACLE\ORADATA\TESTDB\UNDOTBSDBF
C:\ORACLE\ORADATA\TESTDB\INDXDBF
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF
C:\ORACLE\ORADATA\TESTDB\USERSDBF
SQL> alter database open;

  數據庫已更改

  SQL> select name from v$datafile;

  NAME

  C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF
C:\ORACLE\ORADATA\TESTDB\UNDOTBSDBF
C:\ORACLE\ORADATA\TESTDB\INDXDBF
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF
C:\ORACLE\ORADATA\TESTDB\USERSDBF
C:\ORACLE\ORA\DATABASE\MISSING  OPEN時增加了不認識的文件名

  已選擇

  SQL> alter database rename file MISSING to C:\ORACLE\ORA\DATABASE\TOOL
SDBF;
alter database rename file MISSING to C:\ORACLE\ORA\DATABASE\TOOLSD
BF
*
ERROR 位於第 行:
ORA: 重命名日志/數據文件時出錯
ORA: 重命名數據文件 時出錯 未找到新文件
C:\ORACLE\ORA\DATABASE\TOOLSDBF
ORA: 數據文件 名稱未知 請重命名以更正文件
ORA: 數據文件 : C:\ORACLE\ORA\DATABASE\MISSING
ORA: 無法打開文件
OSD: 無法打開文件
O/SError: (OS ) 系統找不到指定的文件
*
ERROR 位於第 行:
ORA: ?? ??????
ORA: ???? : C:\ORACLE\ORADATA\TESTDB\TOOLSDBF

  SQL> alter database datafile C:\ORACLE\ORADATA\TESTDB\TOOLSDBF offline;

  數據庫已更改

  SQL> alter database datafile C:\ORACLE\ORADATA\TESTDB\TOOLSDBF offline;
alter database datafile C:\ORACLE\ORADATA\TESTDB\TOOLSDBF offline
*
ERROR 位於第 行:
ORA: ???????? ????????? C:\ORACLE\ORADATA\TESTDB\TOOLSDBF

  SQL> alter database open ;

  數據庫已更改

  SQL> alter database datafile MISSING offline;  >>注意只讀表空間必須先offline而且注意MISSING不能寫全路徑

  數據庫已更改

  SQL> alter database rename file  MISSING to C:\ORACLE\ORADATA\TESTDB\TOO
LSDBF;

  數據庫已更改
SQL> alter tablespace tools online;

  表空間已更改

  方法
SQL> SHUTDOWN
數據庫已經關閉
已經卸載數據庫
ORACLE 例程已經關閉
SQL> STARTUP NOMOUNT
ORACLE 例程已經啟動

  Total System Global Area  bytes
Fixed Size                   bytes
Variable Size              bytes
Database Buffers           bytes
Redo Buffers                 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE testdb NORESETLOGS  ARCHIVELOG

      SET STANDBY TO MAXIMIZE PERFORMANCE
        MAXLOGFILES
        MAXLOGMEMBERS
        MAXDATAFILES
        MAXINSTANCES
        MAXLOGHISTORY
    LOGFILE
      GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
    GROUP C:\ORACLE\ORADATA\testdb\REDOLOG  SIZE M
  STANDBY LOGFILE
  DATAFILE
    C:\ORACLE\ORADATA\testdb\SYSTEMDBF
    C:\ORACLE\ORADATA\testdb\UNDOTBSDBF
    C:\ORACLE\ORADATA\testdb\INDXDBF
    C:\ORACLE\ORADATA\testdb\TOOLSDBF
    C:\ORACLE\ORADATA\testdb\TOOLSDBF  創建語句中加入該數據文件
    C:\ORACLE\ORADATA\testdb\USERSDBF
  CHARACTER SET ZHSGBK
  ;

  控制文件已創建

  SQL> SELECT NAME FROM V$DATAFILE;

  NAME

  C:\ORACLE\ORADATA\TESTDB\SYSTEMDBF
C:\ORACLE\ORADATA\TESTDB\UNDOTBSDBF
C:\ORACLE\ORADATA\TESTDB\INDXDBF
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF
C:\ORACLE\ORADATA\TESTDB\USERSDBF
C:\ORACLE\ORADATA\TESTDB\TOOLSDBF

  已選擇

  SQL> ALTER DATABASE OPEN;
ALTER DATABASE OPEN
*
ERROR 位於第 行:
ORA: ?? ??????
ORA: ???? : C:\ORACLE\ORADATA\TESTDB\TOOLSDBF

  SQL> RECOVER TABLESPACE TOOLS;
完成介質恢復
SQL> ALTER DATABASE OPEN;

  數據庫已更改

  ##################################             
# [] 使用備份的控制文件進行恢復
#                    
##################################

  前面有很多例子


From:http://tw.wingwit.com/Article/program/Oracle/201311/17289.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.