遷移Oracle資料庫檔案到ASM

來源:互聯網
上載者:User

遷移Oracle資料庫檔案到ASM

閱讀導航

  • 遷移資料檔案到ASM
  • 遷移記錄檔到ASM
  • 遷移控制檔案到ASM

遷移資料檔案到ASM

資料庫一致性情況下遷移:將資料庫啟動到mount狀態,產生rman copy 語句,然後在rman中執行:

SQL> startup mount
SQL> select q'(copy datafile ')'||name||q'(' to '+oradata';)' from v$datafile;
Q'(COPYDATAFILE')'||NAME||Q'('TO'+ORADATA';)'
-------------------------------------------------------------------------------
copy datafile 'D:\NSOADP\SYSTEM01.DBF' to '+oradata';
copy datafile 'D:\NSOADP\SYSAUX01.DBF' to '+oradata';
copy datafile 'F:\NSOADP\UNDOTBS01.DBF' to '+oradata';
copy datafile 'D:\NSOADP\USERS01.DBF' to '+oradata';
SQL> exit
D:\>rman target /
RMAN> run
2> {
3> copy datafile 'D:\NSOADP\SYSTEM01.DBF' to '+oradata';
4> copy datafile 'D:\NSOADP\SYSAUX01.DBF' to '+oradata';
5> copy datafile 'F:\NSOADP\UNDOTBS01.DBF' to '+oradata';
6> copy datafile 'D:\NSOADP\USERS01.DBF' to '+oradata';
7>}
啟動 backup 於 2015-04-15 10:02:44
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 啟動資料檔案副本
輸入資料檔案: 檔案號=00001 名稱=D:\NSOADP\SYSTEM01.DBF
輸出檔案名=+ORADATA/nsoa/datafile/system.260.877082571 標記=TAG20150415T100250 RECID=265 STAMP=877082603
通道 ORA_DISK_1: 資料檔案複製完畢, 經過時間: 00:00:35
完成 backup 於 2015-04-15 10:03:25
……

產生更改控制檔案資料名的語句,然後執行更改:

SQL> SELECT --T.NAME,T.FILE#,C.FILE#,C.NAME
  2  q'(ALTER DATABASE RENAME FILE ')'||c.name||q'(' to ')'||t.name||q'(';)'
  3  FROM V$DATAFILE_COPY T LEFT JOIN V$DATAFILE C
  4  ON T.FILE#=C.FILE#
  5  WHERE T.NAME IS NOT NULL  order by COMPLETION_TIME desc;

SQL> alter database rename file 'D:\NSOADP\SYSTEM01.DBF' to '+ORADATA/nsoa/datafile/system.260.877082571';

資料庫非一致性情況下遷移(歸檔模式):
使用 alter database datafile '' offline 命令將資料檔案offline,然後同上面的方式一樣處理,最後將資料檔案online

SQL> alter database datafile '/u01/oradata/sydb/user01.dbf' offline;

RMAN> copy datafile '/u01/oradata/sydb/user01.dbf' to '+oradata';

Starting backup at 23-APR-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=180 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/oradata/sydb/user01.dbf
output file name=+ORADATA/sydb/datafile/users.257.877803115 tag=TAG20150423T181155 RECID=1 STAMP=877803123
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 23-APR-15

SQL> alter database rename file '/u01/oradata/sydb/user01.dbf' to '+ORADATA/sydb/datafile/users.257.877803115';
SQL> alter database datafile '+ORADATA/sydb/datafile/users.257.877803115' online;
alter database datafile '+ORADATA/sydb/datafile/users.257.877803115' online
*
ERROR at line 1:
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '+ORADATA/sydb/datafile/users.257.877803115'
SQL> recover datafile '+ORADATA/sydb/datafile/users.257.877803115';
Media recovery complete.
SQL> alter database datafile '+ORADATA/sydb/datafile/users.257.877803115' online;

遷移記錄檔到ASM

可以在mount或open狀態遷移非current或active記錄檔到asm;方法將已有的記錄檔(每個日誌組必須有一個member)或日誌組(資料庫必須有兩個日誌組存在)刪除,然後添加新的記錄檔或日誌組;

alter database drop logfile member 'E:\NSOADP\REDO07.LOG';  #刪除記錄檔
alter database drop logfile group 2;  #刪除日誌組
alter database add logfile member '+oradata' to group 7;  #添加記錄檔
alter database add logfile ( '+oradata','oradata') size 50m;  #添加有兩個成員的日誌組
alter database add logfile '+oradata','oradata' size 50m;  #同時添加兩個日誌組

遷移控制檔案到ASM

 首先確定好控制檔案位置和名稱

SQL> show parameter control_file
NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer    7
control_files                        string      F:\NSOADP\CONTROL01.CTL

 修改control_files初始化參數值為asm,然後重啟資料庫到nomount狀態:

SQL> alter system set control_files='+oradata' scope=spfile;
SQL> shutdown immediate;
SQL> startup nomount

使用rman複製當前的控制檔案到asm

rman target /
RMAN> restore controlfile from 'F:\NSOADP\CONTROL01.CTL';
啟動 restore 於 2015-04-22 09:40:30
使用目標資料庫控制檔案替代恢複目錄
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=70 裝置類型=DISK

通道 ORA_DISK_1: 已複製控制檔案副本
輸出檔案名=+ORADATA/nsoa/controlfile/current.314.877686033
完成 restore 於 2015-04-22 09:40:39

注:如果使用備份的控制檔案進行還原,而資料庫以前有過RESETLOGS操作或建立控制檔案時建立語句指定了RESETLOGS,則必須以RESETLOGS方式開啟資料庫。


SQL> alter database mount;
SQL> show parameter control_file

NAME                                TYPE                  VALUE
------------------------------------ ---------------------- ------------------------------
control_file_record_keep_time        integer                7
control_files                        string                +ORADATA/nsoa/controlfile/curr
                                                            ent.314.877686033
SQL> alter database open;

 --Then end

如何將ASM中的資料檔案複製到作業系統中

Oracle 11g RAC ASM磁碟全部丟失後的恢複

Oracle 11g從入門到精通 PDF+光碟片原始碼

RHEL6 ASM方式安裝Oracle 11g R2

Oracle 10g 手工建立ASM資料庫

Oracle 10g R2建立ASM執行個體Step By Step

相關文章

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.