ASM 詳解

ASM
ASM是 Oracle數據庫 10g中一個非常出色的新特性,它以平臺無關的方式提供了文件系統、邏輯卷管理器以及軟件 RAID等服務。ASM可以條帶化和鏡像磁盤,從而實現了在數據庫被加載的情況下添加或移除磁盤以及自動平衡 I/O以刪除“熱點”。它還支持直接和異步的 I/O並使用 Oracle9i中引入的 Oracle數據管理器 API(簡化的 I/O系統調用接口)。
 
,ASM不是一個通用的文件系統
ASM不是一個通用的文件系統,並只能用於 Oracle數據文件、重做日誌以及控制文件。ASM中的文件既可以由數據庫自動創建和命名(通過使用 Oracle管理文件特性),也可以由 DBA手動創建和命名。由於操作系統無法訪問 ASM中存儲的文件,因此對使用 ASM文件的數據庫執行備份和恢復操作的唯一途徑就是通過恢復管理器 (RMAN)。
 
,ASM作爲單獨的Oracle實例實施
ASM作爲單獨的 Oracle實例實施,只有它在運行時其他數據庫才能訪問它。在 Linux上,只有運行 OCSSD服務(由 Oracle通用安裝程序默認安裝)才能使用 ASM。ASM需要的內存不多:對大多數系統,只需 64 MB。
 
,ASM提供了3種冗餘方法。
external redundancy    表示Oracle不幫你管理鏡像,功能由外部存儲系統實現,比如通過RAID技術。
normal redundancy      (默認方式)表示Oracle提供2路鏡像來保護數據。
high redundancy          表示Oracle提供3路鏡像來保護數據。
 
,oracle通過failure group來提供高可用性。
ASM的鏡像算法是extent級別,而不是整個磁盤級別。這裏面有個primary copy和second copy的概念;寫入的時候依據primary copy,最終實現寫入隨機有序讀取,來完成平衡數據讀取的目的。
 
,ASM實例只需要初始參數文件,不需要其它物理文件.
[oracle@kk dbs]$ cat  /opt/oracle/product/10.2.0/db_1/dbs/spfile+ASM.ora  <==初始化參數文件的位置
1O7*+ASM.asm_diskgroups='ASMGRP1'#Manual Mount
*.asm_diskgroups='ASMGRP1'
*.background_dump_dest='/opt/oracle//admin/+ASM/bdump'
*.core_dump_dest='/opt/oracle//admin/+ASM/cdump'
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='SHARED'
*.user_dump_dest='/opt/oracle//admin/+ASM/udump'
 
,ASM的實例的名稱是+ASM。INSTANCE_TYPE=ASM
SQL> select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
+ASM
 
8,ASM實例的控制文件
SQL> SHOW parameter control
 
NAME                          TYPE             VALUE
------------------------------           -------------         --------------------------------------------------
control_file_record_keep_time        integer            7
control_files                       string            /opt/oracle/product/10.2.0/db_1/dbs/cntrl+ASM.dbf

,確認自己系統版本
[root@kk 32bit]# uname –rm   <==查看系統信息,下載合適的軟件
2.6.18-92.el5 i686
 
 
,下載對應的軟件
軟件下載地址:http://www.oracle.com/technology/tech/linux/asmlib/index.html
 
,安裝,注意安裝順序
[root@kk 32bit]# rpm -ivh oracleasm-support-2.1.3-1.el5.i386.rpm
warning: oracleasm-support-2.1.3-1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...               ########################################### [100%]
  1:oracleasm-support     ########################################### [100%]
 
[root@kk 32bit]# rpm -ivh oracleasm-2.6.18-92.el5-2.0.5-1.el5.i686.rpm
warning: oracleasm-2.6.18-92.el5-2.0.5-1.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...               ########################################### [100%]
  1:oracleasm-2.6.18-92.el5########################################### [100%]
 
