在Oracle 10G下玩转ASM

一 ASM的安装
1 到oralce 官方网站现在ASMlib包

[root@sunblaze ~]# ls |grep asm
oracleasm-2.6.9-42.ELsmp-2.0.3-1.i686.rpm
oracleasmlib-2.0.4-1.el4.i386.rpm
oracleasm-support-2.1.7-1.el4.i386.rpm
2 安装ASMlib
[root@sunblaze ~]# rpm -ivh oracleasm-support-2.1.7-1.el4.i386.rpm
warning: oracleasm-support-2.1.7-1.el4.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516
Preparing...                ########################################### [100%]
   1racleasm-support      ########################################### [100%]
[root@sunblaze ~]# rpm -ivh oracleasm-
oracleasm-2.6.9-42.ELsmp-2.0.3-1.i686.rpm  oracleasm-support-2.1.7-1.el4.i386.rpm   
[root@sunblaze ~]# rpm -ivh oracleasm-2.6.9-42.ELsmp-2.0.3-1.i686.rpm
Preparing...                ########################################### [100%]
   1racleasm-2.6.9-42.ELsm########################################### [100%]
[root@sunblaze ~]# rpm -ivh oracleasmlib-2.0.4-1.el4.i386.rpm
warning: oracleasmlib-2.0.4-1.el4.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516
Preparing...                ########################################### [100%]
   1racleasmlib           ########################################### [100%]
3 查看安装后的包

[root@sunblaze ~]# rpm -qa |grep asm
oracleasmlib-2.0.4-1.el4
oracleasm-support-2.1.7-1.el4
ibmasm-3.0-7
oracleasm-2.6.9-42.ELsmp-2.0.3-1


[root@sunblaze ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        6387    51199155   83  Linux
/dev/sda3            6388        6642     2048287+  82  Linux swap
[root@sunblaze ~]# init 0


二 为ASM做空间层面准备

在虚拟机上增加磁盘

这里要说一下ASM选用设备的三种类型
1 裸设备 生产系统常用
2 块设备 用的较少 (本次实验选用此种方式,因为此种方式不需要配置裸设备,能省则省)
3 普通文件  没见用过

1 查看设备
root@sunblaze ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        6387    51199155   83  Linux
/dev/sda3            6388        6642     2048287+  82  Linux swap

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table


2建立分区

[root@sunblaze ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 26108.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n  
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-26108, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-26108, default 26108): +5G

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@sunblaze ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         609     4891761   83  Linux
[root@sunblaze ~]# fdisk  /dev/sdb

The number of cylinders for this disk is set to 26108.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (610-26108, default 610):
Using default value 610
Last cylinder or +size or +sizeM or +sizeK (610-26108, default 26108): +6G

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@sunblaze ~]# fdisk /dev/sdb -l

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         609     4891761   83  Linux
/dev/sdb2             610        1339     5863725   83  Linux
3 修改Oracle属主
[root@sunblaze ~]# chown oracleinstall /dev/sdb*
[root@sunblaze ~]# ls /dev/sdb*
/dev/sdb  /dev/sdb1  /dev/sdb2

4 查看属主
[root@sunblaze ~]# ls /dev/sdb* -l
brw-rw----  1 oracle oinstall 8, 16 Jun 13  2012 /dev/sdb
brw-rw----  1 oracle oinstall 8, 17 Jun 12 17:16 /dev/sdb1
brw-rw----  1 oracle oinstall 8, 18 Jun 12 17:16 /dev/sdb2

5 讲修改属主命令记录到开机启动命令文件中

[root@sunblaze ~]# vi /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

chown oracleinstall /dev/sdb*

touch /var/lock/subsys/local
~                                    

6 配置ASM

root@sunblaze ~]# /etc/init.d/oracleasm configure
Configuring the Oracle ASM library driver.

