rac恢復到單例項

shilei1發表於2018-11-21



1、將使用rman備份的rac的備份檔案傳輸到異地單節點上
[oracle@ora0 ~]$ ls /data_back/racbk/
20120514_3snav1p2_1_1.bk  40nav1sh_1_1_20120514.arc  43nav1sh_1_1_20120514.arc    48nav1vu_1_1_20120514.ctl
20120514_3tnav1p2_1_1.bk  41nav1sh_1_1_20120514.arc  44nav1t7_1_1_20120514.arc
20120514_3unav1pa_1_1.bk  42nav1sh_1_1_20120514.arc  46nav1uq_1_1_20120514.spfil

2、解決pfile
[oracle@ora0 ~]$ rman target /
RMAN> startup

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/oracle/product/10.2.0/dbs/initora10g.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 05/14/2012 13:17:11
ORA-00205: error in identifying control file, check alert log for more info
#############報錯,不用理會############################
恢復spfile
RMAN> restore spfile from '/data_back/racbk/46nav1uq_1_1_20120514.spfil';

連入sql介面
SQL> conn /as sysdba
Connected.
SQL> select status from  v$instance;

STATUS
------------
STARTED

SQL> create pfile from spfile;

File created.

刪除spfile 修改pfile
從RAC資料庫中建立引數檔案,如果RAC使用PFILE,可以直接COPY後修改。
         修改的引數有: audit_file_dest, background_dump_dest, core_dump_dest,user_dump_dest, log_archive_dest_1等,
         與路徑有關的引數,修改為你單例項環境的對應路徑。如:
        background_dump_dest=/u01/oracle/ora/9.2.0/admin/DEV_dbtest/bdump
       重要的: 移除cluster_database_instances,cluster_database引數,因為恢復到的是單例項環境。
                      移除一個UNDO_TABLESPACE設定,這裡假設保留的是APPS_UNDOTBS1

#############################
*.audit_file_dest='/u01/oracle/admin/db/adump'
*.background_dump_dest='/u01/oracle/admin/db/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/oracle/product/10.2.0/dbs/control_01.ctl'
*.core_dump_dest='/u01/oracle/admin/db/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='db'
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=/home/oracle/arc'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=283115520
*.undo_management='AUTO'
undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/oracle/admin/db/udump'
################################################
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  2020224 bytes
Variable Size              92277888 bytes
Database Buffers          188743680 bytes
Redo Buffers                2170880 bytes
SQL>

3、恢復控制檔案,啟動資料庫到mount狀態
RMAN> restore controlfile from '/data_back/racbk/48nav1vu_1_1_20120514.ctl';
RMAN> alter database mount;
database mounted
released channel: ORA_DISK

4、修改資料檔案和日誌檔案路徑
select 'set newname  for datafile '||chr(39)||name||chr(39)||' to '||chr(39)||replace(name,'+DG0/db/datafile/','/home/oracle/data2/')||chr(39)||';' from v$datafile;
#######################

SQL> select 'set newname  for datafile '||chr(39)||name||chr(39)||' to '||chr(39)||replace(name,'+DG0/db/datafile/','/home/oracle/data2/')||chr(39)||';' from v$datafile;

'SETNEWNAMEFORDATAFILE'||CHR(39)||NAME||CHR(39)||'TO'||CHR(39)||REPLACE(NAME,'+DG0/DB/DATAFILE/','/HOME/ORACLE/DATA2/')||CHR(39)||';'
------------------------------------------------------------------------------------------------------------------------------------------------------
set newname  for datafile '+DG0/db/datafile/sysaux.257.780159407' to '/home/oracle/data2/sysaux.257.780159407';
set newname  for datafile '+DG0/db/datafile/system.256.780159407' to '/home/oracle/data2/system.256.780159407';
set newname  for datafile '+DG0/db/datafile/timelineweb01.dbf' to '/home/oracle/data2/timelineweb01.dbf';
set newname  for datafile '+DG0/db/datafile/undotbs1.258.780159409' to '/home/oracle/data2/undotbs1.258.780159409';
set newname  for datafile '+DG0/db/datafile/undotbs2.264.780159511' to '/home/oracle/data2/undotbs2.264.780159511';
set newname  for datafile '+DG0/db/datafile/users.259.780159409' to '/home/oracle/data2/users.259.780159409';

6 rows selected.

######################
5. 恢復資料庫到新的目錄(我的環境是原來是RAW恢復到檔案系統)
 select 'alter database rename file  '||chr(39)||member||chr(39)||' to '||chr(39)||replace(member,'+DG0/db/onlinelog/','/home/oracle/data2/')||chr(39)||';' from v$logfile;
SQL>  select 'alter database rename file  '||chr(39)||member||chr(39)||' to '||chr(39)||replace(member,'+DG0/db/onlinelog/','/home/oracle/data2/')||chr(39)||';' from v$logfile;

