Oracle ASM 详解
生活随笔
收集整理的這篇文章主要介紹了
Oracle ASM 详解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
ASM:Automatic Storage Management, 是Oracle 主推的一種面向Oracle的存儲解決方案, ASM 和 RDBMS 非常相似,ASM 也是由實例和文件組成, 也可以通過sqlplus 工具來維護(hù)。?
?
?
ASM 實例的創(chuàng)建和刪除也可以用DBCA 這個命令來操作。在dbca 的第一個界面選擇配置自動存儲管理就可以了。 ASM 實例需要CSS 進(jìn)程, 如果是非RAC 環(huán)境, 在啟動ASM 實例之前會提示用腳本?
$ORACLE_HOME/bin/localconfig add 啟動CSS。?
?
?
?
1. ASM 實例由SGA 和后臺進(jìn)程組成。
?
1.1 SGA 組成:
ASM 實例的SGA包括Buffer Cache, Share Pool, Large Pool等。 需要注意的是Share Pool, 因為Extent Map 要放在這部分的內(nèi)存中,需要更具數(shù)據(jù)量來估計Extent Map 的大小做相應(yīng)的調(diào)整。?
Extent Map 的大小可以根據(jù)所有文件大小的和來估算,使用下面的語句來計算所有文件和:
?
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';
?
這3個sum 的總和對應(yīng)著數(shù)據(jù)庫存放ASM中所有文件大小總和, 對于使用External Redundancy 的磁盤組, 每100G 需要1MB 的Extent Map, 根據(jù)這個比例計算Extent Map 所需要的空間,在加上額外的2MB就可以了。 在實際工作中一般不需要考慮ASM SGA的配置, 使用Oracle 提供的缺省值就可以了。
?
1.2 后臺進(jìn)程
?
ASM 實例比RDBMS 實例多2個進(jìn)程: RBAL 和 ABRn。
RBAL: 這個進(jìn)程也叫Rebalancer進(jìn)程, 負(fù)責(zé)規(guī)劃ASM 磁盤組的Reblance活動。
ABRn:是RBAL進(jìn)程的子進(jìn)程,這個進(jìn)程在數(shù)量上可以有多個, n從1~9, 這組進(jìn)程負(fù)責(zé)真正完成Reblance活動。
?
使用ASM 作為存儲的RDBMS 實例也會多出2個進(jìn)程: RBAL 和 ASMB
RBAL: 這個進(jìn)程的主要功能是打開每個磁盤的所有磁盤和數(shù)據(jù)的Rebalance。
ASMB: 這個進(jìn)程作為ASM 實例和數(shù)據(jù)庫實例之間的信息通道。 這個進(jìn)程負(fù)責(zé)與ASM 實例的通信, 它先利用Diskgroup Name 從CSS 獲得管理該Diskgroup 的ASM 實例的連接串, 然后建立到ASM 的持久連接, 兩個實例之間通過這條連接定期交換信息,同時也是一種心跳機(jī)制。
?
RDBMS 實例要想使用ASM 作為存儲, RDBMS 實例必須在啟動時從ASM 實例獲得Extent Map, 以后發(fā)生磁盤組的維護(hù)操作, ASM 實例還要把Extent Map的更新信息通知給RDBMS 實例, 這2個實例間的信息交換就是他你哦剛過ASMB 進(jìn)程完成的。 這也就為什么: ASM 實例必須要先于數(shù)據(jù)庫實例啟動,和數(shù)據(jù)庫實例同步運行,遲于數(shù)據(jù)庫實例關(guān)閉。
?
?
注意: ASM 實例和數(shù)據(jù)庫實例的關(guān)系可以是1:1, 也可以是1:n。如果是1:n, 最好為ASM 安裝單獨的ASM_HOME。
?
2. ASM 配置
?
ASM 可以使用裸設(shè)備 或者ASMLib 方式, 因為裸設(shè)別的維護(hù)比較復(fù)雜,在此只講解ASMLib 方式。?
?
對應(yīng)不同的操作系統(tǒng), 需要不同的包,下載的時候一定要和操作系統(tǒng)內(nèi)核一致。 我的操作系統(tǒng)是 Red hat 4 update 7. 內(nèi)核版本是2.6.9-78.ELSMP。
?
oracleasmlib-2.0.4-1.el4.i386.rpm
oracleasm-support-2.1.3-1.el4.i386.rpm
oracleasm-2.6.9-78.EL-2.0.5-1.el4.i686.rpm
?
http://www.oracle.com/technology/tech/linux/asmlib/index.html
該頁面有下載地址,注意選擇CPU 類型。 asmlib 和 support,在同一個頁面下載。
?
安裝包:
#rpm -ivh *.rpm
?
安裝完之后進(jìn)行配置:
#/etc/init.d/oracleasm configure
會有相應(yīng)的提示, 回答 oracle , dba, y, y 就可以了?
分別對應(yīng)默認(rèn)用戶, 默認(rèn)組,隨系統(tǒng)自啟動, 啟動時設(shè)置權(quán)限。
?
/etc/init.d/oracleasm createdisk VOL1 /dev/sdc1?
/etc/init.d/oracleasm scandisks?
/etc/init.d/oracleasm listdisks ?
?
關(guān)于oracleasm 的更多用法參考help:
[root@node1 ~]# /etc/init.d/oracleasm --help
Usage: /etc/init.d/oracleasm {start|stop|restart|enable|disable|configure
?? ? ? ? ? ? |createdisk|deletedisk|querydisk|listdisks|scandisks|status}
?
?
3. ASM 實例配置
?
3.1 初始化參數(shù)
[oracle@node1 bin]$ export ORACLE_SID=+ASM1
[oracle@node1 bin]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Feb 21 19:10:51 2010
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, Real Application Clusters, OLAP and Data Mining options
SQL> create pfile from spfile;
File created.
SQL> show parameter asm
NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TYPE ? ? ? ?VALUE
------------------------------------ ----------- ------------------------------
asm_diskgroups ? ? ? ? ? ? ? ? ? ? ? string ? ? ?FLASH_RECOVERY_AREA, DATA
asm_diskstring ? ? ? ? ? ? ? ? ? ? ? string
asm_power_limit ? ? ? ? ? ? ? ? ? ? ?integer ? ? 1
?
[oracle@node2 dbs]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@node2 dbs]$ ls
ab_+ASM2.dat ?hc_rac2.dat ? ?initrac2.ora ?orapwrac2
hc_+ASM2.dat ?init+ASM2.ora ?orapw+ASM2
[oracle@node2 dbs]$ more init+ASM1.ora
+ASM2.asm_diskgroups='FLASH_RECOVERY_AREA'#Manual Dismount
+ASM1.asm_diskgroups='FLASH_RECOVERY_AREA','DATA'#Manual Mount
*.asm_diskgroups='FLASH_RECOVERY_AREA','DATA'
*.background_dump_dest='/u01/app/oracle/admin/+ASM/bdump'
*.cluster_database=true
*.core_dump_dest='/u01/app/oracle/admin/+ASM/cdump'
+ASM2.instance_number=2
+ASM1.instance_number=1
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='exclusive'
*.user_dump_dest='/u01/app/oracle/admin/+ASM/udump'
?
相關(guān)說明:
ASM 實例的SGA 需要的內(nèi)存很小, 一般默認(rèn)值即可, 無需修改。 ASM SGA的默認(rèn)值如下:
SHARED_POOL_SIZE = 48M
LARGE_POOL_SIZE = 12M
SHARED_POOL_RESERVED_SIZE = 24M
SGA_MAX_SIZE = 88M
??這些默認(rèn)值可以在sqlplus 中通過show parameter 查看。
?
Instance_type: 對于ASM 實例, 這個應(yīng)該設(shè)置成ASM, 如果是數(shù)據(jù)庫實例,則是RDBMS.
DB_UNIQUE_NAME: 這個參數(shù)使用缺省值+ASM即可
?
?
SQL> show parameter asm_power_limit
NAME ? ? ? ? ? ?TYPE ? VALUE
----------------------- --------- ---------------
asm_power_limit ? integer ? ?1
ASM_POWER_LIMIT: 當(dāng)在磁盤組中添加刪除磁盤時,磁盤組會自動對數(shù)據(jù)在新舊磁盤間重新分配, 從而實現(xiàn)分散IO, 這個過程就叫再平衡(Rebalance);
?
這個動作會在磁盤間移動數(shù)據(jù),因此雖然是聯(lián)機(jī)操作,仍然會影響部分性能,所以要在系統(tǒng)空閑的時候進(jìn)行。 ?該參數(shù)控制Rebalance速度, 取值范圍0-11. 最小值0 代表不做Rebalance, 最大值11 代表最快的速度,也意味著嚴(yán)重影響性能, 1 代表最慢的速度和最小的性能影響。 除了在初始化參數(shù)中定義該參數(shù), 也可以在操作時指定。?
?
比如:
SQL> alter diskgroup DATA rebalance power 5;
Disk groups can be rebalanced manually using the REBALANCE clause of the ALTER DISKGROUP statement. If the POWER clause is omitted the ASM_POWER_LIMIT parameter value is used. Rebalancing is only needed when the speed of the automatic rebalancing is not appropriate.
?
ASM_DISKSTRING: 定義哪些磁盤可以被ASM 使用, ASM 實例啟動時就根據(jù)這個參數(shù)值掃描發(fā)現(xiàn)ASM磁盤,配置了這個參數(shù)以后,還必須確認(rèn)ORACLE 用戶對這些磁盤有操作的權(quán)限
1. 如果使用裸設(shè)備, 用逗號分隔每個設(shè)備名:
??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_DISKGROUPS: 這個參數(shù)用于定義ASM 實例啟動后自動掛載的磁盤組, 如果不自動掛載, 也可以使用命令掛載。
?
注意: ASM 實例啟動即可以通過pfile, 也可以通過spfile,如果使用spfile啟動,那么如果創(chuàng)建新的磁盤組, 這個參數(shù)會被自動修改, 下次啟動時會自動掛載這個新建的磁盤組,如果是使用pfile, 這個參數(shù)不會自動更新, 需要手工的更新。
?
3.2 CSS 進(jìn)程
無論是否在RAC 環(huán)境下, ASM 實例都是需要CSS 進(jìn)程的, 所以,如果是非RAC 環(huán)境, 在啟動ASM 實例之前用腳本?
$ORACLE_HOME/bin/localconfig add 啟動CSS, 否則ASM 實例啟動時會報ORA-29701: unable to connect to Cluster Manager, 并提示執(zhí)行該腳本
?
?
3.3 ASM 實例的相關(guān)操作
?
ASM 管理 登錄,啟動,關(guān)閉:
[oracle@node2 dbs]$ export ORACLE_SID=+ASM2
[oracle@node2 dbs]$ sqlplus / as sysdba
SQL> startup
SQL> shutdown immediate;
?
檢查disk group信息的SQL:
SQL> col state format a10
SQL> col name format a15
SQL> col failgroup format a20 ?
SQL> set line 200
SQL> select ?STATE,REDUNDANCY,TOTAL_MB,FREE_MB,NAME,FAILGROUP
?from v$asm_disk;
SQL>select ?GROUP_NUMBER,NAME,STATE,TYPE,TOTAL_MB,FREE_MB,
UNBALANCED ?from v$asm_diskgroup;
?
創(chuàng)建新的diskgroup
SQL> create diskgroup dgtest normal redundancy
??2 ?failgroup DATA1 disk '/dev/oracleasm/VOL5' name DATA1
??3 ?failgroup DATA2 disk '/dev/oracleasm/VOL6' name DATA2;
?
刪除diskgroup
SQL> drop diskgroup DATA including contents;
?
-- 對于多結(jié)點的diskgroup, 只能有在一個asm實例上掛載之后才能被dorp, 其他結(jié)點必須dismount。
?
手動mount命令
ALTER DISKGROUP ALL DISMOUNT;
ALTER DISKGROUP ALL MOUNT;
ALTER DISKGROUP DATA DISMOUNT;
ALTER DISKGROUP DATA MOUNT;
?
為diskgroup增加disk
SQL> alter diskgroup DATA add disk '/dev/oracleasm/VOL5' name
VOL5,'/dev/oracleasm/VOL6' name VOL6;
?
從diskgroup刪除disk
SQL> alter diskgroup DATA drop disk VOL5;
?
取消刪除disk的命令,只能在上述命令沒執(zhí)行完成的時候有效
ALTER DISKGROUP DATA UNDROP DISKS;
?
The UNDROP DISKS clause of the ALTER DISKGROUP statement allows pending disk drops to be undone. It will not revert drops that have completed, or disk drops associated with the
dropping of a disk group.
?
?
數(shù)據(jù)文件的管理
Aliases allow you to reference ASM files using user-friendly names, rather than the fully
qualified ASM filenames.
?
-- Create an alias using the fully qualified filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
??FOR '+disk_group_1/mydb/datafile/my_ts.342.3';
?
-- Create an alias using the numeric form filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
??FOR '+disk_group_1.342.3';
?
-- Rename an alias.
ALTER DISKGROUP disk_group_1 RENAME ALIAS '+disk_group_1/my_dir/my_file.dbf'
??TO '+disk_group_1/my_dir/my_file2.dbf';
?
-- Delete an alias.
ALTER DISKGROUP disk_group_1 DELETE ALIAS '+disk_group_1/my_dir/my_file.dbf';
?
-- Drop file using an alias.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';
?
-- Drop file using a numeric form filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1.342.3';
?
-- Drop file using a fully qualified filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/mydb/datafile/my_ts.342.3';
?
-- create datafile
SQL> create tablespace users2 datafile '+TESTDB_DATA1' size 100m;
?
注意事項:?
1. ASM 實例在配置好并且創(chuàng)建了ASM磁盤組之后,還必須保證已經(jīng)注冊到Listener中后才能在數(shù)據(jù)庫實例中使用,否則就需要手工注冊ASM 實例:
SQL>alter system register;
2. 一旦數(shù)據(jù)庫實例使用ASM 作為存儲, 那么在數(shù)據(jù)庫實例運行時是無法關(guān)閉ASM實例的。 否則會報 ORA-15097:cannot SHUTDOWN ASM instance with connected RDBMS instance. 錯誤。
?
4. Oracle 中刪除 ASM 實例
刪除自動存儲管理實例+ASM實例+ASM的刪除是在數(shù)據(jù)庫被卸載之后完成的,并刪除/ORACLE_HOME/dbs目錄下的所有文件(除了與ASM相關(guān)的)。因此必須完成下列步驟:
4.1在命令提示符中,設(shè)置oracle_sid環(huán)境變量為+ASM實例:
# export oracle_sid=+ASM
4.2啟動SQL*Plus并以sys用戶連接到自動存儲管理+ASM實例:
# sqlplus / as sysdba
4.3使用下列命令來確定是否有數(shù)據(jù)庫實例正在使用自動存儲管理實例+ASM:
SQL>select instance_name from v$asm_client;
該命令結(jié)果列出所有正在運行并使用+ASM實例的數(shù)據(jù)庫實例。只要+ASM包含正在支持的數(shù)據(jù)庫實例,就不能刪除該+ASM實例。(其實可以先shutdown對應(yīng)的數(shù)據(jù)庫實例,然后從asmcmd進(jìn)入磁盤組所在目錄,刪掉對應(yīng)的數(shù)據(jù)庫目錄和文件就可以了)。
4.4 如果沒有與+ASM相關(guān)聯(lián)的數(shù)據(jù)庫實例,則刪除與該實例相關(guān)聯(lián)的磁盤組。
首先,識別與+ASM相關(guān)聯(lián)的磁盤組:
SQL>select name from v$asm_diskgroup;
其次,用下列命令刪除每個要刪除的磁盤組:
SQL>drop diskgroup<disk_group_name>including contents;
4.5 關(guān)閉+ASM實例并退出SQL*Plus:
SQL>shutdown
SQL>exit
4.6 在命令提示符中輸入下列命令,刪除+ASM服務(wù)(我沒找到這個命令,所以沒有運行):
oradim -delete -asmsid +ASM
?
?
?
5. ?ASMCMD 工具
ASM 實例的管理除了sqlplus, Oracle 還提供了asmcmd 命令, 具體參考help。
?
[oracle@node1 bin]$ which asmcmd
/u01/app/oracle/product/10.2.0/db_1/bin/asmcmd
[oracle@node1 bin]$ cd /u01/app/oracle/product/10.2.0/db_1/bin/
[oracle@node1 bin]$ ./asmcmd
ASMCMD> ls
DATA/
FLASH_RECOVERY_AREA/
ASMCMD> help
?? ? ? ?asmcmd [-p] [command]
?
?? ? ? ?The environment variables ORACLE_HOME and ORACLE_SID determine the
?? ? ? ?instance to which the program connects, and ASMCMD establishes a
?? ? ? ?bequeath connection to it, in the same manner as a SQLPLUS / AS
?? ? ? ?SYSDBA. ?The user must be a member of the SYSDBA group.
?
?? ? ? ?Specifying the -p option allows the current directory to be displayed
?? ? ? ?in the command prompt, like so:
?
?? ? ? ?ASMCMD [+DATAFILE/ORCL/CONTROLFILE] >
?
?? ? ? ?[command] specifies one of the following commands, along with its
?? ? ? ?parameters.
?
?? ? ? ?Type "help [command]" to get help on a specific ASMCMD command.
?
?? ? ? ?commands:
?? ? ? ?--------
?? ? ? ?cd
?? ? ? ?du
?? ? ? ?find
?? ? ? ?help
?? ? ? ?ls
?? ? ? ?lsct
?? ? ? ?lsdg
?? ? ? ?mkalias
?? ? ? ?mkdir
?? ? ? ?pwd
?? ? ? ?rm
?? ? ? ?rmalias
ASMCMD>
?
?
----- 2010年9月23日補(bǔ)充--------
里面有刪除別名的語法, 現(xiàn)在已經(jīng)不支持了。 之前沒有測試,寫文章不嚴(yán)禁。 在google上搜這個問題的時候,發(fā)現(xiàn)有人轉(zhuǎn)載了我的文章,但是這個錯誤還是沒有發(fā)現(xiàn)。
?
剛查閱了一下Oracle 的聯(lián)機(jī)文檔, 刪除別名用的也是drop。
Example 7-5 Dropping an alias name for an Oracle ASM filename
ALTER DISKGROUP data DROP ALIAS '+data/payroll/compensation.dbf';
?
地址:
http://download.oracle.com/docs/cd/E11882_01/server.112/e16102/asmfiles.htm#CHDDHIGG
?
?
這里面有對ASM 有詳細(xì)的說明。 可以參考。
?
?
順便補(bǔ)充一點知識:
?
C:/Users/Administrator.DavidDai>sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 9月
Copyright (c) 1982, 2010, Oracle. ?All rights reserved
SQL> conn sys/oracle@rac2 as sysdba;
已連接。
SQL> select file_name from dba_data_files;
FILE_NAME
------------------------------------------------------
+DATA/orcl/datafile/users.279.730181053
+DATA/orcl/datafile/sysaux.277.730181053
+DATA/orcl/datafile/undotbs1.278.730181053
+DATA/orcl/datafile/system.276.730181051
+DATA/orcl/datafile/undotbs2.284.730181347
?
?
ASM文件名字的格式是固定的:+group/dbname/file type/tag.file.incarnation
?
在創(chuàng)建db時系統(tǒng)自動創(chuàng)建的幾個表空間(system,undotbs,sysaux,users)對應(yīng)的都是真實的數(shù)據(jù)文件,即ASM 文件默認(rèn)的命名格式。而且這個信息都寫到了控制文件里。 如果我們使用別名的話,會方便很多。 對于這些創(chuàng)建數(shù)據(jù)庫時自動創(chuàng)建的表空間,我們要他們使用別名,除了手工創(chuàng)建對應(yīng)別名外,還需要重建控制文件,并且在重建時,datafile 里寫別名的信息。 這樣數(shù)據(jù)庫也就使用別名了。
?
?
ASM 實例的創(chuàng)建和刪除也可以用DBCA 這個命令來操作。在dbca 的第一個界面選擇配置自動存儲管理就可以了。 ASM 實例需要CSS 進(jìn)程, 如果是非RAC 環(huán)境, 在啟動ASM 實例之前會提示用腳本?
$ORACLE_HOME/bin/localconfig add 啟動CSS。?
?
?
?
1. ASM 實例由SGA 和后臺進(jìn)程組成。
?
1.1 SGA 組成:
ASM 實例的SGA包括Buffer Cache, Share Pool, Large Pool等。 需要注意的是Share Pool, 因為Extent Map 要放在這部分的內(nèi)存中,需要更具數(shù)據(jù)量來估計Extent Map 的大小做相應(yīng)的調(diào)整。?
Extent Map 的大小可以根據(jù)所有文件大小的和來估算,使用下面的語句來計算所有文件和:
?
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';
?
這3個sum 的總和對應(yīng)著數(shù)據(jù)庫存放ASM中所有文件大小總和, 對于使用External Redundancy 的磁盤組, 每100G 需要1MB 的Extent Map, 根據(jù)這個比例計算Extent Map 所需要的空間,在加上額外的2MB就可以了。 在實際工作中一般不需要考慮ASM SGA的配置, 使用Oracle 提供的缺省值就可以了。
?
1.2 后臺進(jìn)程
?
ASM 實例比RDBMS 實例多2個進(jìn)程: RBAL 和 ABRn。
RBAL: 這個進(jìn)程也叫Rebalancer進(jìn)程, 負(fù)責(zé)規(guī)劃ASM 磁盤組的Reblance活動。
ABRn:是RBAL進(jìn)程的子進(jìn)程,這個進(jìn)程在數(shù)量上可以有多個, n從1~9, 這組進(jìn)程負(fù)責(zé)真正完成Reblance活動。
?
使用ASM 作為存儲的RDBMS 實例也會多出2個進(jìn)程: RBAL 和 ASMB
RBAL: 這個進(jìn)程的主要功能是打開每個磁盤的所有磁盤和數(shù)據(jù)的Rebalance。
ASMB: 這個進(jìn)程作為ASM 實例和數(shù)據(jù)庫實例之間的信息通道。 這個進(jìn)程負(fù)責(zé)與ASM 實例的通信, 它先利用Diskgroup Name 從CSS 獲得管理該Diskgroup 的ASM 實例的連接串, 然后建立到ASM 的持久連接, 兩個實例之間通過這條連接定期交換信息,同時也是一種心跳機(jī)制。
?
RDBMS 實例要想使用ASM 作為存儲, RDBMS 實例必須在啟動時從ASM 實例獲得Extent Map, 以后發(fā)生磁盤組的維護(hù)操作, ASM 實例還要把Extent Map的更新信息通知給RDBMS 實例, 這2個實例間的信息交換就是他你哦剛過ASMB 進(jìn)程完成的。 這也就為什么: ASM 實例必須要先于數(shù)據(jù)庫實例啟動,和數(shù)據(jù)庫實例同步運行,遲于數(shù)據(jù)庫實例關(guān)閉。
?
?
注意: ASM 實例和數(shù)據(jù)庫實例的關(guān)系可以是1:1, 也可以是1:n。如果是1:n, 最好為ASM 安裝單獨的ASM_HOME。
?
2. ASM 配置
?
ASM 可以使用裸設(shè)備 或者ASMLib 方式, 因為裸設(shè)別的維護(hù)比較復(fù)雜,在此只講解ASMLib 方式。?
?
對應(yīng)不同的操作系統(tǒng), 需要不同的包,下載的時候一定要和操作系統(tǒng)內(nèi)核一致。 我的操作系統(tǒng)是 Red hat 4 update 7. 內(nèi)核版本是2.6.9-78.ELSMP。
?
oracleasmlib-2.0.4-1.el4.i386.rpm
oracleasm-support-2.1.3-1.el4.i386.rpm
oracleasm-2.6.9-78.EL-2.0.5-1.el4.i686.rpm
?
http://www.oracle.com/technology/tech/linux/asmlib/index.html
該頁面有下載地址,注意選擇CPU 類型。 asmlib 和 support,在同一個頁面下載。
?
安裝包:
#rpm -ivh *.rpm
?
安裝完之后進(jìn)行配置:
#/etc/init.d/oracleasm configure
會有相應(yīng)的提示, 回答 oracle , dba, y, y 就可以了?
分別對應(yīng)默認(rèn)用戶, 默認(rèn)組,隨系統(tǒng)自啟動, 啟動時設(shè)置權(quán)限。
?
/etc/init.d/oracleasm createdisk VOL1 /dev/sdc1?
/etc/init.d/oracleasm scandisks?
/etc/init.d/oracleasm listdisks ?
?
關(guān)于oracleasm 的更多用法參考help:
[root@node1 ~]# /etc/init.d/oracleasm --help
Usage: /etc/init.d/oracleasm {start|stop|restart|enable|disable|configure
?? ? ? ? ? ? |createdisk|deletedisk|querydisk|listdisks|scandisks|status}
?
?
3. ASM 實例配置
?
3.1 初始化參數(shù)
[oracle@node1 bin]$ export ORACLE_SID=+ASM1
[oracle@node1 bin]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Feb 21 19:10:51 2010
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, Real Application Clusters, OLAP and Data Mining options
SQL> create pfile from spfile;
File created.
SQL> show parameter asm
NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TYPE ? ? ? ?VALUE
------------------------------------ ----------- ------------------------------
asm_diskgroups ? ? ? ? ? ? ? ? ? ? ? string ? ? ?FLASH_RECOVERY_AREA, DATA
asm_diskstring ? ? ? ? ? ? ? ? ? ? ? string
asm_power_limit ? ? ? ? ? ? ? ? ? ? ?integer ? ? 1
?
[oracle@node2 dbs]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@node2 dbs]$ ls
ab_+ASM2.dat ?hc_rac2.dat ? ?initrac2.ora ?orapwrac2
hc_+ASM2.dat ?init+ASM2.ora ?orapw+ASM2
[oracle@node2 dbs]$ more init+ASM1.ora
+ASM2.asm_diskgroups='FLASH_RECOVERY_AREA'#Manual Dismount
+ASM1.asm_diskgroups='FLASH_RECOVERY_AREA','DATA'#Manual Mount
*.asm_diskgroups='FLASH_RECOVERY_AREA','DATA'
*.background_dump_dest='/u01/app/oracle/admin/+ASM/bdump'
*.cluster_database=true
*.core_dump_dest='/u01/app/oracle/admin/+ASM/cdump'
+ASM2.instance_number=2
+ASM1.instance_number=1
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='exclusive'
*.user_dump_dest='/u01/app/oracle/admin/+ASM/udump'
?
相關(guān)說明:
ASM 實例的SGA 需要的內(nèi)存很小, 一般默認(rèn)值即可, 無需修改。 ASM SGA的默認(rèn)值如下:
SHARED_POOL_SIZE = 48M
LARGE_POOL_SIZE = 12M
SHARED_POOL_RESERVED_SIZE = 24M
SGA_MAX_SIZE = 88M
??這些默認(rèn)值可以在sqlplus 中通過show parameter 查看。
?
Instance_type: 對于ASM 實例, 這個應(yīng)該設(shè)置成ASM, 如果是數(shù)據(jù)庫實例,則是RDBMS.
DB_UNIQUE_NAME: 這個參數(shù)使用缺省值+ASM即可
?
?
SQL> show parameter asm_power_limit
NAME ? ? ? ? ? ?TYPE ? VALUE
----------------------- --------- ---------------
asm_power_limit ? integer ? ?1
ASM_POWER_LIMIT: 當(dāng)在磁盤組中添加刪除磁盤時,磁盤組會自動對數(shù)據(jù)在新舊磁盤間重新分配, 從而實現(xiàn)分散IO, 這個過程就叫再平衡(Rebalance);
?
這個動作會在磁盤間移動數(shù)據(jù),因此雖然是聯(lián)機(jī)操作,仍然會影響部分性能,所以要在系統(tǒng)空閑的時候進(jìn)行。 ?該參數(shù)控制Rebalance速度, 取值范圍0-11. 最小值0 代表不做Rebalance, 最大值11 代表最快的速度,也意味著嚴(yán)重影響性能, 1 代表最慢的速度和最小的性能影響。 除了在初始化參數(shù)中定義該參數(shù), 也可以在操作時指定。?
?
比如:
SQL> alter diskgroup DATA rebalance power 5;
Disk groups can be rebalanced manually using the REBALANCE clause of the ALTER DISKGROUP statement. If the POWER clause is omitted the ASM_POWER_LIMIT parameter value is used. Rebalancing is only needed when the speed of the automatic rebalancing is not appropriate.
?
ASM_DISKSTRING: 定義哪些磁盤可以被ASM 使用, ASM 實例啟動時就根據(jù)這個參數(shù)值掃描發(fā)現(xiàn)ASM磁盤,配置了這個參數(shù)以后,還必須確認(rèn)ORACLE 用戶對這些磁盤有操作的權(quán)限
1. 如果使用裸設(shè)備, 用逗號分隔每個設(shè)備名:
??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_DISKGROUPS: 這個參數(shù)用于定義ASM 實例啟動后自動掛載的磁盤組, 如果不自動掛載, 也可以使用命令掛載。
?
注意: ASM 實例啟動即可以通過pfile, 也可以通過spfile,如果使用spfile啟動,那么如果創(chuàng)建新的磁盤組, 這個參數(shù)會被自動修改, 下次啟動時會自動掛載這個新建的磁盤組,如果是使用pfile, 這個參數(shù)不會自動更新, 需要手工的更新。
?
3.2 CSS 進(jìn)程
無論是否在RAC 環(huán)境下, ASM 實例都是需要CSS 進(jìn)程的, 所以,如果是非RAC 環(huán)境, 在啟動ASM 實例之前用腳本?
$ORACLE_HOME/bin/localconfig add 啟動CSS, 否則ASM 實例啟動時會報ORA-29701: unable to connect to Cluster Manager, 并提示執(zhí)行該腳本
?
?
3.3 ASM 實例的相關(guān)操作
?
ASM 管理 登錄,啟動,關(guān)閉:
[oracle@node2 dbs]$ export ORACLE_SID=+ASM2
[oracle@node2 dbs]$ sqlplus / as sysdba
SQL> startup
SQL> shutdown immediate;
?
檢查disk group信息的SQL:
SQL> col state format a10
SQL> col name format a15
SQL> col failgroup format a20 ?
SQL> set line 200
SQL> select ?STATE,REDUNDANCY,TOTAL_MB,FREE_MB,NAME,FAILGROUP
?from v$asm_disk;
SQL>select ?GROUP_NUMBER,NAME,STATE,TYPE,TOTAL_MB,FREE_MB,
UNBALANCED ?from v$asm_diskgroup;
?
創(chuàng)建新的diskgroup
SQL> create diskgroup dgtest normal redundancy
??2 ?failgroup DATA1 disk '/dev/oracleasm/VOL5' name DATA1
??3 ?failgroup DATA2 disk '/dev/oracleasm/VOL6' name DATA2;
?
刪除diskgroup
SQL> drop diskgroup DATA including contents;
?
-- 對于多結(jié)點的diskgroup, 只能有在一個asm實例上掛載之后才能被dorp, 其他結(jié)點必須dismount。
?
手動mount命令
ALTER DISKGROUP ALL DISMOUNT;
ALTER DISKGROUP ALL MOUNT;
ALTER DISKGROUP DATA DISMOUNT;
ALTER DISKGROUP DATA MOUNT;
?
為diskgroup增加disk
SQL> alter diskgroup DATA add disk '/dev/oracleasm/VOL5' name
VOL5,'/dev/oracleasm/VOL6' name VOL6;
?
從diskgroup刪除disk
SQL> alter diskgroup DATA drop disk VOL5;
?
取消刪除disk的命令,只能在上述命令沒執(zhí)行完成的時候有效
ALTER DISKGROUP DATA UNDROP DISKS;
?
The UNDROP DISKS clause of the ALTER DISKGROUP statement allows pending disk drops to be undone. It will not revert drops that have completed, or disk drops associated with the
dropping of a disk group.
?
?
數(shù)據(jù)文件的管理
Aliases allow you to reference ASM files using user-friendly names, rather than the fully
qualified ASM filenames.
?
-- Create an alias using the fully qualified filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
??FOR '+disk_group_1/mydb/datafile/my_ts.342.3';
?
-- Create an alias using the numeric form filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
??FOR '+disk_group_1.342.3';
?
-- Rename an alias.
ALTER DISKGROUP disk_group_1 RENAME ALIAS '+disk_group_1/my_dir/my_file.dbf'
??TO '+disk_group_1/my_dir/my_file2.dbf';
?
-- Delete an alias.
ALTER DISKGROUP disk_group_1 DELETE ALIAS '+disk_group_1/my_dir/my_file.dbf';
?
-- Drop file using an alias.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';
?
-- Drop file using a numeric form filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1.342.3';
?
-- Drop file using a fully qualified filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/mydb/datafile/my_ts.342.3';
?
-- create datafile
SQL> create tablespace users2 datafile '+TESTDB_DATA1' size 100m;
?
注意事項:?
1. ASM 實例在配置好并且創(chuàng)建了ASM磁盤組之后,還必須保證已經(jīng)注冊到Listener中后才能在數(shù)據(jù)庫實例中使用,否則就需要手工注冊ASM 實例:
SQL>alter system register;
2. 一旦數(shù)據(jù)庫實例使用ASM 作為存儲, 那么在數(shù)據(jù)庫實例運行時是無法關(guān)閉ASM實例的。 否則會報 ORA-15097:cannot SHUTDOWN ASM instance with connected RDBMS instance. 錯誤。
?
4. Oracle 中刪除 ASM 實例
刪除自動存儲管理實例+ASM實例+ASM的刪除是在數(shù)據(jù)庫被卸載之后完成的,并刪除/ORACLE_HOME/dbs目錄下的所有文件(除了與ASM相關(guān)的)。因此必須完成下列步驟:
4.1在命令提示符中,設(shè)置oracle_sid環(huán)境變量為+ASM實例:
# export oracle_sid=+ASM
4.2啟動SQL*Plus并以sys用戶連接到自動存儲管理+ASM實例:
# sqlplus / as sysdba
4.3使用下列命令來確定是否有數(shù)據(jù)庫實例正在使用自動存儲管理實例+ASM:
SQL>select instance_name from v$asm_client;
該命令結(jié)果列出所有正在運行并使用+ASM實例的數(shù)據(jù)庫實例。只要+ASM包含正在支持的數(shù)據(jù)庫實例,就不能刪除該+ASM實例。(其實可以先shutdown對應(yīng)的數(shù)據(jù)庫實例,然后從asmcmd進(jìn)入磁盤組所在目錄,刪掉對應(yīng)的數(shù)據(jù)庫目錄和文件就可以了)。
4.4 如果沒有與+ASM相關(guān)聯(lián)的數(shù)據(jù)庫實例,則刪除與該實例相關(guān)聯(lián)的磁盤組。
首先,識別與+ASM相關(guān)聯(lián)的磁盤組:
SQL>select name from v$asm_diskgroup;
其次,用下列命令刪除每個要刪除的磁盤組:
SQL>drop diskgroup<disk_group_name>including contents;
4.5 關(guān)閉+ASM實例并退出SQL*Plus:
SQL>shutdown
SQL>exit
4.6 在命令提示符中輸入下列命令,刪除+ASM服務(wù)(我沒找到這個命令,所以沒有運行):
oradim -delete -asmsid +ASM
?
?
?
5. ?ASMCMD 工具
ASM 實例的管理除了sqlplus, Oracle 還提供了asmcmd 命令, 具體參考help。
?
[oracle@node1 bin]$ which asmcmd
/u01/app/oracle/product/10.2.0/db_1/bin/asmcmd
[oracle@node1 bin]$ cd /u01/app/oracle/product/10.2.0/db_1/bin/
[oracle@node1 bin]$ ./asmcmd
ASMCMD> ls
DATA/
FLASH_RECOVERY_AREA/
ASMCMD> help
?? ? ? ?asmcmd [-p] [command]
?
?? ? ? ?The environment variables ORACLE_HOME and ORACLE_SID determine the
?? ? ? ?instance to which the program connects, and ASMCMD establishes a
?? ? ? ?bequeath connection to it, in the same manner as a SQLPLUS / AS
?? ? ? ?SYSDBA. ?The user must be a member of the SYSDBA group.
?
?? ? ? ?Specifying the -p option allows the current directory to be displayed
?? ? ? ?in the command prompt, like so:
?
?? ? ? ?ASMCMD [+DATAFILE/ORCL/CONTROLFILE] >
?
?? ? ? ?[command] specifies one of the following commands, along with its
?? ? ? ?parameters.
?
?? ? ? ?Type "help [command]" to get help on a specific ASMCMD command.
?
?? ? ? ?commands:
?? ? ? ?--------
?? ? ? ?cd
?? ? ? ?du
?? ? ? ?find
?? ? ? ?help
?? ? ? ?ls
?? ? ? ?lsct
?? ? ? ?lsdg
?? ? ? ?mkalias
?? ? ? ?mkdir
?? ? ? ?pwd
?? ? ? ?rm
?? ? ? ?rmalias
ASMCMD>
?
?
----- 2010年9月23日補(bǔ)充--------
里面有刪除別名的語法, 現(xiàn)在已經(jīng)不支持了。 之前沒有測試,寫文章不嚴(yán)禁。 在google上搜這個問題的時候,發(fā)現(xiàn)有人轉(zhuǎn)載了我的文章,但是這個錯誤還是沒有發(fā)現(xiàn)。
?
剛查閱了一下Oracle 的聯(lián)機(jī)文檔, 刪除別名用的也是drop。
Example 7-5 Dropping an alias name for an Oracle ASM filename
ALTER DISKGROUP data DROP ALIAS '+data/payroll/compensation.dbf';
?
地址:
http://download.oracle.com/docs/cd/E11882_01/server.112/e16102/asmfiles.htm#CHDDHIGG
?
?
這里面有對ASM 有詳細(xì)的說明。 可以參考。
?
?
順便補(bǔ)充一點知識:
?
C:/Users/Administrator.DavidDai>sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 9月
Copyright (c) 1982, 2010, Oracle. ?All rights reserved
SQL> conn sys/oracle@rac2 as sysdba;
已連接。
SQL> select file_name from dba_data_files;
FILE_NAME
------------------------------------------------------
+DATA/orcl/datafile/users.279.730181053
+DATA/orcl/datafile/sysaux.277.730181053
+DATA/orcl/datafile/undotbs1.278.730181053
+DATA/orcl/datafile/system.276.730181051
+DATA/orcl/datafile/undotbs2.284.730181347
?
?
ASM文件名字的格式是固定的:+group/dbname/file type/tag.file.incarnation
?
在創(chuàng)建db時系統(tǒng)自動創(chuàng)建的幾個表空間(system,undotbs,sysaux,users)對應(yīng)的都是真實的數(shù)據(jù)文件,即ASM 文件默認(rèn)的命名格式。而且這個信息都寫到了控制文件里。 如果我們使用別名的話,會方便很多。 對于這些創(chuàng)建數(shù)據(jù)庫時自動創(chuàng)建的表空間,我們要他們使用別名,除了手工創(chuàng)建對應(yīng)別名外,還需要重建控制文件,并且在重建時,datafile 里寫別名的信息。 這樣數(shù)據(jù)庫也就使用別名了。
總結(jié)
以上是生活随笔為你收集整理的Oracle ASM 详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle 数据字典表 -- SYS.
- 下一篇: ORA-00060 Deadlock d