This will configure the on-boot properties of the Oracle ASM library
driver.  The following questions will determine whether the driver is
loaded on boot and what permissions it will have.  The current values
will be shown in brackets ('[]').  Hitting <ENTER> without typing an
answer will keep that current value.  Ctrl-C will abort.

Default user to own the driver interface []: oracle
Default group to own the driver interface []: oinstall
Start Oracle ASM library driver on boot (y/n) [n]: y
Scan for Oracle ASM disks on boot (y/n) [y]: y
Writing Oracle ASM library driver configuration: done
Initializing the Oracle ASMLib driver:                     [  OK  ]
Scanning the system for Oracle ASMLib disks:               [  OK  ]


7  创建并查看磁盘
[root@sunblaze ~]# /etc/init.d/oracleasm createdisk VOL1 /dev/sdb1
Marking disk "VOL1" as an ASM disk:                        [  OK  ]
[root@sunblaze ~]# /etc/init.d/oracleasm createdisk VOL2 /dev/sdb2
Marking disk "VOL2" as an ASM disk:                        [  OK  ]
[root@sunblaze ~]# /etc/init.d/oracleasm listdisks
VOL1
VOL2


8 创建CSS进程,以便使用ASM

如跳过这步讲会报错ORA-29701

[root@sunblaze ~]# /u01/oracle/product/OraHome/bin/localconfig add
/etc/oracle does not exist. Creating it now.
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
Configuration for local CSS has been initialized

Adding to inittab
Startup will be queued to init within 90 seconds.
Checking the status of new Oracle init process...
Expecting the CRS daemons to be up within 600 seconds.
CSS is active on these nodes.
        sunblaze
CSS is active on all nodes.
Oracle CSS service is installed and running under init(1M)

[root@sunblaze ~]# /u01/oracle/product/OraHome/bin/crsctl check crs
CSS appears healthy
Cannot communicate with CRS
Cannot communicate with EVM


################################################################################
注:如果失败
则运行
1 $ORALCE_HOME/bin/localconfig delete
2 $ORACLE_HOME/root.sh
3 $ORALCE_HOME/bin/localconfig  add
################################################################################



[oracle@sunblaze admin]$ cp -R  orcl/ +ASM



三 创建ASM实例


[oracle@sunblaze bdump]$ cd $ORACLE_HOME/dbs
[oracle@sunblaze dbs]$ ls
hc_orcl.dat  initdw.ora  init.ora  lkORCL  orapworcl  spfileorcl.ora
创建密码文件
[oracle@sunblaze dbs]$ orapwd file=orapw+ASM entries=5 password=asm
为ASM实例 创建pfile
$ vi $ORACLE_HOME/dbs/init+ASM.ora
################################################################################
*._asm_allow_only_raw_disks=false
*.asm_diskgroups='DG1','DG2'
*.asm_diskstring='ORCL:VOL1','ORCL:VOL2'
*.background_dump_dest='/u01/oracle/admin/+ASM/bdump'
*.compatible='10.2.0.1.0'
*.core_dump_dest='/u01/oracle/admin/+ASM/cdump'
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='exclusive'
*.user_dump_dest='/u01/oracle/admin/+ASM/udump'
################################################################################
[oracle@sunblaze dbs]$ export ORACLE_SID=+ASM
[oracle@sunblaze dbs]$ sqlplus / as sysDBA

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jun 12 17:48:20 2012

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

startupConnected to an idle instance.
启动实例

SQL>
ASM instance started

Total System Global Area   83886080 bytes
Fixed Size                  1217836 bytes
Variable Size              57502420 bytes
ASM Cache                  25165824 bytes
ORA-15110: no diskgroups mounted


创建磁盘组

SQL> create diskgroup DG1 external redundancy  disk 'ORCL:VOL1';

Diskgroup created.

SQL> create diskgroup DG2 external redundancy  disk 'ORCL:VOL2';

Diskgroup created.

注:
################################################################################

ASM_DISKSTRING: 定义哪些磁盘可以被ASM 使用, ASM 实例启动时就根据这个参数值扫描发现ASM磁盘,
                配置了这个参数以后,还必须确认ORACLE 用户对这些磁盘有操作的权限
