目录
* 这里忘记将+ASM实例的创建方法了。。很简单,用dbca来创建!
一,认识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是 Oracle 数据库 10g 中一个非常出色的新特性,它以平台无关的方式提供了文件系统、逻辑卷管理器以及软件 RAID 等服务。ASM 可以条带化和镜像磁盘,从而实现了在数据库被加载的情况下添加或移除磁盘以及自动平衡 I/O 以删除“热点”。它还支持直接和异步的 I/O 并使用 Oracle9i 中引入的 Oracle 数据管理器 API(简化的 I/O 系统调用接口)。
ASM 不是一个通用的文件系统,并只能用于 Oracle 数据文件、重做日志以及控制文件。ASM 中的文件既可以由数据库自动创建和命名(通过使用 Oracle 管理文件特性),也可以由 DBA 手动创建和命名。由于操作系统无法访问 ASM 中存储的文件,因此对使用 ASM 文件的数据库执行备份和恢复操作的唯一途径就是通过恢复管理器 (RMAN)。
ASM 作为单独的 Oracle 实例实施,只有它在运行时其他数据库才能访问它。在 Linux 上,只有运行 OCSSD 服务(由 Oracle 通用安装程序默认安装)才能使用 ASM。ASM 需要的内存不多:对大多数系统,只需 64 MB。
external redundancy 表示Oracle不帮你管理镜像,功能由外部存储系统实现,比如通过RAID技术。
normal redundancy (默认方式)表示Oracle提供2路镜像来保护数据。
high redundancy 表示Oracle提供3路镜像来保护数据。
ASM的镜像算法是extent级别,而不是整个磁盘级别。这里面有个primary copy 和second copy的概念;写入的时候依据primary copy,最终实现写入随机有序读取,来完成平衡数据读取的目的。
[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'
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%]
[root@kk 32bit]# vi /etc/selinux/config <==关闭selinux,否则会报错
SELINUX=enforcing
改为
SELINUX=disabled
[root@kk Server]# setenforce 0
[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
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 ]
[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
首先安装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)
注意: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 ]
[root@kk 32bit]# /etc/init.d/oracleasm listdisks <==查看已标记为ASMLib的硬盘
VOL1
VOL2
VOL3
冗余
- 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例程
否则会报下面的错误
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>
正文:
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
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
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: 从时间戳提取,唯一值 。
[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';
[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
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
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
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
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
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
http://space.itpub.net/?uid-354732-action-viewspace-itemid-627665
http://space.itpub.net/?uid-354732-action-viewspace-itemid-628992
http://space.itpub.net/?uid-354732-action-viewspace-itemid-629497
http://space.itpub.net/?uid-354732-action-viewspace-itemid-629586
http://space.itpub.net/?uid-354732-action-viewspace-itemid-629618
http://blog.chinaunix.net/u/19769/showart_244125.html
http://yangtingkun.itpub.net/post/468/484002
http://www.orafaq.com/wiki/ASM_FAQ
转载请标明出处:http://blog.sina.com.cn/s/blog_465a4a1e0100qthi.html