'ALTERDATABASERENAMEFILE'||CHR(39)||MEMBER||CHR(39)||'TO'||CHR(39)||REPLACE(MEMBER,'+DG0/DB/ONLINELOG/','/HOME/ORACLE/DATA2/')||CHR(39)||';'
------------------------------------------------------------------------------------------------------------------------------------------------------
alter database rename file  '+DG0/db/onlinelog/group_2.262.780159469' to '/home/oracle/data2/group_2.262.780159469';
alter database rename file  '+DG0/db/onlinelog/group_1.261.780159467' to '/home/oracle/data2/group_1.261.780159467';
alter database rename file  '+DG0/db/onlinelog/group_3.265.780159539' to '/home/oracle/data2/group_3.265.780159539';
alter database rename file  '+DG0/db/onlinelog/group_4.266.780159539' to '/home/oracle/data2/group_4.266.780159539';

在sql介面執行與日誌檔案有關的語句:
alter database rename file  '+DG0/db/onlinelog/group_2.262.780159469' to '/home/oracle/data2/group_2.262.780159469';
alter database rename file  '+DG0/db/onlinelog/group_1.261.780159467' to '/home/oracle/data2/group_1.261.780159467';
alter database rename file  '+DG0/db/onlinelog/group_3.265.780159539' to '/home/oracle/data2/group_3.265.780159539';
alter database rename file  '+DG0/db/onlinelog/group_4.266.780159539' to '/home/oracle/data2/group_4.266.780159539';

在rman介面執行如下指令碼:

RMAN> catalog start with '/data_back/racbk/';
查出catalog的scn號
Rman > list backup #找出最大的scn
然後執行如下指令碼
run {
set newname  for datafile '+DG0/db/datafile/sysaux.257.780159407' to '/home/oracle/data2/sysaux.257.780159407';
set newname  for datafile '+DG0/db/datafile/system.256.780159407' to '/home/oracle/data2/system.256.780159407';
set newname  for datafile '+DG0/db/datafile/timelineweb01.dbf' to '/home/oracle/data2/timelineweb01.dbf';
set newname  for datafile '+DG0/db/datafile/undotbs1.258.780159409' to '/home/oracle/data2/undotbs1.258.780159409';
set newname  for datafile '+DG0/db/datafile/undotbs2.264.780159511' to '/home/oracle/data2/undotbs2.264.780159511';
set newname  for datafile '+DG0/db/datafile/users.259.780159409' to '/home/oracle/data2/users.259.780159409';
set until scn 1385018;
restore database ;
switch datafile all;
recover database;
}

6,開啟資料庫
SQL> alter database open resetlogs;

Database altered.

7、
處理臨時檔案:
先建立一個臨時表空間temp1
SQL> create temporary tablespace temp1 tempfile  '/home/oracle/data2/temp2.dbf' size 512m  autoextend on next 1m maxsize unlimited;

Tablespace created.
SQL> alter database default temporary tablespace temp1;

Database altered.

刪掉不用的undo表空間及檔案
SQL> select tablespace_name,status from dba_data_files;

TABLESPACE_NAME                STATUS
------------------------------ ---------
USERS                          AVAILABLE
SYSAUX                         AVAILABLE
UNDOTBS1                       AVAILABLE
SYSTEM                         AVAILABLE
UNDOTBS2                       AVAILABLE
TIMELINEWEB                    AVAILABLE

6 rows selected.

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS1
SQL> drop tablespace undotbs2 including contents and datafiles;

Tablespace dropped.

SQL>

刪除透過RMAN回覆過來的臨時檔案。完成臨時檔案的整個處理過程。
SQL> drop tablespace temp including contents and datafiles;
Tablespace dropped.

刪除不用的日誌
select thread#,status,enabled from v$thread; --查詢thread,那個可以刪除

SQL> select thread#,status,enabled from v$thread;

   THREAD# STATUS ENABLED
---------- ------ --------
         1 OPEN   PUBLIC
         2 CLOSED PUBLIC

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1          0   52428800          1 YES UNUSED                       0
         2          1          1   52428800          1 NO  CURRENT                1385019 14-MAY-12
         3          2          0   52428800          1 YES UNUSED                       0
         4          2          1   52428800          1 NO  CURRENT                1385019 14-MAY-12

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                        IS_
---------- ------- ------- --------------------------------------------- ---
         2         ONLINE  /home/oracle/data2/group_2.262.780159469      NO
         1         ONLINE  /home/oracle/data2/group_1.261.780159467      NO
         3         ONLINE  /home/oracle/data2/group_3.265.780159539      NO
         4         ONLINE  /home/oracle/data2/group_4.266.780159539      NO

SQL> ALTER DATABASE DISABLE THREAD 2;

Database altered.

SQL> alter database drop logfile group 3
  2  ;

Database altered.

SQL> alter database drop logfile group 4;
alter database drop logfile group 4
*
ERROR at line 1:
ORA-00350: log 4 of instance db2 (thread 2) needs to be archived
ORA-00312: online log 4 thread 2: '/home/oracle/data2/group_4.266.780159539'

SQL>  alter database clear unarchived logfile group 4;

Database altered.

SQL> alter database drop logfile group 4;

Database altered.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1          0   52428800          1 YES UNUSED                       0
         2          1          1   52428800          1 NO  CURRENT                1385019 14-MAY-12

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                        IS_
---------- ------- ------- --------------------------------------------- ---
         2         ONLINE  /home/oracle/data2/group_2.262.780159469      NO
         1         ONLINE  /home/oracle/data2/group_1.261.780159467      NO

SQL>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/196700/viewspace-2220927/,如需轉載,請註明出處,否則將追究法律責任。

相關文章