1. 如果使用裸设备, 用逗号分隔每个设备名:
  Asm_diskstring='/dev/raw/raw1','/dev/raw/raw2','/dev/raw/raw3'
2. 如果使用ASMLib时,就需要使用"ORCL:磁盘名"
Asm_diskstring='ORCL:VOL1'
3. 使用ASMLib 时, 也可以使用通配符
Asm_diskstring='ORCL:VOL*'
################################################################################



ASM查看脚本
DISKGROUP
select  GROUP_NUMBER,NAME,STATE,TYPE,TOTAL_MB,FREE_MB, UNBALANCED  from v$asm_diskgroup;

ASMDISK
select  STATE,REDUNDANCY,TOTAL_MB,FREE_MB,NAME,FAILGROUP from v$asm_disk;



磁盘组的挂载
单个磁盘
ALTER DISKGROUP DG1 MOUNT;
ALTER DISKGROUP DG1 DISMOUNT;
所有磁盘组
ALTER DISKGROUP ALL MOUNT;
ALTER DISKGROUP ALL DISMOUNT;



SQL> ALTER DISKGROUP ALL MOUNT;
ALTER DISKGROUP ALL MOUNT
*
ERROR at line 1:
ORA-15110: no diskgroups mounted

报错了,磁盘组没声明啊。

SQL> SHOW PARAMETER ASM        

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_asm_allow_only_raw_disks            boolean     FALSE
asm_diskgroups                       string
asm_diskstring                       string      ORCL:VOL1, ORCL:VOL2
asm_power_limit                      integer     1


祸起红字参数啊!!


SQL>  ALTER SYSTEM SET asm_diskgroups = dg1,dg2 scope=both ;

System altered.

SQL> alter diskgroup all mount ;

Diskgroup altered.

SQL> alter diskgroup all dismount ;

Diskgroup altered.

下面完成一次添加磁盘的过程


[root@sunblaze ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 26108.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1340-26108, default 1340):
Using default value 1340
Last cylinder or +size or +sizeM or +sizeK (1340-26108, default 26108): +5G

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

修改权限
[root@sunblaze ~]# chown oracleinstall /dev/sdb*

[root@sunblaze ~]# ls /dev/sd* -l
brw-rw----  1 root   disk     8,  0 Jun 13 01:10 /dev/sda
brw-rw----  1 root   disk     8,  1 Jun 13 01:10 /dev/sda1
brw-rw----  1 root   disk     8,  2 Jun 13 01:10 /dev/sda2
brw-rw----  1 root   disk     8,  3 Jun 13 01:10 /dev/sda3
brw-rw----  1 oracle oinstall 8, 16 Jun 13 01:10 /dev/sdb
brw-rw----  1 oracle oinstall 8, 17 Jun 13 21:31 /dev/sdb1
brw-rw----  1 oracle oinstall 8, 18 Jun 13 21:31 /dev/sdb2
brw-rw----  1 oracle oinstall 8, 19 Jun 13 21:31 /dev/sdb3

创建ASM磁盘
[root@sunblaze ~]# /etc/init.d/oracleasm createdisk VOL3 /dev/sdb3
Marking disk "VOL3" as an ASM disk:                        [  OK  ]
[root@sunblaze ~]# /etc/init.d/oracleasm listdisks ;
VOL1
VOL2
VOL3

登录ASM实例