[root@kk 32bit]# rpm -ivh oracleasmlib-2.0.4-1.el5.i386.rpm
warning: oracleasmlib-2.0.4-1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...               ########################################### [100%]
  1:oracleasmlib          ########################################### [100%]
 
 

,使用ASM前線關閉selinux
 [root@kk 32bit]# vi /etc/selinux/config  <==關閉selinux,否則會報錯
SELINUX=enforcing
改爲
SELINUX=disabled
 
[root@kk Server]# setenforce 0
 
,運行配置腳本,準備ASMLib驅動程序
[root@kk 32bit]# /etc/init.d/oracleasm configure   <==使用 ASMLib之前,必須運行配置腳本以準備驅動程序
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 []: dba
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 ]
 
,啓用ASMLib驅動程序
[root@kk 32bit]# /etc/init.d/oracleasm enable <==啓用 ASMLib 驅動程序
Writing Oracle ASM library driver configuration: done
Initializing the Oracle ASMLib driver:                    [ OK ]
Scanning the system for Oracle ASMLib disks:              [ OK ]
 
[root@kk 32bit]# fdisk –l  <==查看系統都掛載了那些磁盤
Disk /dev/sdb: 4294 MB, 4294967296 bytes 
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
  Device Boot     Start        End     Blocks  Id System
