在使用ASM建立oracle数据库的时候,ASM磁盘组的缺省冗余为normal(两路冗余),而大多数数据库系统都是建立在RAID存储上次,在存储上已经有了一个冗余以保证数据的安全,如果在ASM中再建立一个两路冗余,一来会浪费很多的存储空间,二来也会增加很大的存储IO负载。

 

而现实中有一些DBA在建立数据库的时候一路next,最后导致了两级冗余,更有甚者,甚至在ASM中建立磁盘组时选择HIGH(至少3路冗余),在性能和cost都是很大的浪费,这就需要在建库后修改磁盘组的冗余模式,而oracle没有提供直接修改ASM磁盘组冗余模式的手段,我们可以借助磁盘组替换来修改冗余模式,本次实验使用rmancopy-switch方法来实现数据文件磁盘组的替换,接下来还有备份恢复方式实现数据文件磁盘组的替换以及闪回磁盘组的替换;

 

替换的具体步骤为:

1)         查看ASM中磁盘组及磁盘的情况:

SYS@+ASM1 SQL>select name,state,type from v$asm_diskgroup;

NAME                           STATE                          TYPE

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

RACDAT                         MOUNTED          NORMAL

RACFRA                         MOUNTED          NORMAL

 

SYS@+ASM1 SQL> select group_number,disk_number,name,path from v$asm_disk;

GROUP_NUMBER DISK_NUMBER NAME                           PATH

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

           0        0                                /dev/oracleasm/disks/VOL6

           0        1                                /dev/oracleasm/disks/VOL5

           2         1 RACFRA_0001                    /dev/oracleasm/disks/VOL4

           1        1 RACDAT_0001                    /dev/oracleasm/disks/VOL2

           2        0 RACFRA_0000                    /dev/oracleasm/disks/VOL3

           1        0 RACDAT_0000                    /dev/oracleasm/disks/VOL1

6 rows selected.

假设在存储级已经做了RAID,现在将用一个无冗余的磁盘组替换磁盘组RATDAT

2)         数据库中数据库文件的存放情况:

@ SQL>conn / as sysdba

Connected.

SYS@racdb2 SQL>select name from v$datafile

 union

 select name from v$tempfile

 union

 select member from v$logfile

 union

 select filename from v$block_change_tracking

 union

 select name from v$controlfile

 order by 1;

NAME

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

+RACDAT/racdb/datafile/sysaux.257.775268603

+RACDAT/racdb/datafile/system.256.775268603

+RACDAT/racdb/datafile/tbs_test.270.781050709

+RACDAT/racdb/datafile/tbs_test2.271.781050815

+RACDAT/racdb/datafile/tbs_test2.272.781050871

+RACDAT/racdb/datafile/ts_big1.269.780845025

+RACDAT/racdb/datafile/ts_big2.268.780845053

+RACDAT/racdb/datafile/undotbs1.258.775268605

+RACDAT/racdb/datafile/undotbs2.264.775269055

+RACDAT/racdb/datafile/users.259.775268605

+RACDAT/racdb/onlinelog/group_1.261.775268843

+RACDAT/racdb/onlinelog/group_2.262.775268885

+RACDAT/racdb/onlinelog/group_3.265.775269149

+RACDAT/racdb/onlinelog/group_4.266.775269189

+RACDAT/racdb/tempfile/temp.263.775268947

+RACFRA/racdb/onlinelog/group_1.257.775268863

+RACFRA/racdb/onlinelog/group_2.258.775268909

+RACFRA/racdb/onlinelog/group_3.259.775269165

+RACFRA/racdb/onlinelog/group_4.260.775269213

3)         用两块备用磁盘建一个外部冗余的磁盘组RACDAT_EXT

SYS@+ASM1 SQL>create diskgroup racdat_ext external redundancy disk '/dev/oracleasm/disks/VOL5';

Diskgroup created.

 

SYS@+ASM1 SQL>alter diskgroup racdat_ext add disk '/dev/oracleasm/disks/VOL6';

Diskgroup altered.

 

SYS@+ASM1 SQL>select name,state,type from v$asm_diskgroup;

NAME                           STATE       TYPE

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

RACDAT                         MOUNTED     NORMAL

RACFRA                         MOUNTED     NORMAL

RACDAT_EXT                     MOUNTED     EXTERN

 

SYS@+ASM1 SQL>select group_number,disk_number,name,path from v$asm_disk;

