asm 檔案系統遷移

perfychi發表於2012-08-28

此文是在oracle10g的基礎上,將管理的檔案系統上。

一、環境:

OS :

[oracle@yitai ~]$ lsb_release --all
LSB Version:    :core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch
Distributor ID: RedHatEnterpriseAS
Description:    Red Hat Enterprise Linux AS release 4 (Nahant Update 7)
Release:        4
Codename:       NahantUpdate7

RDBMS:

SQL> SELECT * FROM V$VERSION;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

ASM:(這裡使用磁碟組DATA2)

SQL> select name, state, type from v$asm_diskgroup;

NAME                           STATE       TYPE
------------------------------ ----------- ------
DATA1                          MOUNTED     EXTERN
DATA2                          MOUNTED     EXTERN

[oracle@yitai ~]$ export ORACLE_SID=+ASM
[oracle@yitai ~]$ asmcmd
ASMCMD> lsdg
State    Type    Rebal  Unbal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Name
MOUNTED  EXTERN  N      N         512   4096  1048576      2038      763                0             763              0  DATA1/
MOUNTED  EXTERN  N      N         512   4096  1048576      2038      929                0             929              0  DATA2/

二、遷移前檢視rdbms的資訊

檢視當前檔案系統的控制檔案路徑

SQL> select name from v$controlfile;

NAME
-------------------------------------------------------------------------------
/u01/app/oracle/oradata/prod/control01.ctl
/u01/app/oracle/oradata/prod/control02.ctl
/u01/app/oracle/oradata/prod/control03.ctl

檢視臨時檔案資訊

SQL>SQL> select  file#,  name  from v$tempfile;
FILE#, NAME
 --   --------------------------------------------------------------------------------
  1   /u01/app/oracle/oradata/prod/temp01.dbf

檢視日誌檔案資訊:

SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;

    GROUP# MEMBER                                                       STATUS
---------- ------------------------------------------------------------ ----------------
         1 /u01/app/oracle/oradata/prod/redo01.log                  CURRENT
         2 /u01/app/oracle/oradata/prod/redo02.log                  INACTIVE
         3 /u01/app/oracle/oradata/prod/redo03.log               INACTIVE

檢視資料檔案位置:

SQL> select name from v$datafile;

NAME

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

 /u01/app/oracle/oradata/prod//system01.dbf
 /u01/app/oracle/oradata/prod/undotbs01.dbf
 /u01/app/oracle/oradata/prod/sysaux01.dbf
 /u01/app/oracle/oradata/prod//users01.dbf
 /u01/app/oracle/oradata/prod//example01.dbf

 

三、利用RMAN工具遷移

export ORACLE_SID=prod

SQL > shutdown immediate

SQL > startup nomount    #rdbms操作控制檔案的時候,需要進入nomount狀態

[oracle@yitai ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Aug 28 08:01:45 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: CUUG (DBID=1247937484)

轉移控制檔案

RMAN> restore controlfile to '+DATA2' from '/u01/app/oracle/oradata/prod/control01.ctl';

Starting restore at 21-AUG-12ITPUB個人空間.K&e;\r}J
using channel ORA_DISK_1
channel ORA_DISK_1: copied control file copy
Finished restore at 21-AUG-12

檢視新的控制檔案

ASMCMD> cd +DATA2
ASMCMD> ls
PROD/
DB_UNKNOWN/
ASMCMD> cd  prod
ASMCMD> ls
CONTROLFILE/
ASMCMD> find -t controlfile . *
+DATA2/prod/CONTROLFILE/Backup.262.792483465
+DATA2/prod/CONTROLFILE/backup.256.792483231

 

修改當前系統的控制檔案引數相關

SQL> alter system set control_files='+DATA2/prod/CONTROLFILE/Backup.262.792483465,  +DATA2/prod/CONTROLFILE/backup.256.792483231' scope=spfile;
 
System altered.
 
SQL> shutdown immediate
ORA-01507: database not mounted
RACLE instance shut down.
 
SQL> startup mount;  #運算元據檔案,臨時檔案,日誌檔案rdbms需要進入mount狀態(因為前面的控制檔案已經完成,所以這裡進入mount狀態是完全沒問題的)
 
ORACLE instance started.
 
將資料庫檔案系統到ASM磁碟組
 
[oracle@yitai ~]$ rman target /     
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Aug 28 08:08:37 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: CUUG (DBID=1247937484)
 
RMAN> BACKUP AS COPY DATABASE FORMAT '+DATA2';
 
將資料庫檔案系統切換到ASM磁碟組
 
RMAN> SWITCH DATABASE TO COPY;
datafile 1 switched to datafile  +DATA2/prod/datafile/system.257.792483427
datafile 2 switched to datafile +DATA2/prod/datafile/undotbs1.260.792483461
datafile 3 switched to datafile +DATA2/prod/datafile/sysaux.258.792483441
datafile 4switched to datafile +DATA2/prod/datafile/users.261.792483463
datafile 5 switched to datafile
+DATA2/prod/datafile/example.259.792483457
 
修改臨時檔案
RMAN > run {
set newname for tempfile 1 to '+DATA2';
switch tempfile all;
}
 
或者 處於mount狀態,重新在+DATA2上建立一個臨時檔案,然後再刪除掉以前檔案系統的臨時檔案。這兩種方法都可以轉移tempfile.
 
