在Oracle 环境下,使用grid帐号执行
运行asmcmd进入asm命令模式,如:
[grid@oradb-node1 ~]$ asmcmd
ASMCMD>
ASMCMD> du //显示指定的ASM目录下ASM文件占用的所有磁盘空间
Used_MB Mirror_used_MB
2070568 2070832
ASMCMD> ls -ls //列出ASM目录下的内容及其属性、磁盘空间占用
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 614400 520061 0 520061 0 N ARCH/
MOUNTED EXTERN N 512 4096 1048576 3735552 1759332 0 1759332 0 N DATA/
MOUNTED NORMAL N 512 4096 1048576 30720 29794 10240 9777 0 Y OCRVOTE/
ASMCMD> pwd //查看当前路径
ASMCMD> cd ..//进入上层目录
ASMCMD> cd +DATA 切换目录
ASMCMD> lsct //列出当前ASM客户端的信息
DB_Name Status Software_Version Compatible_version Instance_Name Disk_Group
+ASM CONNECTED 11.2.0.4.0 11.2.0.4.0 +ASM1 OCRVOTE
+ASM CONNECTED 11.2.0.4.0 11.2.0.4.0 +ASM1 DATA
CJOTM CONNECTED 11.2.0.4.0 11.2.0.4.0 CJOTM1 DATA
CJOTM CONNECTED 11.2.0.4.0 11.2.0.4.0 CJOTM1 ARCH
ASMCMD> lsdg //列出所有磁盘组及其属性
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 614400 519765 0 519765 0 N ARCH/
MOUNTED EXTERN N 512 4096 1048576 3735552 1759332 0 1759332 0 N DATA/
MOUNTED NORMAL N 512 4096 1048576 30720 29794 10240 9777 0 Y OCRVOTE/
ASMCMD> lsof //列出数据文件信息
DB_Name Instance_Name Path
+ASM +ASM1 +ocrvote.255.4294967295
CJOTM CJOTM1 +arch/cjotm/control02.ctl
CJOTM CJOTM1 +data/cjotm/control01.ctl
CJOTM CJOTM1 +data/cjotm/datafile/archive.334.957386631
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day1.313.957386317
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day2.329.957386613
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day3.330.957386613
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day4.333.957386627
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day5.325.957386633
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day6.307.957386315
CJOTM CJOTM1 +data/cjotm/datafile/bpl_day7.326.957386639
CJOTM CJOTM1 +data/cjotm/datafile/data.286.957386149
CJOTM CJOTM1 +data/cjotm/datafile/data.296.957386261
CJOTM CJOTM1 +data/cjotm/datafile/data.316.957386493
CJOTM CJOTM1 +data/cjotm/datafile/data.320.957386563
CJOTM CJOTM1 +data/cjotm/datafile/data.321.957386579
ASMCMD> lsdsk//列出盘的信息
Path
/dev/asm-diskb
/dev/asm-diskc
/dev/asm-diskd
/dev/asm-diske
/dev/asm-diskf
/dev/asm-diskg
/dev/asm-diskh
/dev/asm-diski
ASMCMD> rm -f *.dbf //删除当前所有扩展名为 .dbf 文件
ASMCMD> rm -fr orcldemo //删除当前 orcldemo 目录
ASM磁盘的根路径为“+”,而不是“/",以下为演示操作:
ASMCMD> cd DATA
ASMCMD> pwd
+DATA //当前路径为+datadg/gd
ASMCMD> cd + //切换到ASM磁盘根路径
ASMCMD> pwd
+ //当前路径为根路径 +
也可以不进入ASM命令模式下操作,如:
[grid@oradb-node1 ~]$ asmcmd ls -ls //查看ASM磁盘占用情况
[grid@otmdb2 ~]$ asmcmd ls -ls
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 614400 519765 0 519765 0 N ARCH/
MOUNTED EXTERN N 512 4096 1048576 3735552 1759332 0 1759332 0 N DATA/
MOUNTED NORMAL N 512 4096 1048576 30720 29794 10240 9777 0 Y OCRVOTE/
若要使用图形界面,可以使用ASM助手命令:asmca
[grid@oradb-node1 ~]$ sqlplus / as sysasm
--查看磁盘组信息
SQL> select name,state,type,total_mb ,free_mb from v$asm_diskgroup;
正式库OTM:
NAME STATE TYPE TOTAL_MB FREE_MB
ARCH CONNECTED EXTERN 614400 519765
DATA CONNECTED EXTERN 3735552 1759332
OCRVOTE MOUNTED NORMAL 30720 29794
--查看磁盘信息
select group_number,path,state,total_mb,free_mb from v$asm_disk;
select t.path,t.state,t.TOTAL_MB/1024,t.FREE_MB/1024,t.name from v$asm_disk t order by t.NAME
生产库:
PATH STATE T.TOTAL_MB/1024 T.FREE_MB/1024 NAME
/dev/asm-diske NORMAL 600 507.5830078125 ARCH_0000
/dev/asm-diskf NORMAL 800 376.7744140625 DATA_0000
/dev/asm-diskg NORMAL 800 376.7666015625 DATA_0001
/dev/asm-diskh NORMAL 1024 482.27734375 DATA_0002
/dev/asm-diski NORMAL 1024 482.279296875 DATA_0003
/dev/asm-diskd NORMAL 10 9.6982421875 OCRVOTE_0000
/dev/asm-diskc NORMAL 10 9.7001953125 OCRVOTE_0001
/dev/asm-diskb NORMAL 10 9.697265625 OCRVOTE_0002
测试库:
/dev/oracleasm/disks/VOL3 NORMAL 11.99609375 11.1484375 DATA_0000
/dev/oracleasm/disks/VOL4 NORMAL 11.99609375 11.146484375 DATA_0001
/dev/oracleasm/disks/VOL5 NORMAL 11.99609375 11.1494140625 DATA_0002
/dev/oracleasm/disks/VOL2 NORMAL 10.9921875 10.1044921875 FRA_0000
/dev/oracleasm/disks/VOL1 NORMAL 9.99609375 9.57421875 OCR_0000
--查看磁盘I/O信息,datadg为磁盘组名
[grid@rac1 ~]$ asmcmd lsdsk --statistics -G DATA
Reads Write Read_Errs Write_Errs Read_time Write_Time Bytes_Read Bytes_Written Voting_File Path
8390 6018 0 0 7.463504 11.516104 132957184 74924032 N /dev/oracleasm/disks/VOL3
11113 1502 0 0 6.45236 20.018922 178943488 17656320 N /dev/oracleasm/disks/VOL4
11713 4237 0 0 11.42369 6.222838 185649664 14785536 N /dev/oracleasm/disks/VOL5
或者简要显示读写,包括ASM磁盘列表
[grid@rac1 ~]$ asmcmd iostat -G DATA
Group_Name Dsk_Name Reads Writes
DATA DATA_0000 133645312 75618304
DATA DATA_0001 180073984 17754624
DATA DATA_0002 186894848 14851072
增加ASM磁盘disk08_test至ASM磁盘组datadg,磁盘路径为ORCL:DATA3_TEST
(需要先在操作系统级别/etc/init.d/oracleasm createdisk DATA3_TEST /dev/mapper/mpathx建立此磁盘名)
SQL> alter diskgroup datadg add disk 'ORCL:DATA3_TEST' name disk08_test;
从ASM磁盘组datadg里删除ASM磁盘disk08_test
SQL> alter diskgroup datadg drop disk disk08_test;
一、ASM磁盘和磁盘组管理
1、创建磁盘组
create diskgroup DG2 EXTERNAL REDUNDANCY DISK 'ORCL:A1';
create diskgroup SYSDGM normal redundancy FAILGROUP flgrp1 disk '/dev/rhdisk52','/dev/rhdisk53' FAILGROUP flgrp2 disk '/dev/rhdisk14','/dev/rhdisk13';
1)磁盘名称需要大写
2)磁盘名称使用V$asm_disk.path
2、磁盘组中添加磁盘
alter diskgroup dg2 add disk 'ORCL:A2';
1)磁盘名称使用V$asm_disk.path
3、磁盘组中删除磁盘
alter diskgroup dg2 drop disk 'a1';
1)磁盘名称使用的是V$asm_disk.name
4、删除磁盘组
drop diskgroup dg2 including contents;
二、ASM相关视图
1、查看是否有数据库实例连接上ASM实例
select instance_name,db_name,status from v$asm_client;
INSTANCE_NAME DB_NAME STATUS
+ASM1 CJOTM CONNECTED
+ASM1 CJOTM CONNECTED
2、记录BALANCE操作
select operation,state,power,actual,sofar from v$asm_operation;
alter diskgroup SYSDGM rebalance power 11;
---power0~11,0表示不rebalance,这个参数由ASM_POWER_LIMIT设置。
3、ASM DISK信息
select path, state, total_mb, free_mb from v$asm_disk;
4、ASM DISKGROUP信息,包括磁盘大小和剩余空间
select name,state,type,total_mb,free_mb from v$asm_diskgroup;
NAME STATE TYPE TOTAL_MB FREE_MB
ARCH CONNECTED EXTERN 614400 518931
DATA CONNECTED EXTERN 3735552 1759332
OCRVOTE MOUNTED NORMAL 30720 29794
三、ASM和表空间管理
1、ASM中创建表空间
create tablespace tgyun datafile '+DG2' SIZE 100M;
2、ASM表空间中添加数据文件
alter tablespace tgyun add datafile '+dg2' size 10m;
3、ASM表空间中删除数据文件
alter tablespace tgyun drop datafile '+DG2/tgyun/datafile/tgyun.257.747278679';
或者
alter tablespace tgyun drop datafile 3;
4、删除表空间
drop tablespace tgyun including contents;
--查看当前磁盘组状态
SQL> select group_number,name,state,total_mb,free_mb from v$asm_diskgroup;
--卸载dg2磁盘组
SQL> alter diskgroup dg2 dismount;
SQL> select group_number,name,state,total_mb,free_mb from v$asm_diskgroup;
--挂载dg2磁盘组
SQL> alter diskgroup dg2 mount;
--卸载所有磁盘组
SQL> alter diskgroup all dismount;
SQL> select group_number,name,state,total_mb,free_mb from v$asm_diskgroup;
--挂载所有磁盘组
SQL> alter diskgroup all mount;
select group_number,name,state,total_mb,free_mb from v$asm_diskgroup;
--如果当前磁盘组有实例在访问,则不能被卸载
SQL> alter diskgroup data dismount;
alter diskgroup data dismount
* ERROR at line 1: ORA-15032: not all alterations performed
ORA-15027: active use of diskgroup "DATA" precludes its dismount
--创建目录
SQL> alter diskgroup dg2 add directory '+DG2/TGYUN';
Diskgroup altered.
--使用asmcmd查看(export ORACLE_SID=+ASM;asmcmd进入)
ASMCMD> pwd
+DG2
ASMCMD> ls -l
Type Redund Striped Time Sys Name
N TGYUN/
--目录重命名
SQL> alter diskgroup dg2 rename directory '+DG2/CHENGFEI' TO '+DG2/TGYUN';
Diskgroup altered.
ASMCMD> ls TGYUN/
--删除目录
SQL> alter diskgroup dg2 drop directory '+DG2/tgyun';
Diskgroup altered.
ASMCMD> ls
ASMCMD>
--添加别名
SQL> alter diskgroup dg2 add alias '+dg2/TGYUN' for '+dg2/tgyun/datafile/TY.256.754832383';
Diskgroup altered.
--使用asmcmd查看别名是否成功
ASMCMD> pwd
--别名重命名
SQL> alter diskgroup dg2 rename alias '+DG2/TGYUN' TO '+DG2/TGYUN.DBF';
Diskgroup altered.
--删除别名
SQL> alter diskgroup dg2 drop alias '+dg2/tgyun.dbf';
Diskgroup altered.
说明:
1)asmcmd命令行操作中,目录文件名不区分大小写,命令关键字区分大小写
2)磁盘组中的一个文件,最多只能建立一个别名,可以通过v$asm_alias视图查看别名的相关信息