GROUP_NUMBER DISK_NUMBER NAME                           PATH

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

           2         1 RACFRA_0001                    /dev/oracleasm/disks/VOL4

           3        1 RACDAT_EXT_0001                /dev/oracleasm/disks/VOL6

           3        0 RACDAT_EXT_0000                /dev/oracleasm/disks/VOL5

           1        1 RACDAT_0001                    /dev/oracleasm/disks/VOL2

           2        0 RACFRA_0000                    /dev/oracleasm/disks/VOL3

           1        0 RACDAT_0000                    /dev/oracleasm/disks/VOL1

 

6 rows selected.

 

SYS@+ASM1 SQL>select group_number,disk_number,name,path from v$asm_disk order by 1,2;

GROUP_NUMBER DISK_NUMBER NAME                           PATH

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

1       0      RACDAT_0000                    /dev/oracleasm/disks/VOL1

1    1       RACDAT_0001                    /dev/oracleasm/disks/VOL2

2    0       RACFRA_0000                    /dev/oracleasm/disks/VOL3

2    1      RACFRA_0001                    /dev/oracleasm/disks/VOL4

3       0      RACDAT_EXT_0000                /dev/oracleasm/disks/VOL5

3       1      RACDAT_EXT_0001                /dev/oracleasm/disks/VOL6

6 rows selected.

 

SYS@+ASM1 SQL>show parameter asm_diskgroup

 

NAME                    TYPE        VALUE

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

asm_diskgroups            string         RACDAT, RACFRA, RACDAT_EXT

4)         将控制文件备份到新建的磁盘组RACDAT_EXT并修改controlfile的指向:

SYS@racdb1 SQL>alter database backup controlfile to '+RACDAT_EXT';

Database altered.

 

[oracle@Linux1]asmcmd

ASMCMD> ls

RACDAT/

RACDAT_EXT/

RACFRA/

ASMCMD> cd racdat_ext

ASMCMD> ls

RACDB/

ASMCMD> cd racdb

ASMCMD> ls

CONTROLFILE/

ASMCMD> cd controlfile

ASMCMD> ls

Backup.256.781102479

 

SYS@racdb1 SQL>show parameter control

 

NAME                           TYPE        VALUE

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

control_file_record_keep_time           integer        7

control_files                      string         +RACDAT/racdb/controlfile/curr

                                             ent.258.781288271, +RACFRA

                                                /racdb/controlfile/current.263

                                                 .781288273

 

SYS@racdb1 SQL>alter system set control_files= '+RACDAT_EXT/racdb/controlfile/current.258.781288271', '+RACFRA_EXT/racdb/controlfile/current.263.781288273' SCOPE=spfile sid='*';

 

System altered.

 

SYS@racdb1 SQL>alter system set db_create_file_dest='+RACDAT_EXT'  scope=spfile SID='*';

System altered.

 

5)         由于spfile位于将要删除的磁盘组中,因此需要先在新磁盘组中创建一个spfile

SYS@racdb1 SQL>create pfile='/mnt/share/init_racdb.ora' from spfile;

File created.

 

SYS@racdb1 SQL>show parameter pfile  

NAME                        TYPE                           VALUE

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

spfile                                     string                        +RACDAT /racdb/spfileracdb. ora                                             

 

SYS@racdb1 SQL>create spfile='+RACDAT_EXT/racdb/spfileracdb.ora' from pfile='/mnt/share/init_racdb.ora';

File created.

6)         修改各个节点的pfile中对spfile的指向

[oracle@Linux1]cd $ORACLE_HOME/dbs

[oracle@Linux1]vi initracdb1.ora

SPFILE='+RACDAT_EXT/racdb/spfileracdb.ora'

 

[oracle@Linux2]cd $ORACLE_HOME/dbs

[oracle@Linux2]vi initracdb2.ora

SPFILE='+RACDAT_EXT/racdb/spfileracdb.ora'

 

7)         修改srvconfigspfile配置

[oracle@Linux1]srvctl config database -d racdb -a

linux1 racdb1 /u01/app/oracle/product/10.2.0/db_1

linux2 racdb2 /u01/app/oracle/product/10.2.0/db_1

 

(blog贴文不能超过8万字符,没办法,此处略去n段,具体见附件)

 

 

至此,已经用一个外部冗余的磁盘组RACDAT_EXT替换了一个两路冗余的磁盘组RACDAT