單節點Windows上的ASM(1)

zhyuh發表於2007-01-29

ASM (Automatic Storage Management) 是Oracle 10g的一個重要新特性,在實現資料庫I/O自動負載平衡,資料檔案映象等方面起著重要的作用。即使是單節點的資料庫,Oracle也推薦使用ASM。但一般文件上提到ASM時,都需要有磁碟組或者多塊磁碟才能實現,這使得很多人無法建立學習和實踐的環境。下面的實驗將帶領你在windows xp的作業系統中建立ASM環境,並將已有的資料庫轉移到ASM中,同時該實驗
1. 不需要磁碟組或者多塊磁碟
2. 不需要在Windows xp中安裝虛擬機器,Linux等複雜的步驟

[@more@]

=====================
一、建立ASM Instance
=====================

1. 建立模擬磁碟
建立ASM Instance,首先要在一個磁碟上模擬出多塊磁碟。Oracle的asmtool可以實現這個功能。Asmtool是Oracle 10g for Windows的一個自帶工具,位於ORACLE_HOME¥bin目錄下。

C:¥>md c:¥asmdisks

C:¥>cd asmdisks

C:¥asmdisks>asmtool -create c:¥asmdisks¥disk1 1000;

C:¥asmdisks>asmtool -create c:¥asmdisks¥disk2 1000;

C:¥asmdisks>asmtool -create c:¥asmdisks¥disk3 1000;

C:¥asmdisks>asmtool -create c:¥asmdisks¥disk4 1000;

C:¥asmdisks>asmtool -create c:¥asmdisks¥disk5 1000;

C:¥asmdisks>dir
 Volume in drive C is OS
 Volume Serial Number is FCC6-4EA2

 Directory of C:¥asmdisks

01/03/2007  09:28 AM   

          .
01/03/2007  09:28 AM              ..
01/03/2007  09:12 AM     1,048,576,000 disk1
01/03/2007  10:01 AM     1,048,576,000 disk2
01/03/2007  10:01 AM     1,048,576,000 disk3
01/03/2007  10:01 AM     1,048,576,000 disk4
01/03/2007  10:01 AM     1,048,576,000 disk5
               5 File(s)  5,242,880,000 bytes
               2 Dir(s)  48,027,619,328 bytes free
              
這樣我們就在C:¥asmdisks目錄中生成了5個檔案,每個大小為1G。ASM instance會把它們當成5塊1G的硬碟。

2. 配置CSS(Cluster Synchronization Services)
CSS主要用來同步ASM instance和它的client,也即database instance。這一步就算不是在cluster環境中也是必須的,可以由Oracle自帶的localconfig命令來完成。Localconfig命令也位於ORACLE_HOME¥bin目錄下。

C:¥oracle¥product¥10.2.0¥db_1¥BIN>localconfig add
Step 1:  creating new OCR repository
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'corp¥e468447', privgrp ''..
Operation successful.
Step 2:  creating new CSS service
successfully created local CSS service
successfully added CSS to home

檢查CSS daemon狀態:

C:¥asmdisks>crsctl check cssd
CSS appears healthy

“CSS appears healthy”表明該程式正在執行。

3. 建立ASM Instance的initial檔案
ASM Instance有自己的初始引數檔案,可以為spfile或者文字檔案。透過在檔名中嵌入SID,來區分ASM Instance和Database Instance。單節點的環境中,ASM SID預設為+ASM, RAC中各節點上的SID預設為+ASMnode#。

開啟記事本編輯初始引數檔案。
C:¥oracle¥product¥10.2.0¥db_1¥database>notepad init+ASM.ora
INSTANCE_TYPE=ASM        #必須設定的引數,而且值只能為ASM
DB_UNIQUE_NAME=+ASM
LARGE_POOL_SIZE=8M       #給ASM的internal packages使用,至少8M
ASM_DISKSTRING='C:¥asmdisks¥*' #告訴ASM Instance物理磁碟位置
_ASM_ALLOW_ONLY_RAW_DISKS=FALSE #Oracle隱藏引數,允許ASM使用非裸裝置。


