怎么样使用普通文件玩转ASM?

怎么样使用普通文件玩转ASM?

本文主要参考:How to use Files in place of Real Disk Devices for ASM - (Windows)

1.实验环境
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 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

2.配置css(Cluster Synchronization Services)
E:>localconfig add
Step 1: creating new OCR repository
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'gdchaiyuan.ning', privgrp ''..
Operation successful.
Step 2: creating new CSS service
successfully created local CSS service
successfully added CSS to home

配置成功后,windows服务中会出现一个名为OracleCSService的服务。

3.创建用于ASM的文件
这里使用一段perl脚本来创建预先分配空间的普通os文件,一个四个文件,每个200M
-------------------------------------------------------------------------------
my $s='0' x 2**20;

open(DF1,">d:/asmdisks/_file_disk1") || die "Cannot create file - $!n";
open(DF2,">d:/asmdisks/_file_disk2") || die "Cannot create file - $!n";
open(DF3,">d:/asmdisks/_file_disk3") || die "Cannot create file - $!n";
open(DF4,">d:/asmdisks/_file_disk4") || die "Cannot create file - $!n";

for (my $i=1; $i<200; $i++) {
print DF1 $s;
print DF2 $s;
print DF3 $s;
print DF4 $s;
}

exit
-------------------------------------------------------------------------------
windows平台的perl解释器,可以从以下地址下载
http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl

4.创建ASM实例

a.创建相应的dump目录
mkdir %ORACLE_BASE%admin+ASMbdump
mkdir %ORACLE_BASE%admin+ASMcdump
mkdir %ORACLE_BASE%admin+ASMhdump
mkdir %ORACLE_BASE%admin+ASMpfile
mkdir %ORACLE_BASE%admin+ASMudump

b.创建参数文件
_asm_allow_only_raw_disks=false
asm_diskstring='d:asmdisks_file*'

background_dump_dest=E:oracleora10admin+ASMbdump
core_dump_dest=E:oracleora10admin+ASMcdump
user_dump_dest=E:oracleora10admin+ASMudump
instance_type=asm
compatible=10.2.0.1.0
large_pool_size=12M
remote_login_passwordfile=exclusive

c.使用oradim创建instance
E:>oradim -new -asmsid +ASM -syspwd pass
实例已创建。

5.启动ASM实例

E:>set ORACLE_SID=+ASM

E:>sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 11月 30 16:28:57 2006

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

SQL> conn / as sysdba
已连接到空闲例程。
SQL> startup nomount;
ASM 实例已启动

Total System Global Area 83886080 bytes
Fixed Size 1247420 bytes
Variable Size 57472836 bytes
ASM Cache 25165824 bytes

SQL> create spfile from pfile;

文件已创建。

SQL> shutdown;
ORA-15100: invalid or missing diskgroup name

ASM 实例已关闭
SQL> startup
ASM 实例已启动

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

这里的ORA-15100和ORA-15110错误可以忽略。

另外,如果第二步的css服务没有创建,或者服务没有启动,则启动asm实例时会报错:ORA-29701: unable to connect to Cluster Manager

6.创建ASM磁盘组
首先查看是否已经将前面建的普通文件当作磁盘认出来了

SQL> col group_name heading gNo for 99
SQL> col group_number heading gNo for 99
SQL> col disk_number heading dNo for 99
SQL> col mount_status heading mstatus for a6
SQL> col header_status heading hstatus for a9
SQL> col path for a40
SQL> SELECT group_number, disk_number, mount_status, header_status, state, path
2 from v$asm_disk;

gNo dNo mstatus hstatus STATE PATH
--- --- ------- --------- ------ ---------------------------------------------
0 0 CLOSED CANDIDATE NORMAL D:ASMDISKS_FILE_DISK1
0 3 CLOSED CANDIDATE NORMAL D:ASMDISKS_FILE_DISK4
0 2 CLOSED CANDIDATE NORMAL D:ASMDISKS_FILE_DISK3
0 1 CLOSED CANDIDATE NORMAL D:ASMDISKS_FILE_DISK2

注意到group_number都是0,说明这4个磁盘还不属于任何一个磁盘组

SQL> create diskgroup test_data1 normal redundancy
2 failgroup controller1 disk 'D:ASMDISKS_FILE_DISK1','D:ASMDISKS_FILE_DISK2'
3 failgroup controller2 disk 'D:ASMDISKS_FILE_DISK3','D:ASMDISKS_FILE_DISK4';

磁盘组已创建。

查看磁盘组状态
SQL> select group_number, name, total_mb, free_mb, state, type
2 from v$asm_diskgroup;

gNo NAME TOTAL_MB FREE_MB STATE TYPE
--- ---------- ---------- ---------- -------- ------------
1 TEST_DATA1 597 493 MOUNTED NORMAL

由于冗余的关系,整个diskgroup只有493M可用空间

再次查看磁盘状态
SQL> select group_number, disk_number, mount_status, header_status, state, path,
failgroup
2 from v$asm_disk;

gNo dNo status hstatus STATE PATH FAILGROUP
--- --- ------ --------- -------- ------------------------------ ------------
1 0 CACHED MEMBER NORMAL D:ASMDISKS_FILE_DISK1 CONTROLLER1
1 1 CACHED MEMBER NORMAL D:ASMDISKS_FILE_DISK2 CONTROLLER1
1 2 CACHED MEMBER NORMAL D:ASMDISKS_FILE_DISK3 CONTROLLER2
1 3 CACHED MEMBER NORMAL D:ASMDISKS_FILE_DISK4 CONTROLLER2

至此,ASM创建成功,以后可以再添加,删除磁盘和磁盘组。通过DBCA创建数据库时,文件就可以选择这

里创建好的磁盘组来做为存储选项了。另外,也可以使用DBCA来管理ASM的磁盘组。