1. 程式人生 > >oracle資料庫檔案系統遷移到ASM

oracle資料庫檔案系統遷移到ASM

檢視ASM磁碟組

SQL> select name,state from  v$asm_diskgroup;

登陸RMAN執行映象全備到ASM磁碟組

$rman target /
RMAN> backup as copy database format '+data';

Starting backup at 01-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=13 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf
output file name=+DATA/prod1/datafile/system.260.900002069 tag=TAG20160101T163428 RECID=22 STAMP=900002071
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
output file name=+DATA/prod1/datafile/sysaux.259.900002071 tag=TAG20160101T163428 RECID=23 STAMP=900002074
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
output file name=+DATA/prod1/datafile/undotbs1.261.900002079 tag=TAG20160101T163428 RECID=24 STAMP=900002080
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/test01.dbf
output file name=+DATA/prod1/datafile/test1.262.900002083 tag=TAG20160101T163428 RECID=25 STAMP=900002082
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/app/oracle/oradata/PROD1/test02.dbf
output file name=+DATA/prod1/datafile/test2.258.900002083 tag=TAG20160101T163428 RECID=26 STAMP=900002083
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/t1.dbf
output file name=+DATA/prod1/datafile/t1.257.900002085 tag=TAG20160101T163428 RECID=27 STAMP=900002084
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf<pre name="code" class="plain">RMAN> restore controlfile from '/u01/app/oracle/oradata/PROD1/control02.ctl';

Starting restore at 01-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=+DATA/prod1/controlfile/current.263.900003463
Finished restore at 01-JAN-16

修改檔案建立預設位置和控制檔案位置

SQL> alter system set control_files='+data' scope=spfile;

System altered.

SQL> alter system set db_create_file_dest='+data' scope=spfile;

System altered.
重啟
SQL> shutdown immediate
SQL> startup

遷移控制檔案

RMAN> startup nomount
RMAN> restore controlfile from '/u01/app/oracle/oradata/PROD1/control02.ctl';

Starting restore at 01-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=+DATA/prod1/controlfile/current.263.900003463
Finished restore at 01-JAN-16
遷移資料檔案
RMAN> alter database mount;
RMAN> switch database to copy; 
RMAN> recover database;     #一致性備份不需要)
RMAN> alter database open;
遷移日誌檔案

建立新檔案,刪除老檔案。(日誌組處於INACTIVE狀態才可以刪除)

SQL> select group#,status from v$log;
強制切換日誌組改變日誌組狀態
SQL> alter system switch logfile;

刪除老的日誌組(刪一個,加一個)

SQL> alter database drop logfile group 3;
Database altered.
SQL> alter database drop logfile group 1;
Database altered.
SQL> alter database drop logfile group 2;
Database altered.

增加日誌組到ASM

SQL> alter database add logfile group 3 '+data' size 50m;
Database altered.
SQL> alter database add logfile group 1 '+data' size 50m;
Database altered.
SQL> alter database add logfile group 2 '+data' size 50m;
Database altered.
遷移初始化檔案
SQL> create pfile from spfile;
File created.
SQL> create spfile='+data' from pfile;
File created.
vi $ORACLE_HOME/dbs/initPROD1.ora
spfile='+data/db_unknown/parameterfile/SPFILE.263.905991571'
mv spfilePROD1.ora spfilePROD1.ora.bak
遷移temp檔案
SQL> select name from v$tempfile;
SQL> alter tablespace temp add tempfile '+data';
SQL> alter tablespace temp drop tempfile '/u01/app/oracle/oradata/PROD1/temp01.dbf';
SQL> select name from v$tempfile;

檢視遷移的檔案

SQL> select name from v$datafile union select name from v$tempfile union select name from v$controlfile union select member from v$logfile;

NAME
----------------------------------------------------------------------------------------------------
+DATA/prod1/controlfile/current.263.900003463
+DATA/prod1/datafile/sysaux.259.900002071
+DATA/prod1/datafile/system.260.900002069
+DATA/prod1/datafile/t1.257.900002085
+DATA/prod1/datafile/test1.262.900002083
+DATA/prod1/datafile/test2.258.900002083
+DATA/prod1/datafile/undotbs1.261.900002079
+DATA/prod1/datafile/users.256.900002085
+DATA/prod1/onlinelog/group_1.265.900005697
+DATA/prod1/onlinelog/group_2.267.900005919
+DATA/prod1/onlinelog/group_3.266.900005729
+DATA/prod1/tempfile/temp.268.900006743
SQL>show parameter pfile;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
spfile				     string	 +DATA/db_unknown/parameterfile
						 /spfile.263.905991571