[root@sunblaze ~]# su - oracle
[oracle@sunblaze ~]$ export ORACLE_SID=+ASM
[oracle@sunblaze ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jun 13 21:33:03 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> show parameter disk

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_asm_allow_only_raw_disks            boolean     FALSE
asm_diskgroups                       string      DG1, DG2
asm_diskstring                       string      ORCL:VOL1, ORCL:VOL2
disk_asynch_io                       boolean     TRUE

修改参数,注册新加的磁盘
SQL> alter system set asm_diskstring='ORCL:VOL1','ORCL:VOL2','ORCL:VOL3' scope=both ;

System altered.

至此添加磁盘完成!



像磁盘组中增加磁盘

SQL> alter diskgroup DG1 add disk 'ORCL:VOL3' name VOL3 ;

Diskgroup altered.

在磁盘组中删除磁盘


QL> select  STATE,REDUNDANCY,TOTAL_MB,FREE_MB,NAME,FAILGROUP  from v$asm_disk;


STATE    REDUNDA   TOTAL_MB    FREE_MB NAME
-------- ------- ---------- ---------- ------------------------------
FAILGROUP
------------------------------
NORMAL   UNKNOWN       4777       4751 VOL1
VOL1

NORMAL   UNKNOWN       5726       5676 VOL2
VOL2

NORMAL   UNKNOWN       4777       4751 VOL3
VOL3


SQL> select group_number,name from v$asm_disk ;

GROUP_NUMBER NAME
------------ ------------------------------
           1 VOL1
           2 VOL2
           1 VOL3                --添加完成

SQL> alter diskgroup dg1 drop disk VOL3 ;

Diskgroup altered.


再次添加,这次我们修改映射的名字
SQL> alter diskgroup DG1 add disk 'ORCL:VOL3' name VOL4 ;

Diskgroup altered.



SQL> alter diskgroup dg1 drop disk VOL3 ;
alter diskgroup dg1 drop disk VOL3
*
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15054: disk "VOL3" does not exist in diskgroup "DG1"

--验证完成,必须是name 的名字
SQL> alter diskgroup dg1 drop disk VOL4 ;

Diskgroup altered

创建磁盘组

SQL> CREATE DISKGROUP DB_RECOVDER_AREA  external redundancy  disk 'ORCL:VOL3';

Diskgroup created.


SQL> SET LINESIZE 200
SQL> select  GROUP_NUMBER,NAME,STATE,TYPE,TOTAL_MB,FREE_MB, UNBALANCED  from v$asm_diskgroup;

GROUP_NUMBER NAME                           STATE       TYPE     TOTAL_MB    FREE_MB U
------------ ------------------------------ ----------- ------ ---------- ---------- -
           1 DG1                            MOUNTED     EXTERN       4777       4727 N
           2 DG2                            MOUNTED     EXTERN       5726       5676 N
           3 DB_RECOVDER_AREA               MOUNTED     EXTERN       4777       4727 N


删除磁盘组

SQL>  drop diskgroup DB_RECOVDER_AREA  including contents;

Diskgroup dropped.


SQL> select  GROUP_NUMBER,NAME,STATE,TYPE,TOTAL_MB,FREE_MB, UNBALANCED  from v$asm_diskgroup;

GROUP_NUMBER NAME                           STATE       TYPE     TOTAL_MB    FREE_MB U
------------ ------------------------------ ----------- ------ ---------- ---------- -
           1 DG1                            MOUNTED     EXTERN       4777       4727 N
           2 DG2                            MOUNTED     EXTERN       5726       5676 N



利用RMAN将数据库从文件系统迁移到ASM中
####################################################################################
先看下数据库状态
[oracle@sunblaze ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 15 10:03:54 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 open_mode from v$database ;

OPEN_MODE
----------
READ WRITE

read write 我这个肯定是数据库实例了 不是ASM实例,你懂的。

查看数据文件位置,本次使用DBCA默认创建的数据库。

SQL> select file_name from dba_data_files ;

FILE_NAME
--------------------------------------------------------------------------------
/u01/oracle/oradata/orcl/users01.dbf
/u01/oracle/oradata/orcl/sysaux01.dbf
/u01/oracle/oradata/orcl/undotbs01.dbf
/u01/oracle/oradata/orcl/system01.dbf
/u01/oracle/oradata/orcl/example01.dbf


登录Oracle数据库

[oracle@sunblaze ~]$ export ORACLE_SID=+ASM
[oracle@sunblaze ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 15 10:23:57 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> set linesize 200

QL> select * from v$asm_diskgroup ;

GROUP_NUMBER NAME                           SECTOR_SIZE BLOCK_SIZE ALLOCATION_UNIT_SIZE STATE       TYPE     TOTAL_MB    FREE_MB REQUIRED_MIRROR_FREE_MB USABLE_FILE_MB OFFLINE_DISKS U
------------ ------------------------------ ----------- ---------- -------------------- ----------- ------ ---------- ---------- ----------------------- -------------- ------------- -
COMPATIBILITY                                                DATABASE_COMPATIBILITY
------------------------------------------------------------ ------------------------------------------------------------
           1 DG1                                    512       4096              1048576 MOUNTED     EXTERN       4777       4727                       0           4727        0 N
10.1.0.0.0                                                   10.1.0.0.0

           2 DG2                                    512       4096              1048576 MOUNTED     EXTERN       5726       5676                       0           5676        0 N
10.1.0.0.0                                                   10.1.0.0.0

           3 DB_RECOVDER_AREA                       512       4096              1048576 MOUNTED     EXTERN       4777       4727                       0           4727        0 N
10.1.0.0.0            

注:使用RMAN 数据库要处于归档模式,如不是,需要切换到修改模式
############################################################################################
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  289406976 bytes
Fixed Size                  1219016 bytes
Variable Size              88081976 bytes
Database Buffers          197132288 bytes
Redo Buffers                2973696 bytes
Database mounted.

SQL> alter database open ;

Database altered.
############################################################################################

备份数据库

############################################################################################
oracle@sunblaze ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jun 15 11:34:31 2012

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

connected to target database: ORCL (DBID=1227760728)

RMAN> backup as copy database format '+DG2';


Starting backup at 15-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=143 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=/u01/oracle/oradata/orcl/system01.dbf
output filename=+DG2/orcl/datafile/system.256.786022521 tag=TAG20120615T113517 recid=3 stamp=786022568
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:56
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=/u01/oracle/oradata/orcl/sysaux01.dbf
output filename=+DG2/orcl/datafile/sysaux.257.786022573 tag=TAG20120615T113517 recid=4 stamp=786022609
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=/u01/oracle/oradata/orcl/example01.dbf
output filename=+DG2/orcl/datafile/example.258.786022619 tag=TAG20120615T113517 recid=5 stamp=786022632
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=/u01/oracle/oradata/orcl/undotbs01.dbf
output filename=+DG2/orcl/datafile/undotbs1.259.786022635 tag=TAG20120615T113517 recid=6 stamp=786022640
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=/u01/oracle/oradata/orcl/users01.dbf
output filename=+DG2/orcl/datafile/users.260.786022643 tag=TAG20120615T113517 recid=7 stamp=786022643
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=+DG2/orcl/controlfile/backup.261.786022645 tag=TAG20120615T113517 recid=8 stamp=786022647
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 15-JUN-12
channel ORA_DISK_1: finished piece 1 at 15-JUN-12
piece handle=+DG2/orcl/backupset/2012_06_15/nnsnf0_tag20120615t113517_0.262.786022651 tag=TAG20120615T113517 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 15-JUN-12

RMAN>
RMAN> exit


Recovery Manager complete.

############################################################################################



设置OMF相关参数

############################################################################################

SQL> alter system set db_recovery_file_dest_size=4G scope=both ;

System altered.

SQL> alter system set db_recovery_file_dest='+DB_RECOVDER_AREA' scope=both ;

System altered.

SQL> alter system set db_create_file_dest='+DG1' scope=both ;

System altered.

SQL> alter system set db_create_online_log_dest_1='+DG1' scope=both ;

System altered.

SQL> alter system set db_create_online_log_dest_1='+DG2' scope=both ;


System altered.

############################################################################################

日志文件的转移

SQL> select group#,member from v$logfile ;

    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
         3
/u01/oracle/oradata/orcl/redo03.log

         2
/u01/oracle/oradata/orcl/redo02.log

         1
/u01/oracle/oradata/orcl/redo01.log


SQL> alter database add logfile member '+DG1','+DG2' to group 1 ;

Database altered.

SQL> alter database add logfile member '+DG1','+DG2' to group 2 ;

Database altered.

SQL> alter database add logfile member '+DG1','+DG2' to group 3 ;

Database altered.

SQL> set linesize 200
SQL> select * from v$log ;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1          2   52428800          3 YES INACTIVE                475324 11-OCT-09
         2          1          3   52428800          3 YES INACTIVE                500428 14-JUL-11
         3          1          4   52428800          3 NO  CURRENT                 539963 13-JUN-12

SQL> alter database drop logfile member '/u01/oracle/oradata/orcl/redo02.log';
alter database drop logfile member '/u01/oracle/oradata/orcl/redo02.log'
*
ERROR at line 1:
ORA-00362: member is required to form a valid logfile in group 2
ORA-01517: log member: '/u01/oracle/oradata/orcl/redo02.log'



SQL> select group#,member from v$logfile ;

    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         3
/u01/oracle/oradata/orcl/redo03.log

         2
/u01/oracle/oradata/orcl/redo02.log

         1
/u01/oracle/oradata/orcl/redo01.log


    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         1
+DG1/orcl/onlinelog/group_1.257.786023173

         1
+DG2/orcl/onlinelog/group_1.263.786023175

         2
+DG1/orcl/onlinelog/group_2.258.786023179


    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         2
+DG2/orcl/onlinelog/group_2.264.786023181

         3
+DG1/orcl/onlinelog/group_3.259.786023197

         3
+DG2/orcl/onlinelog/group_3.265.786023199


9 rows selected.



SQL> select * from v$log ;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1          2   52428800          3 YES INACTIVE                475324 11-OCT-09
         2          1          3   52428800          3 YES INACTIVE                500428 14-JUL-11
         3          1          4   52428800          3 NO  CURRENT                 539963 13-JUN-12


切换日志


SQL> alter system switch logfile ;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> select * from v$log ;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1          5   52428800          3 YES INACTIVE                554817 15-JUN-12
         2          1          6   52428800          3 YES INACTIVE                554825 15-JUN-12
         3          1          7   52428800          3 NO  CURRENT                 554828 15-JUN-12

SQL> alter database drop logfile member '/u01/oracle/oradata/orcl/redo01.log';

Database altered.

SQL> alter database drop logfile member '/u01/oracle/oradata/orcl/redo02.log';

Database altered.

SQL> alter system switch logfile ;

System altered.

SQL> alter database drop logfile member '/u01/oracle/oradata/orcl/redo03.log';

Database altered.



SQL> select member from v$logfile ;

MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+DG1/orcl/onlinelog/group_1.257.786023173
+DG2/orcl/onlinelog/group_1.263.786023175
+DG1/orcl/onlinelog/group_2.258.786023179
+DG2/orcl/onlinelog/group_2.264.786023181
+DG1/orcl/onlinelog/group_3.259.786023197
+DG2/orcl/onlinelog/group_3.265.786023199

6 rows selected.


数据文件与控制文件的迁移





SQL> alter tablespace temp drop tempfile '/u01/oracle/oradata/orcl/temp01.dbf' ;

Tablespace altered.

SQL> select name from v$tempfile ;

NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+DG1/orcl/tempfile/temp.260.786023969

SQL> show parameter control ;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
control_files                        string      /u01/oracle/oradata/orcl/contr
                                                 ol01.ctl, /u01/oracle/oradata/
                                                 orcl/control02.ctl, /u01/oracl
                                                 e/oradata/orcl/control03.ctl
SQL> alter system set control_files='+DG1/orcl/controlfile/control01.ctrl','+DG2/orcl/controlfile/control02.ctrl' ;
alter system set control_files='+DG1/orcl/controlfile/control01.ctrl','+DG2/orcl/controlfile/control02.ctrl'
                 *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified


SQL> alter system set control_files='+DG1/orcl/controlfile/control01.ctrl','+DG2/orcl/controlfile/control02.ctrl' ;
alter system set control_files='+DG1/orcl/controlfile/control01.ctrl','+DG2/orcl/controlfile/control02.ctrl'
                 *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified


SQL> alter system set control_files='+DG1/orcl/controlfile/control01.ctrl','+DG2/orcl/controlfile/control02.ctrl'  scope=spfile ;

System altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options



进入RMAN控制台

RMAN> startup nomount

connected to target database (not started)
Oracle instance started

Total System Global Area     289406976 bytes

Fixed Size                     1219016 bytes
Variable Size                 92276280 bytes
Database Buffers             192937984 bytes
Redo Buffers                   2973696 bytes


RMAN> restore controlfile from   '/u01/oracle/oradata/orcl/control01.ctl';

Starting restore at 15-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: copied control file copy
output filename=+DG1/orcl/controlfile/control01.ctrl
output filename=+DG2/orcl/controlfile/control02.ctrl
Finished restore at 15-JUN-12

RMAN> alter database mount ;

database mounted
released channel: ORA_DISK_1


转换数据文件


RMAN> switch database to copy ;

datafile 1 switched to datafile copy "+DG2/orcl/datafile/system.256.786022521"
datafile 2 switched to datafile copy "+DG2/orcl/datafile/undotbs1.259.786022635"
datafile 3 switched to datafile copy "+DG2/orcl/datafile/sysaux.257.786022573"
datafile 4 switched to datafile copy "+DG2/orcl/datafile/users.260.786022643"
datafile 5 switched to datafile copy "+DG2/orcl/datafile/example.258.786022619"

RMAN> recover database ;

Starting recover at 15-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

starting media recovery

archive log thread 1 sequence 4 is already on disk as file +DB_RECOVDER_AREA/orcl/archivelog/2012_06_15/thread_1_seq_4.256.786023529
archive log thread 1 sequence 5 is already on disk as file +DB_RECOVDER_AREA/orcl/archivelog/2012_06_15/thread_1_seq_5.257.786023533
archive log thread 1 sequence 6 is already on disk as file +DB_RECOVDER_AREA/orcl/archivelog/2012_06_15/thread_1_seq_6.258.786023537
archive log thread 1 sequence 7 is already on disk as file +DB_RECOVDER_AREA/orcl/archivelog/2012_06_15/thread_1_seq_7.259.786023567
archive log filename=+DB_RECOVDER_AREA/orcl/archivelog/2012_06_15/thread_1_seq_4.256.786023529 thread=1 sequence=4
archive log filename=+DB_RECOVDER_AREA/orcl/archivelog/2012_06_15/thread_1_seq_5.257.786023533 thread=1 sequence=5
media recovery complete, elapsed time: 00:00:05
Finished recover at 15-JUN-12

RMAN> alter database open ;

database opened


########################################################################################

进行验证


[oracle@sunblaze ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 15 12:17: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> show parameter controlfile ;
SQL> show parameter control

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
control_files                        string      +DG1/orcl/controlfile/control0
                                                 1.ctrl, +DG2/orcl/controlfile/
                                                 control02.ctrl



SQL> select * from dba_data_files ;

FILE_NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   FILE_ID TABLESPACE_NAME                     BYTES     BLOCKS STATUS    RELATIVE_FNO AUT   MAXBYTES  MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS ONLINE_
---------- ------------------------------ ---------- ---------- --------- ------------ --- ---------- ---------- ------------ ---------- ----------- -------
+DG2/orcl/datafile/users.260.786022643
         4 USERS                             5242880        640 AVAILABLE            4 YES 3.4360E+10    4194302          160    5177344         632 ONLINE

+DG2/orcl/datafile/sysaux.257.786022573
         3 SYSAUX                          251658240      30720 AVAILABLE            3 YES 3.4360E+10    4194302         1280  251592704       30712 ONLINE

+DG2/orcl/datafile/undotbs1.259.786022635
         2 UNDOTBS1                         31457280       3840 AVAILABLE            2 YES 3.4360E+10    4194302          640   31391744        3832 ONLINE


FILE_NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   FILE_ID TABLESPACE_NAME                     BYTES     BLOCKS STATUS    RELATIVE_FNO AUT   MAXBYTES  MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS ONLINE_
---------- ------------------------------ ---------- ---------- --------- ------------ --- ---------- ---------- ------------ ---------- ----------- -------
+DG2/orcl/datafile/system.256.786022521
         1 SYSTEM                          503316480      61440 AVAILABLE            1 YES 3.4360E+10    4194302         1280  503250944       61432 SYSTEM

+DG2/orcl/datafile/example.258.786022619
         5 EXAMPLE                         104857600      12800 AVAILABLE            5 YES 3.4360E+10    4194302           80  104792064       12792 ONLINE


SQL> select * from v$logfile ;

    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IS_
---
         1         ONLINE
+DG1/orcl/onlinelog/group_1.257.786023173
NO

         1         ONLINE
+DG2/orcl/onlinelog/group_1.263.786023175
NO

    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IS_
---

         2         ONLINE
+DG1/orcl/onlinelog/group_2.258.786023179
NO

         2         ONLINE
+DG2/orcl/onlinelog/group_2.264.786023181

    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IS_
---
NO

         3         ONLINE
+DG1/orcl/onlinelog/group_3.259.786023197
NO

         3         ONLINE

    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IS_
---
+DG2/orcl/onlinelog/group_3.265.786023199
NO


6 rows selected.


最后可以清理之前文件系统上的文件了

[oracle@sunblaze ~]$ ls /u01/oracle/
admin/               flash_recovery_area/ oradata/             oraInventory/        product/            
[oracle@sunblaze ~]$ ls /u01/oracle/oradata/orcl/
control01.ctl  control02.ctl  control03.ctl  example01.dbf  redo01.log  redo02.log  redo03.log  sysaux01.dbf  system01.dbf  undotbs01.dbf  users01.dbf
[oracle@sunblaze ~]$ ls /u01/oracle/oradata/orcl/ -l
total 1050944
-rw-r-----  1 oracle oinstall   7061504 Jun 15 12:13 control01.ctl
-rw-r-----  1 oracle oinstall   7061504 Jun 15 12:13 control02.ctl
-rw-r-----  1 oracle oinstall   7061504 Jun 15 12:13 control03.ctl
-rw-r-----  1 oracle oinstall 104865792 Jun 15 12:12 example01.dbf
-rw-r-----  1 oracle oinstall  52429312 Jun 15 11:52 redo01.log
-rw-r-----  1 oracle oinstall  52429312 Jun 15 11:52 redo02.log
-rw-r-----  1 oracle oinstall  52429312 Jun 15 11:52 redo03.log


至此 ASM文章至此结束,当然不排除后续深入学习,继续的可能。

此文章参考了《大话RAC》以及网上的一些文章,在此表示感谢!



标签: 暂无标签
oraask2

写了 49 篇文章,拥有财富 561,被 72 人关注

转播转播 分享分享 分享淘帖
回复

使用道具

P6 | 发表于 2012-6-26 10:26:09
支持,甲骨论-晨曦,继续努力啊
回复

使用道具

P4 | 发表于 2012-6-30 09:26:41
这文章收藏了
回复

使用道具

P5 | 发表于 2012-7-3 13:22:23
有参加相老师RAC班的么? 到时候我把虚拟机环境带过去,大家可以按照文章自己做一遍。
回复

使用道具

P3 | 发表于 2012-9-6 16:49:50
谢谢啊,学习了
回复

使用道具

您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

意见
反馈