/dev/sdb1              1        130    1044193+ 83 Linux
/dev/sdb2            131        250     963900  83 Linux
/dev/sdb3            251        522    2184840  83 Linux
,ASM的運行需要CSS服務,下面來安裝它
首先安裝CSS(Oracle Cluster Synchronization Service)
[root@kk 32bit]# cd /opt/oracle/product/10.2.0/db_1/bin/
[root@kk 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.
  kk
CSS is active on all nodes.
Oracle CSS service is installed and running under init(1M)
 
 
,創建ASM磁盤
注意:VOL* :這裏必須要大寫,否則會出錯
 /dev/sdb*:這裏可以是整塊未分區的硬盤也可以是硬盤的分區。
[root@kk 32bit]# /etc/init.d/oracleasm createdisk VOL1 /dev/sdb1
Marking disk "VOL1" as an ASM disk:                       [ OK ]
[root@kk 32bit]# /etc/init.d/oracleasm createdisk VOL2/dev/sdb2
Marking disk "VOL2" as an ASM disk:                       [ OK ]
[root@kk 32bit]# /etc/init.d/oracleasm createdisk VOL3/dev/sdb3
Marking disk "VOL3" as an ASM disk:                       [ OK ]
 
,查看已標記爲ASMLib的硬盤
[root@kk 32bit]# /etc/init.d/oracleasm listdisks  <==查看已標記爲ASMLib的硬盤
VOL1
VOL2
VOL3
 
 
,創建diskgroup
冗餘
- High鏡像數據兩次。
- Normal鏡像數據一次。
- External不鏡像 ASM中的數據。如果外部 RAID陣列提供冗餘,則通常使用此選項。 
 
SQL> select name,path,group_number from v$asm_disk;  <==查詢asm_disk的名稱和路徑,一會創建時要用
 
NAME                         PATH                              GROUP_NUMBER
---------------------------------- ----------------------------------------------         -------------------------
                               ORCL:VOL4                             0  <==0說明該磁盤不屬於任何組
VOL1                          ORCL:VOL1                             1
VOL2                          ORCL:VOL2                             1
VOL3                          ORCL:VOL3                             1
 
SQL> create diskgroup DISKGRP2 external redundancy disk  'ORCL:VOL4';
Diskgroup created.
 
,啓動/關閉ASM實例
【原則】先關閉其它例程,最後關閉ASM例程
否則會報下面的錯誤
SQL> shutdown immediate;
ORA-15097: cannot SHUTDOWN ASM instance with connected RDBMS instance
 
啓動順序
案例:這裏強調ASM實例啓動只需要spfile.ora不需要其它任何物理數據文件!
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/product/10.2.0/db_1/dbs/init+ASM.ora'
 
[oracle@kk ~]$ export ORACLE_SID=+ASM
[oracle@kk ~]$ sqlplus "/ as sysdba"
 
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 13 07:54:58 2010
 
Copyright (c) 1982, 2005, Oracle. All rights reserved.
 
Connected to an idle instance.
 
SQL> startup
ASM instance started
 
Total System Global Area  83886080 bytes
Fixed Size                 1217836 bytes
Variable Size             57502420 bytes
ASM Cache                 25165824 bytes
ASM diskgroups mounted
 
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
[oracle@kk ~]$ exit
logout
[root@kk ~]# su - oracle
[oracle@kk ~]$ sqlplus "/ as sysdba"
 
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 13 07:55:36 2010
 
Copyright (c) 1982, 2005, Oracle. All rights reserved.
 
Connected to an idle instance.
 
SQL> startup
ORACLE instance started.
 
Total System Global Area 608174080 bytes
Fixed Size                 1220844 bytes
Variable Size            176164628 bytes
Database Buffers         427819008 bytes
Redo Buffers               2969600 bytes
Database mounted.
Database opened.
SQL>
目錄
一,認識ASM 2
1,ASM   2
2,ASM不是一個通用的文件系統   2
3,ASM作爲單獨的 Oracle實例實施      2
4,ASM提供了3種冗餘方法。        2
5,oracle通過failure group來提供高可用性。  2
6,ASM實例只需要初始參數文件,不需要其它物理文件. 2
7,ASM的實例的名稱是+ASM。INSTANCE_TYPE=ASM         2
 
二,安裝ASM 2
1,確認自己系統版本        2
2,下載對應的軟件  3
3,安裝,注意安裝順序    3
 
三,使用3
1,使用ASM前線關閉selinux  3
2,運行配置腳本,準備ASMLib驅動程序         3
3,啓用ASMLib驅動程序         3
4,ASM的運行需要CSS服務,下面來安裝它  4
5,創建ASM磁盤   4
6,查看已標記爲ASMLib的硬盤      4
7,創建diskgroup     4
8,啓動/關閉ASM實例    4
 
四,ASM相關視圖及內部命令     5
1,查看asm diskgroup的名字、狀態、複製類型、總大小、空閒空間      5
2,查看ASM磁盤的名字、路徑、掛載狀態、磁盤號   5
3,數據文件命名含義 dba_data_files     6
4,在ASM實例中查詢文件編號和大小6
查詢文件號及其大小     7
5,查詢相關的物理文件的大小 7
6,ASM的內部命令 asmcmd    7
 
五,高級操作  8
1,創建或更改表空間   8
a,查詢asm_diskgroup信息   8
b.創建表空間erp   8
c,觀察磁盤組空間變化  8
d,dba_data_files中關於文件名稱和大小的信息8
e,resize文件大小 8
2,刪除disk     8
3,添加新硬盤並重新負載均衡 8
 
六,FAQ:  9
1,diskgroup的管理     9
2,條帶化原理和rebalance  9
3,文件名和Template    9
4,ASMCMD命令行    9
5,ASM文件轉化  9
6,Failure Groups in ASM     9
7,Oracle10g新增DBMS_FILE_TRANSFER包 9
 
正文:
相關視圖及內部命令
,查看asm diskgroup的名字、狀態、複製類型、總大小、空閒空間
SQL> select name, state, type, total_mb, free_mb from v$asm_diskgroup;
 
NAME                STATE           TYPE          TOTAL_MB   FREE_MB
--------------------   -----------------------      -----------------     -------------------  ----------
ASMGRP1         MOUNTED           NORMAL          6273        3616
DISKGRP2         MOUNTED           EXTERN          1913        1863
 
 
,查看ASM磁盤的名字、路徑、掛載狀態、磁盤號
SQL> select name, path, mode_status, state, disk_number from v$asm_disk;
 
NAME    PATH          MODE_STATUS    STATE              DISK_NUMBER
---------------------------------------------------------------------------------------------------------------------------------
VOL1    ORCL:VOL1      ONLINE         NORMAL                    0
VOL2    ORCL:VOL2      ONLINE         NORMAL                    1
VOL3    ORCL:VOL3      ONLINE         NORMAL                    2
VOL4    ORCL:VOL4      ONLINE         NORMAL                    0
 
,數據文件命名含義dba_data_files
SQL> select file_name from dba_data_files;
 
FILE_NAME
--------------------------------------------------------------------------------
+ASMGRP1/boy/datafile/users.259.713439439
+ASMGRP1/boy/datafile/sysaux.257.713439427
+ASMGRP1/boy/datafile/undotbs1.258.713439433
+ASMGRP1/boy/datafile/system.256.713439419
+ASMGRP1/boy/datafile/example.269.713440119
+DISKGRP2/boy/datafile/erp.256.713522125
 
格式說明:
+ASMGRP1/boy /datafile/tbs_name.asm_filenumber.incarnation_number
 
   + ASMGRP1: diskgroup名
            boy:  該數據庫名
  datafile: 文件類型,表示是數據文件
 tbs_name:  表空間名
 asm file#: 表示ASM file編號,v$asm_file.file_number
incarnation number: 從時間戳提取,唯一值 。
 
,在ASM實例中查詢文件編號和大小
[oracle@kk ~]$ export ORACLE_SID=+ASM
[oracle@kk ~]$ sqlplus '/as sysdba'
SQL> select file_number,bytes/1024/1024 from v$asm_file;
 
FILE_NUMBER BYTES/1024/1024
----------- ---------------
       256     480.007813
       257     250.007813
       258     25.0078125
       259     70.0078125
       260       6.734375
       261       6.734375
       262     50.0004883
       263     50.0004883
       264     50.0004883
       265     50.0004883
       266     50.0004883
       267     50.0004883
       268     20.0078125
       269     100.007813
       270     .002441406
       256     800.007813
 
SQL> select member from v$logfile;
 
MEMBER
--------------------------------------------------------------------------------
+ASMGRP1/boy/onlinelog/group_3.266.713439655
+ASMGRP1/boy/onlinelog/group_3.267.713439663
+ASMGRP1/boy/onlinelog/group_2.264.713439635
+ASMGRP1/boy/onlinelog/group_2.265.713439643
+ASMGRP1/boy/onlinelog/group_1.262.713439615
+ASMGRP1/boy/onlinelog/group_1.263.713439627
 
16 rows selected.
 
所查詢到的值,與dba_data_files相匹配。
 

+ASM (ASM instance)
SQL> select file_number , sum(bytes)/(1024*1024)  MB from v$asm_file group by file_number;
 
FILE_NUMBER SUM(BYTES)/(1024*1024)
----------- ----------------------
       256            360.007813
       257            35.0078125
 
BOY (database instance)
SQL> select name from v$datafile
 
NAME
----------------------------------------
+DATA/orcl/datafile/sysaux.256.3
+DATA/orcl/datafile/system.258.3
+DATA/orcl/datafile/undotbs1.257.3
+DATA/orcl/datafile/users.265.3
+DATA/orcl/datafile/nitin.263.3
 
,查詢相關的物理文件的大小
select sum(bytes)/(1024*1024*1024) from v$datafile;
 
select sum(bytes)/(1024*1024*1024) from v$logfile a, v$log b where a.group#=b.group#; 
 
select sum(bytes)/(1024*1024*1024) from v$tempfile where status='ONLINE';
 
,ASM的內部命令asmcmd
[oracle@kk ~]$ export ORACLE_SID=+ASM
[oracle@kk ~]$ asmcmd
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "AMRICAN"
   are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "AMRICAN"
   are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
ASMCMD> ls -l
State   Type   Rebal Unbal Name
MOUNTED NORMAL N     N     ASMGRP1/
MOUNTED EXTERN N     N     DISKGRP2/
ASMCMD [+ASMGRP1] > help
       commands:
       --------
       cd
       du
       find
       help
       ls
       lsct
       lsdg
       mkalias
       mkdir
       pwd
       rm
       rmalias
 
 

,創建或更改表空間
查詢asm_diskgroup信息
SQL> select group_number,name, total_mb,free_mb from v$asm_diskgroup
 
GROUP_NUMBER     NAME                                TOTAL_MB   FREE_MB
------------ ------------------------------------------------------------       ----------       ----------
          1        ASMGRP1                                  6273        3616
          2        DISKGRP2                                 1913         1863
 
創建表空間erp
SQL> create tablespace erp datafile '+DISKGRP2' size 800m;
 
Tablespace created.
 
觀察磁盤組空間變化
SQL> select group_number,name, total_mb,free_mb from v$asm_diskgroup;
 
GROUP_NUMBER   NAME                        TOTAL_MB FREE_MB
------------ ------------------------------------------------------------  ----------     ----------
          1      ASMGRP1                        6273      3616
          2     DISKGRP2                        1913      1060
,dba_data_files中關於文件名稱和大小的信息
SQL>  select file_name,tablespace_name,bytes/1024/1024 MB,autoextensible from dba_data_files
FILE_NAME                              TABLESPACE_NAME        MB  AUTOEX
------------------------------------------------------------- ------------------------------------------------------------ ---------- ------
+ASMGRP1/boy/datafile/users.259.713439439    USERS                     5    YES
+ASMGRP1/boy/datafile/sysaux.257.713439427   SYSAUX                   240        YES
+ASMGRP1/boy/datafile/undotbs1.258.713439433 UNDOTBS1                25   YES
+ASMGRP1/boy/datafile/system.256.713439419   SYSTEM                   480 YES
+ASMGRP1/boy/datafile/example.269.713440119  EXAMPLE                 100  YES
+DISKGRP2/boy/datafile/erp.256.713522125      ERP                       800  NO
 
,resize文件大小
SQL> alter database datafile '+ASMGRP1/boy/datafile/users.259.713439439' resize 70M;
 
Database altered.
 
SQL> select file_name,tablespace_name,bytes/1024/1024 MB,autoextensible from dba_data_files;
 
FILE_NAME                                 TABLESPACE_NAME      MB                 AUTOEX
----------------------------------------------------------------- ------------------------------------------------------------ ---------- ------
+ASMGRP1/boy/datafile/users.259.713439439       USERS                  70        YES
 
,刪除disk
SQL> select group_number, name from v$asm_diskgroup;
SQL> select path, name from v$asm_disk where group_number=1;
SQL> alter diskgroup DISKGRP2 drop disk VOL4;
 
Diskgroup altered.
 
,添加新硬盤並重新負載均衡
SQL> alter diskgroup DATA add disk '/dev/rdsk/c3t19d39s4' rebalance power 11 <==power:允許使用系統資源的一個參數
 
SQL> select * from v$asm_operation
 
 

,diskgroup的管理
http://space.itpub.net/?uid-354732-action-viewspace-itemid-627665
,條帶化原理和rebalance
http://space.itpub.net/?uid-354732-action-viewspace-itemid-628992
,文件名和Template
http://space.itpub.net/?uid-354732-action-viewspace-itemid-629497
,ASMCMD命令行
http://space.itpub.net/?uid-354732-action-viewspace-itemid-629586
,ASM文件轉化
http://space.itpub.net/?uid-354732-action-viewspace-itemid-629618
,Failure Groups in ASM
http://blog.chinaunix.net/u/19769/showart_244125.html
,Oracle10g新增DBMS_FILE_TRANSFER包
http://yangtingkun.itpub.net/post/468/484002
8, oracle wiki
http://www.orafaq.com/wiki/ASM_FAQ

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章