C:¥oracle¥product¥10.2.0¥db_1¥database>dir
 Volume in drive C is OS
 Volume Serial Number is FCC6-4EA2

 Directory of C:¥oracle¥product¥10.2.0¥db_1¥database

12/28/2006  09:48 AM   

          .
12/28/2006  09:48 AM              ..
11/17/2006  09:14 AM              archive
11/17/2006  03:33 PM             2,048 hc_orcl.dat
12/28/2006  09:49 AM               123 init+ASM.ora
11/17/2006  09:38 AM                59 initorcl.ora
06/25/2005  03:18 AM            31,744 oradba.exe
12/28/2006  08:56 AM             4,092 oradim.log
11/21/2006  10:03 AM             1,536 PWDorcl.ora
              37 File(s)         42,888 bytes
               3 Dir(s)  47,781,150,720 bytes free

4. 用oradim建立Oracle ASM例項。
C:¥oracle¥product¥10.2.0¥db_1¥database>oradim -NEW -ASMSID +ASM -STARTMODE auto
例項已建立。

其中
-NEW: indicates that you are creating a new instance. This is a mandatory parameter
-ASMSID SID: is the name of the Automatic Storage Management (ASM) instance to create
STARTMODE: indicates whether to start the instance when the Oracle Database service is started. Default is manual


5. 連線到ASM Instance。
C:¥oracle¥product¥10.2.0¥db_1¥database>set ORACLE_SID=+ASM

C:¥oracle¥product¥10.2.0¥db_1¥database>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 12月 28 10:04:21 2006

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


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

SQL> show user
USER 為 "SYS"
SQL> select status from v$instance;

STATUS
------------------------
STARTED

6. 建立磁碟組
SQL> set pages 3000
SQL> set lines 132
SQL> column path format a50
SQL> select path,mount_status from v$asm_disk;

PATH                                               MOUNT_STATUS
-------------------------------------------------- --------------
C:¥ASMDISKS¥DISK1                                  CLOSED
C:¥ASMDISKS¥DISK2                                  CLOSED
C:¥ASMDISKS¥DISK5                                  CLOSED
C:¥ASMDISKS¥DISK4                                  CLOSED
C:¥ASMDISKS¥DISK3                                  CLOSED

注意MOUNT_STATUS為"CLOSED",因為磁碟組還沒建立。


SQL> create diskgroup dgroup1 normal redundancy disk
  2  'c:¥asmdisks¥disk1',
  3  'c:¥asmdisks¥disk2',
  4  'c:¥asmdisks¥disk3',
  5  'c:¥asmdisks¥disk4',
  6  'c:¥asmdisks¥disk5';

磁碟組已建立。

再檢查磁碟狀態,MOUNT_STATUS變成"CACHED",表示磁碟已經成為磁碟組的一部分,並且正在被ASM Instance訪問。
SQL> select path,mount_status from v$asm_disk;

PATH                                               MOUNT_STATUS
-------------------------------------------------- --------------
C:¥ASMDISKS¥DISK1                                  CACHED
C:¥ASMDISKS¥DISK2                                  CACHED
C:¥ASMDISKS¥DISK3                                  CACHED
C:¥ASMDISKS¥DISK4                                  CACHED
C:¥ASMDISKS¥DISK5                                  CACHED


關閉ASM Instance,
SQL> shutdown immediate;
ASM 磁碟組已卸裝
ASM 例項已關閉

在init+ASM.ora中加入引數 ASM_DISKGROUPS='DGROUP1',並建立spfile。
SQL> create spfile from pfile='C:¥oracle¥product¥10.2.0¥db_1¥database¥init+asm.ora';

檔案已建立。

啟動ASM Instance。
SQL> startup
ASM 例項已啟動

Total System Global Area   79691776 bytes
Fixed Size                  1247396 bytes
Variable Size              53278556 bytes
ASM Cache                  25165824 bytes
ASM 磁碟組已裝載

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

相關文章