如果是之前一致性關閉資料庫(shutdown immediate),可以直接刪掉檔案系統上的日誌檔案然後在+DATA2上重建,或者是rename 日誌檔案到+DATA2上。這些方法都可行,不過這裡這兩種方法沒有采用。而採用是開庫以後,在+DATA2上增加了新的日誌檔案, 在檔案系統上刪除掉舊的日誌檔案。這三種方法都可以轉移日誌檔案。第三種方法如下:
 
 

引數檔案

RMAN> run {

backup as backupset spfile;

restore spfile to "+DATA2/spfileprod.ora";

}

 
修改initprod.ora內容如下:
spfile=+DATA2/spfileprod.ora
 
RMAN> ALTER DATABASE OPEN;
database opened
 
[oracle@yitai ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Aug 28 08:24:59 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;

    GROUP# MEMBER                                                       STATUS
---------- ------------------------------------------------------------ ----------------
         1 /u01/app/oracle/oradata/prod/redo01.log                  CURRENT
         2 /u01/app/oracle/oradata/prod/redo02.log                  INACTIVE
         3 /u01/app/oracle/oradata/prod/redo03.log               INACTIVE

SQL> ALTER DATABASE ADD LOGFILE MEMBER '+DATA2' TO GROUP 1;

SQL> ALTER DATABASE ADD LOGFILE MEMBER '+DATA2' TO GROUP 2;
 
SQL> ALTER DATABASE ADD LOGFILE MEMBER '+DATA2' TO GROUP 3;
 
SQL> alter system checkpoint; #這個是把日誌的狀態從active 變為inactive,active的日誌是不允許刪除的  (不行的話就試試alter system swith logfile,切換日誌,因為狀態是current的日誌也不允許刪除的)
 
SQL> /
 
System altered.
 
SQL> /
 
System altered.
SQL> /
 
System altered.
 
SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;
GROUP# MEMBER                                                       STATUS
---------- ------------------------------------------------------------ ----------------
         1 /u01/app/oracle/oradata/prod/redo01.log                  CURRENT
         2 /u01/app/oracle/oradata/prod/redo02.log                  INACTIVE
         3 /u01/app/oracle/oradata/prod/redo03.log               INACTIVE
        1 +DATA2/prodonlinelog/group_1.265.792483781                  inactive
         2 +DATA2/prod/onlinelog/group_2.266.792483795                  INACTIVE
         3 +DATA2/prod/onlinelog/group_3.267.792483801                  INACTIVE

SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u01/app/oracle/oradata/prod/redo03.log';

SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u01/app/oracle/oradata/prod/redo02.log';

SQL> alter system switch logfile;   #切一下日誌才能刪除redo01.log,因為當前狀態是current,正在使用
System altered.
SQL> alter system checkpoint;
SQL > /

    GROUP# MEMBER                                                       STATUS
---------- ------------------------------------------------------------ ----------------
         1 /u01/app/oracle/oradata/prod/redo01.log                  inactive         2 /u01/app/oracle/oradata/prod/redo02.log                  INACTIVE
         3 /u01/app/oracle/oradata/prod/redo03.log               INACTIVE

         1 +DATA2/prodonlinelog/group_1.265.792483781                  CURRENT
         2 +DATA2/prod/onlinelog/group_2.266.792483795                  INACTIVE
         3 +DATA2/prod/onlinelog/group_3.267.792483801                  INACTIVE

SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;
 
GROUP# MEMBER                                                       STATUS
---------- ------------------------------------------------------------ ----------------
         1 +DATA2/pord/onlinelog/group_1.265.792483781                  CURRENT
         2 +DATA2/prod/onlinelog/group_2.266.792483795                  INACTIVE
         3 +DATA2/prod/onlinelog/group_3.267.792483801                  INACTIVE
 

SQL> select file#, name from v$tempfile;
     FILE# NAME
---------- ------------------------------------------------------------
         1 +DATA2/prod/tempfile/temp.264.792483707
 
SQL> select name from v$datafile;
NAME
------------------------------------------------------------
+DATA2/prod/datafile/system.257.792483427
+DATA2/prod/datafile/undotbs1.260.792483461
+DATA2/prod/datafile/sysaux.258.792483441
+DATA2/prod/datafile/users.261.792483463
+DATA2/prod/datafile/example.259.792483457
 
[oracle@yitai ~]$ vi /u01/app/oracle/product/10.2.0/db_1/dbs/initprod.ora
spfile='+DATA1/prod/spfileprod.ora'
 
檢視asm檔案結構
 
[oracle@yitai ~]$ export ORACLE_SID=+ASM
[oracle@yitai ~]$ asmcmd
ASMCMD> cd +DATA2
ASMCMD> ls
PROD/
ASMCMD> cd prod(# asmcmd不區分大小寫)
ASMCMD> ls
BACKUPSET/
CONTROLFILE/
DATAFILE/
ONLINELOG/
TEMPFILE/
spfilecuug.ora

 
重啟rdbms資料庫,檢視spfile位置是否修改成功
 
SQL> shutdown immediate
SQL > startup
SQL> show parameter spfile
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      +DATA2/prod/spfilecuug.ora
 
查詢測試 :
SQL> select * from scott.emp;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
 
到此全部OK了。 GOOK LUCK WITH YOU!
 

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

相關文章