一、ASM使用中需要注意的知识点
1.单个磁盘的大小不要大于2T,因为超过2T的磁盘无法创建磁盘组。
2.尽量使用多块大小相同的磁盘创建同一磁盘组,这样做的好处有两点:
a.磁盘头部损坏时方便更换,减少数据损坏风险。
b.如果大小不统一,容易导致磁盘组剩余容量足够但不能使用的问题。
3.创建磁盘组之前要设置好冗余度,之后无法调整,需要改变磁盘组的冗余(external, normal,high),需要重建磁盘组。
4.对于AIX系统,裸盘不能有pvid,且要设置reserve_policy
pvid会占用盘头,而asm需要在盘头写信息
例如:
lsattr -El hdisk5
/usr/sbin/chdev -l hdisk5 -a pv=clear
chdev -l hdisk20 -a reserve_policy=no_reserve
5.对于已有文件系统的数据库环境新增ASM功能时,需要给oracle用户授予asmdba组。
6.asm disk的前50个AU(50M)是为asm metadata保留的空间。
7.asm的前255个file number是为 metadata file保留的,
文件号从1开始,file_number=1的1号文件为asm的file directory。
普通的asm file 的file number从256开始,asm disk的第二个au即是file number=1 的file directory(非必然),在1MB AU和 4096bytesblock 的情况下可以存放255个file directory information,其block type 为kfbtyp_filedir。
普通asm file 的directory info 的位置,可以这样计算, file number=1 的第(file number-256)/256+2 个extent, blkn=mod((file number-256),256),例如文件号258=第二个extent的blkn=2.
KFBTYP_FILEDIR中从kfffde[0].xptr.au 是直接盘区指针 directory extent pointers, kfffde[60].xptr.au 以上是 kfbtyp_indirect(kffixe)间接盘区指针 indirectory extents pointers
8.ASM磁盘的sector尽量不使用4096大小。
asm磁盘属性的sector依赖磁盘属性,如果磁盘属性是512,却设置为4096,则会有性能损失,而如果磁盘属性是4096,创建磁 盘组指定为512时,则会报错
例:
sqlplus / as sysasm
ALTER DISKGROUP crs
SET ATTRIBUTE 'sector_size'='4096';
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15242: could not set attribute sector_size
ORA-15238: 4096 is not a valid value for attribute sector_size
ORA-15376: The existence of native disk 'AFD:CRS1' does not allow disk group
CRS from changing sector sizes. Sector size of native disk is 512.
asm sector支持的矩阵
查看sector_size的语句
SELECT name, value FROM V$ASM_ATTRIBUTE
WHERE (name = 'sector_size' OR name = 'logical_sector_size') AND group_number = 1;
或
SELECT logical_sector_size, sector_size FROM V$ASM_DISKGROUP
WHERE group_number = 1;
指定sector_size创建磁盘组及修改命令
CREATE DISKGROUP data NORMAL REDUNDANCY
FAILGROUP controller1 DISK
'/devices/diska1',
'/devices/diska2',
'/devices/diska3',
'/devices/diska4'
FAILGROUP controller2 DISK
'/devices/diskb1',
'/devices/diskb2',
'/devices/diskb3',
'/devices/diskb4'
QUORUM FAILGROUP quorum_failgrp DISK '/devices/diskc1'
ATTRIBUTE 'compatible.asm' = '12.2', 'compatible.rdbms' = '12.2',
'sector_size'='4096', 'logical_sector_size'='512';
ALTER DISKGROUP data2
SET ATTRIBUTE 'compatible.asm' = '12.2', 'compatible.rdbms' = '12.2';
ALTER DISKGROUP data2
SET ATTRIBUTE 'sector_size'='4096', 'logical_sector_size'='4096';
9.为ASM磁盘组增加磁盘时,会导致rebalance,占用IO资源,尽量在非生产时间添加磁盘。
10.ASM磁盘组的属性disk_repair_time的修改需要其兼容性在11.1.0.0.0以上
disk_repair_time影响冗余的情景下,自动offline的磁盘被快速加回
例:
alter diskgroup data1 set attribute 'disk_repair_time' = '5m';
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15242: could not set attribute disk_repair_time
ORA-15283: ASM operation requires compatible.rdbms of 11.1.0.0.0 or higher
ALTER DISKGROUP data1 SET ATTRIBUTE 'compatible.rdbms' = '11.1';
如果该参数为空,也可以导致问题
ORA-15032: not all alterations performed
ORA-15063: ASM discovered an insufficient number of disks for diskgroup "DG_U1RSB1_000"
asm_diskstring可以为如下内容
'/dev/rhdisk10','/dev/rhdisk11','/dev/rhdisk12'
12.ASM中文件名的incarnation号会因为restore发生变化
文件名“+diskgroup_name/database_name/database file type/tag_name.file_number.incarnation”
每次 restore,incarnation 号会变
Extent mapping table for ASM files
Column Name Description
ADDR table address/identifier
INDX row identifier
INST_ID instance number (RAC)
NUMBER_KFFXP ASM file number. Join with v$asm_file and v$asm_alias
COMPOUND_KFFXP File identifier. Join with compound_index in v$asm_file
INCARN_KFFXP File incarnation id. Join with incarnation in v$asm_file
PXN_KFFXP Extent number per file
XNUM_KFFXP Logical extent number per file (mirrored extents have the same value)
GROUP_KFFXP ASM disk group number. Join with v$asm_disk and v$asm_diskgroup
DISK_KFFXP Disk number where the extent is allocated. Join with v$asm_disk
AU_KFFXP Relative position of the allocation unit from the beginning of the disk. The allocation unit size (1 MB) in v$asm_diskgroup
LXN_KFFXP 0,1 used to identify primary/mirror extent, 2 identifies file header allocation unit (hypothesis)
set pagesize 999
SELECT lpad(' ', 3 * (level - 1)) || concat('+'||gname, sys_connect_by_path(aname, '/')) full_alias_path FROM
(SELECT g.name gname, a.parent_index pindex, a.name aname,
a.reference_index rindex FROM v$asm_alias a, v$asm_diskgroup g
WHERE a.group_number = g.group_number)
START WITH (mod(pindex, power(2, 24))) = 0
CONNECT BY PRIOR rindex = pindex;
5.查看每个文件在各个磁盘分布的AU数col "ASM file number" for 9999
col "ASM metadata file name" for a40
col "Allocation units" for 9999
set linesize 120
select
NUMBER_KFFXP "ASM file number", DECODE (NUMBER_KFFXP, 1, 'File directory', 2, 'Disk directory', 3, 'Active change directory', 4, 'Continuing operations directory', 5, 'Template directory', 6, 'Alias directory', 7, 'ADVM file directory', 8, 'Disk free space directory', 9, 'Attributes directory', 10, 'ASM User directory', 11, 'ASM user group directory', 12, 'Staleness directory', 253, 'spfile for ASM instance', 254, 'Stale bit map space registry ', 255, 'Oracle Cluster Repository registry') "ASM metadata file name", count(AU_KFFXP) "Allocation units"
from X$KFFXP
where GROUP_KFFXP=1 and NUMBER_KFFXP<256
group by NUMBER_KFFXP
order by 1;
col name for a40
col description for a50
col VALUE for a10
col isdefault for a5
col ISMODIFIED for a5
col ISADJUSTED for a5
set linesize 120
set pagesize 9999
SELECT i.ksppinm name,
CV.ksppstvl VALUE,
CV.ksppstdf isdefault,
DECODE (BITAND (CV.ksppstvf, 7),
1, 'MODIFIED',
4, 'SYSTEM_MOD',
'FALSE')
ismodified,
DECODE (BITAND (CV.ksppstvf, 2), 2, 'TRUE', 'FALSE') isadjusted,
i.ksppdesc description
FROM sys.x$ksppi i, sys.x$ksppcv CV
WHERE i.inst_id = USERENV ('Instance')
AND CV.inst_id = USERENV ('Instance')
AND i.indx = CV.indx
AND i.ksppinm LIKE '/_%' ESCAPE '/'
ORDER BY REPLACE (i.ksppinm, '_', '');
10g
cd
du
find
help
ls
lsct
lsdg
mkalias
mkdir
pwd
rm
rmalias
11g
md_backup, md_restore
lsattr, setattr
cd, cp, du, find, help, ls, lsct, lsdg, lsof, mkalias
mkdir, pwd, rm, rmalias
chdg, chkdg, dropdg, iostat, lsdsk, lsod, mkdg, mount
offline, online, rebal, remap, umount
dsget, dsset, lsop, shutdown, spbackup, spcopy, spget
spmove, spset, startup
chtmpl, lstmpl, mktmpl, rmtmpl
chgrp, chmod, chown, groups, grpmod, lsgrp, lspwusr, lsusr
mkgrp, mkusr, orapwusr, passwd, rmgrp, rmusr
volcreate, voldelete, voldisable, volenable, volinfo
volresize, volset, volstat
12c
md_backup, md_restore
amdu_extract
lsattr, setattr
audcleanaudittrail, audclearproperty, audcleartimestamp
audcreatejob, auddropjob, audloaduniauditfiles, audsetdebug
audsetjobinterval, audsetjobstatus, audsetproperty, audsettimestamp
audsettraillocation, audshowtimestamp, lsaudcleanevents
lsaudcleanupjobs, lsaudconfigparams
cd, cp, du, find, help, ls, lsct, lsdg, lsof, mkalias
mkdir, pwd, rm, rmalias, showclustermode, showclusterstate
showpatches, showversion
mapau, mapextent
chdg, chkdg, dropdg, iostat, lsdsk, lsod, mkdg, mount
offline, online, rebal, remap, umount
pwcopy, pwcreate, pwdelete, pwget, pwmove, pwset
afd_configure, afd_deconfigure, afd_dsget, afd_dsset
afd_filter, afd_label, afd_lsdsk, afd_scan, afd_state
afd_unlabel, dsget, dsset, lsop, mkcc, rmcc, shutdown
spbackup, spcopy, spget, spmove, spset, startup
chtmpl, lstmpl, mktmpl, rmtmpl
chgrp, chmod, chown, groups, grpmod, lsgrp, lspwusr, lsusr
mkgrp, mkusr, orapwusr, passwd, rmgrp, rmusr, rpusr
volcreate, voldelete, voldisable, volenable, volinfo
volresize, volset, volstat
md_backup backup_file [-G diskgroup [,diskgroup,...]]
例
ASMCMD [+] > md_backup /tmp/dgbackup20090716
ASMCMD [+] > md_backup /tmp/dgbackup20090716 -G DATA,FRA
md_restore backup_file [--silent][--full|--nodg--newdg -o 'old_diskgroup:new_diskgroup [,...]'][-S sql_script_file] [-G 'diskgroup [,diskgroup...]']
例
ASMCMD [+] > md_restore --full -G data --silent /tmp/dgbackup20090716
ASMCMD [+] > md_restore --nodg -G data --silent /tmp/dgbackup20090716
ASMCMD> lsattr -l -G asmca
Name Value
access_control.enabled FALSE
access_control.umask 066
au_size 1048576
cell.smart_scan_capable FALSE
compatible.asm 11.2.0.0.0
compatible.rdbms 10.1.0.0.0
disk_repair_time 3.6h
sector_size 512
setattr -G asmca compatible.rdbms 11.2.0.0.0
等同于
ALTER DISKGROUP ASMCA SET ATTRIBUTE 'compatible.rdbms' = '11.2.0.0.0'
注意,只能往高改,可在线改
ASMCMD> setattr -G asmca disk_repair_time 5.0h
ASMCMD> lsattr -l -G asmca
Name Value
access_control.enabled FALSE
access_control.umask 066
au_size 1048576
cell.smart_scan_capable FALSE
compatible.asm 11.2.0.0.0
compatible.rdbms 11.2.0.0.0
disk_repair_time 5.0h
sector_size 512
ASMCMD [+] > mount -f data
ASMCMD [+] > mount --restrict data
ASMCMD [+] > mount -a
ASMCMD [+] > umount -a
ASMCMD [+] > umount -f DATA
ASMCMD [+] > rebal --power 4 FRA
相当于 ALTER DISKGROUP fra REBALANCE POWER 4
ASMCMD [+] > lsop
Group_Name Operation State Power
FRA REBAL RUN 4
8.find
asmcmd find --type controlfile + "*"
ASMCMD> find / undo*
+asmca/open/datafile/UNDOTBS1.258.776215267
+asmca/open/datafile/UNDOTBS2.264.776215457
9.mkalias
mkalias +DATA/ASM/DATAFILE/USERS.259.899216077 users01.dbf
1.asmcmd里的cp
unix里面的cp用法一致,但只针对oracle文件(数据文件,日志文件,控制文件,参数文件)包括数据泵出文件以及增量trace文件,如果使用acfs,可以支持各种文件。
2.DBMS_FILE_TRANSFER
(2.1)本地拷贝
DBMS_FILE_TRANSFER.COPY_FILE(
source_directory_object IN VARCHAR2,
source_file_name IN VARCHAR2,
destination_directory_object IN VARCHAR2,
destination_file_name IN VARCHAR2);
案例
SQL> create directory DGROUP as '+diskgroup1/dbs/backup';
Directory created.
SQL> BEGIN
2 DBMS_FILE_TRANSFER.COPY_FILE('SOURCEDIR','t_xdbtmp.f', 'DGROUP', 't_xdbtmp.f');
3 END;
4 /
PL/SQL procedure successfully completed.
SQL> EXIT
$ASMCMD
ASMCMD> ls
DISKGROUP1/
ASMCMD> cd diskgroup1/dbs/backup
ASMCMD> ls
t_xdbtmp.f => +DISKGROUP1/ORCL/TEMPFILE/COPY_FILE.267.546546525
DBMS_FILE_TRANSFER.GET_FILE
source_directory_object IN VARCHAR2,
source_file_name IN VARCHAR2,
source_database IN VARCHAR2,
destination_directory_object IN VARCHAR2,
destination_file_name IN VARCHAR2);
案例
CREATE OR REPLACE DIRECTORY df AS '+datafile' ;
GRANT WRITE ON DIRECTORY df TO "user";
CREATE DIRECTORY DSK_FILES AS ''^t_work^'';
GRANT WRITE ON DIRECTORY dsk_files TO "user";
-- asumes that dbs2 link has been created and we are connected to the instance.
-- dbs2 could be a loopback or point to another instance.
BEGIN
-- asm file to an os file
-- get an asm file from dbs1.asm/a1 to dbs2.^t_work^/oa5.dat
DBMS_FILE_TRANSFER.GET_FILE ( 'df' , 'a1' , 'dbs1', 'dsk_files' , 'oa5.dat' );
-- os file to an os file
-- get an os file from dbs1.^t_work^/a2.dat to dbs2.^t_work^/a2back.dat
DBMS_FILE_TRANSFER.GET_FILE ( 'dsk_files' , 'a2.dat' , 'dbs1', 'dsk_files' , 'a2back.dat' );
END ;
/
DBMS_FILE_TRANSFER.PUT_FILE(
source_directory_object IN VARCHAR2,
source_file_name IN VARCHAR2,
destination_directory_object IN VARCHAR2,
destination_file_name IN VARCHAR2,
destination_database IN VARCHAR2);
CREATE OR REPLACE DIRECTORY df AS '+datafile' ;
GRANT WRITE ON DIRECTORY df TO "user";
CREATE OR REPLACE DIRECTORY ft1 AS '+datafile/ft1' ;
GRANT READ,WRITE ON DIRECTORY ft1 TO "user";
CREATE OR REPLACE DIRECTORY ft1_1 AS '+datafile/ft1/ft1_1' ;
CONNECT user;
Enter password: password
-- - put a1.dat to a4.dat (using dbs2 dblink)
-- - level 2 sub dir to parent dir
-- - user has read privs on ft1_1 at dbs1 and write on df in dbs2
BEGIN
DBMS_FILE_TRANSFER.PUT_FILE ( 'ft1_1' , 'a2.dat' , 'df' , 'a4.dat' , 'dbs2' ) ;
END ;
/
Make sure that XML DB is installed. To check if installed issue the desc resource_view as SQL prompts. The output in Oracle 11gR2 is displayed below. If the object does not exist XML DB must be installed. If XML DB is installed continue.
SQL> desc resource_view
Name Null? Type
—————————————– ——– —————————-
RES XMLTYPE(XMLSchema “http://xmlns.oracle.com/xdb/XDBResource.xsd” Element “Resource”)
ANY_PATH VARCHAR2(4000)
RESID RAW(16)
SQL>
Check if http and ftp ports are set
SQL> SELECT dbms_xdb.gethttpport FROM dual;
GETHTTPPORT
———–
0
SQL> SELECT dbms_xdb.getftpport FROM dual;
GETFTPPORT
———-
0
SQL>
Set the port if not already set.
SQL> exec dbms_xdb.sethttpport(8080);
PL/SQL procedure successfully completed.
SQL>
SQL> exec dbms_xdb.setftpport(2100);
PL/SQL procedure successfully completed.
SQL>
Verify the ports.
SQL> SELECT dbms_xdb.getftpport FROM dual;
GETFTPPORT
———-
2100
SQL> SELECT dbms_xdb.gethttpport FROM dual;
GETHTTPPORT
———–
8080
SQL>
If XML DB is installed an ASM virtual folder is created in /sys and is names /sys/asm. XML DB provides access via ftp or http using the hostname where the database is installed and the respective ftp or http port.
FTP
Example on Windows (database on windows non ASM storage): As this is non ASM based database /sys/asm folder is empty.
E:\app\Administrator\product\11.1.0\db_3>ftp -n
ftp> open userpc 2100
Connected to userpc.gj.com.
220- userpc
Unauthorised use of this FTP server is prohibited and may be subject to civil and criminal prosecution.
220 userpc FTP Server (Oracle XML DB/Oracle Database) ready.
ftp> user system
331 pass required for SYSTEM
Password:
230 SYSTEM logged in
ftp>
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
OLAP_XDS
home
images
olap_data_security
public
sys
xdbconfig.xml
226 ASCII Transfer Complete
ftp: 72 bytes received in 0.10Seconds 0.73Kbytes/sec.
ftp> cd sys
250 CWD Command successful
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
acloids
acls
apps
asm
databaseSummary.xml
log
oid
principals
schemas
version
workspaces
xs
226 ASCII Transfer Complete
ftp: 103 bytes received in 0.00Seconds 103000.00Kbytes/sec.
ftp> cd asm
250 CWD Command successful
例1
sqlplus / as sysasm
create diskgroup dgroup_01 external redundancy
disk '/devices/disks/c*';
例2
sqlplus / as sysasm
create diskgroup DATADG external redundancy
disk '/dev/asm-diskb'
ATTRIBUTE 'compatible.rdbms' = '11.2','compatible.asm' = '11.2';
su - grid
sqlplus / as sysasm
alter diskgroup 磁盘组的名字 add disk '/dev/rhdisk5' rebalance power 5;
或者 alter diskgroup 磁盘组的名字 add disk '/dev/rhdisk5' named DISK5,add disk '/dev/rhdisk6' named DISK6;
3.给磁盘组删盘
su - grid
sqlplus / as sysasm
alter diskgroup drop disk data_01;
4.撤销删除动作
su - grid
sqlplus / as sysasm
alter diskgroup data undrop disk;
5.修改asm磁盘大小
*asm中的磁盘也可以resize,需要注意:增大磁盘大小要确定对应的裸卷具有足够空间,减少空间要确保剩余的空间足以存放数据量大小,否则会报错
例:
alter diskgroup data resize disk data_01 size 1024m;
6.rebalance
ALTER DISKGROUP fra REBALANCE POWER 4
alter diskgroup data drop disk DATA_0000 rebalance power 3;
power代表并行度,值越大rebalance越快,但占用资源越多
power:0~11 , 0代表不做 rebalance
11.2.0.2 版本上限为 1024
查看rebalance进度
select operation,state,power,actual,sofar,est_work,est_minutes from v$asm_operation;
快速rebalance方法
sqlplus / as sysasm
startup restrict;
alter diskgroup dgext11gasm mount restricted;
alter diskgroup dgext11gasm rebalance power 10;
shutdown immediate;
startup
alter diskgroup data mount/unmount
*以上操作只在当前实例挂载磁盘组,如果想每个实例都挂载,需要分别在各个实例中执行!
alter diskgroup all mount/dismount
挂载/卸载所有的磁盘组。
8.删磁盘组(drop diskgroup)
drop diskgroup data
*需要磁盘组mount状态,对于多节点的diskgroup,只能在一个asm实例上挂载之后才能被drop,其他节点必须dismount。
另:drop diskgroup data including contents;
9.disk online
alter diskgroup DATA online disk 'diskname';
或者:alter diskgroup DATA online all;
10.磁盘组的属性调整
alter diskgroup data set attribute 'DISK_REPAIR_TIME'='12h';
11.文件别名操作
加别名
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';
改别名
ALTER DISKGROUP disk_group_1 RENAME ALIAS '+disk_group_1/my_dir/my_file.dbf' TO '+disk_group_1/my_dir/my_file2.dbf';
删别名
ALTER DISKGROUP disk_group_1 DELETE ALIAS '+disk_group_1/my_dir/my_file.dbf';
删文件
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';
EXTERNAL means allow the underlying physical disk array do the mirroring
NORMAL means ASM will create one additional copy of an extent for redundancy
HIGH means ASM will create two additional copies of an extent for redundancy
由于使用extent进行冗余,这种特性允许各 failure group总容量可以不一致
要改变冗余度,需要新建磁盘组
USABALE_FILE_MB = (FREE_MB - REQUIRED_MIRROR_FREE_MB) / 2
sqlplus / as asmsys
CREATE DISKGROUP data1 NORMAL REDUNDANCY
FAILGROUP data1f1 DISK
'/dev/fg11' name f1d1,
'/dev/fg12' name f1d2
FAILGROUP data1f2 DISK
'/dev/fg21' name f2d1,
'/dev/fg22' name f2d2
ATTRIBUTE 'compatible.asm' = '11.2';
CREATE DISKGROUP data2 NORMAL REDUNDANCY
FAILGROUP data2f1 DISK
'/dev/fg13' name f3d1,
'/dev/fg14' name f3d2
FAILGROUP data2f2 DISK
'/dev/fg23' name f4d1,
'/dev/fg24' name f4d2
ATTRIBUTE 'compatible.asm' = '11.2';
3.给磁盘组加盘
alter diskgroup DATA1 add failgourp data1f2 disk '/dev/fg21' name data1f2;
*如果磁盘有盘头信息时加入会报错
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15033: disk '/dev/fg21' belongs to diskgroup "DATA1"
此时可以用force选项加盘,但注意会清掉磁盘头
alter diskgroup data1 add failgroup data1f2 disk '/dev/fg21' name data1f2 force;
alter system set ASM_PREFERRED_READ_FAILURE_GROUPS='DATA.FG01' sid='ORCL1';
alter system set ASM_PREFERRED_READ_FAILURE_GROUPS='DATA.FG01' sid='ORCL2';
alter system set ASM_PREFERRED_READ_FAILURE_GROUPS='DATA.FG02' sid='ORCL3';
则每个实例优先读本地存储,适合 extend rac情况
1.asmlib 的下载地址
http://www.oracle.com/technetwork/server-storage/linux/downloads/index-088143.html
http://www.oracle.com/technetwork/server-storage/linux/asmlib/index-101839.html
参考文档
http://www.askmaclean.com/archives/why-asmlib-and-why-not.html
ASMLIB是一种基于Linux module,专门为Oracle Automatic Storage Management特性设计的内核支持库(kernel support library)。
长久以来我们对ASMLIB的认识并不全面,这里我们来具体了解一下使用ASMLIB的优缺点。
理论上我们可以从ASMLIB API中得到的以下益处:
虽然从理论上我们可以从ASMLIB中得到性能收益,但实践过程中这种优势是几乎可以忽略的,没有任何性能报告显示ASMLIB对比Linux上原生态的udev设备管理服务有任何性能上的优势。在Oracle官方论坛上有一篇
ASMLIB可能带来的缺点:
结论:
尽可能不要使用ASMLIB,所以本章节不介绍如何安装asmlib,只介绍如何使用其命令。
asmlib安装之后,会在/usr/sbin/下生成oracleasm命令(或者位于/etc/init.d/oracleasm),该命令由root用户执行,有以下参数
oracleasm -h
Usage: oracleasm [--exec-path=
oracleasm --exec-path
oracleasm -h
oracleasm -V
The basic oracleasm commands are:
configure Configure the Oracle Linux ASMLib driver
init Load and initialize the ASMLib driver
exit Stop the ASMLib driver
scandisks Scan the system for Oracle ASMLib disks
status Display the status of the Oracle ASMLib driver
listdisks List known Oracle ASMLib disks
querydisk Determine if a disk belongs to Oracle ASMlib
createdisk Allocate a device for Oracle ASMLib use
deletedisk Return a device to the operating system
renamedisk Change the label of an Oracle ASMlib disk
update-driver Download the latest ASMLib driver
/etc/init.d/oracleasm configure (这里需要输入oracle用户和dba组,所以需要先创建好。)
/etc/init.d/oracleasm enable
/etc/init.d/oracleasm createdisk VOL1 /dev/sdb1
/etc/init.d/oracleasm createdisk VOL2 /dev/sdc1
/etc/init.d/oracleasm createdisk VOL3 /dev/sdd1
获取磁盘变化:/etc/init.d/oracleasm scandisks
/etc/init.d/oracleasm deletedisk VOL1
/etc/init.d/oracleasm deletedisk VOL2
/etc/init.d/oracleasm deletedisk VOL3
获取磁盘变化:/etc/init.d/oracleasm scandisks
/etc/init.d/oracleasm listdisks
结果类似
[root@rac1 ~]# /etc/init.d/oracleasm listdisks
ASMDATA
ASMDATA2
CRSVOL
smlib创建完磁盘后,会在/dev/oracleasm/disks下放置设备文件
ls -l /dev/oracleasm/disks
[root@rac1 disks]# ll
total 0
brw-rw---- 1 grid asmadmin 8, 33 Jul 12 19:08 ASMDATA
brw-rw---- 1 grid asmadmin 8, 49 Jul 12 19:08 ASMDATA2
brw-rw---- 1 grid asmadmin 8, 17 Jul 12 19:08 CRSVOL
通过主次号可以与/dev下的设备号找到对应关系,也可以通过如下命令查看
/etc/init.d/oracleasm querydisk -d ASMDATA
或者直接进入/dev/oracleasm/disks,查看所有设备对应关系
cd /dev/oracleasm/disks
/etc/init.d/oracleasm querydisk -d *
Disk "ASMDATA" is a valid ASM disk on device /dev/sdc1[8,33]
Disk "ASMDATA2" is a valid ASM disk on device /dev/sdd1[8,49]
Disk "CRSVOL" is a valid ASM disk on device /dev/sdb1[8,17]
也可以通过原设备号查看asmlib设备名
/etc/init.d/oracleasm querydisk -d /dev/sdc1
Device "/dev/sdc1" is marked an ASM disk with the label "ASMDATA"
重命名磁盘一般在遇到误delete磁盘,或者asmlib盘头被清的情况
在修复盘头后,执行如下命令
/etc/init.d/oracleasm force-renamedisk /dev/sdbg1
/etc/init.d/oracleasm scandisks
/etc/init.d/oracleasm listdisks
kfod disks=all
kfod disks=all status=true
如果是 11g 以上
kfod disks=all status=true dscvgroup=true
12c 有新增参数,显示结果最全
kfod disks=all status=true dscvgroup=true name=true asm_diskstring=/dev/data*,/dev/crs*
amdu是11g自带抽取asm磁盘中文件的工具,10g如果想使用,参考文档:Placeholder for AMDU binaries and using with ASM 10g [ID 553639.1]
使用amdu -h 查看所有参数解释
amdu用来从无法启动的磁盘组里抽取文件,但需要知道文件的号码
( 1-255 是 asm元文件,数据库文件均从 256 后开始)
amdu -diskstring '/dev/raw/raw*' -dump 'DATA'
cd amdu_2012_03_05_03_19_38/
strings DATA_0001.img |grep DATAFILE
恢复数据文件
amdu -diskstring '/dev/raw/raw*' -extract 'DATA.259'
--extrace spfile
amdu -dis '/dev/sd*' -extract data1.265 -output spfile.ora
--extrace controlfile
amdu -dis '/dev/sd*' -nodir -norep -extract data1.260 -output control01.ctl
--extract datafile
amdu -dis '/dev/sd*' -nodir -norep -extract data1.256 -output system01.dbf
amdu -dis '/dev/sd*' -nodir -norep -extract data1.257 -output sysaux01.dbf
amdu -dis '/dev/sd*' -nodir -norep -extract data1.258 -output undotbs01.dbf
amdu -dis '/dev/sd*' -nodir -norep -extract data1.259 -output users01.dbf
--extract redo logfile
amdu -dis '/dev/sd*' -nodir -norep -extract data1.261 -output redo01.log
amdu -dis '/dev/sd*' -nodir -norep -extract data1.262 -output redo02.log
amdu -dis '/dev/sd*' -nodir -norep -extract data1.263 -output redo03.log
kfed是用来编辑asm数据块的工具(主要是读取信息),也可以用来写数据块。
Oracle 10g中,需要编译,方法为
make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk ikfed
在Oracle 11g中,kfed默认已被编译
典型命令语法:
kfed read /dev/raw/raw1 aunum=0 blknum=0 ausz=1048576 text=raw1.txt
含义为:读取裸盘/dev/raw/raw1,第一个au的第一号块(每块4k),au大小为1m,结果输出到raw1.txt文件中。
如果只读取盘头块,上一个命令可缩写成(不输入aunum及blknum时默认读取aunum=0及blknum=0块)
kfed read /dev/raw/raw1 text=raw1.txt
数据块类型详见2.2
kfed find /dev/data cnt=1024 type=1 ausz=1048576
ausize=`kfed read /dev/data | grep ausize | tr -s ' ' | cut -d' ' -f2`
blksize=`kfed read /dev/data | grep blksize | tr -s ' ' | cut -d' ' -f2`
let n=$ausize/$blksize
for (( i=2; i<$n; i++ ))
do
kfed read /dev/data blkn=$i | grep KFBTYP
done
不能有任何这样的行
kfbh.type=KFBTYP_INVALID
kfed find /dev/data cnt=1024 type=0 ausz=1048576
kfed read /dev/raw/raw1 aunum=0 blknum=0 ausz=1048576
读取的磁盘头信息
oracle 10.2.0.5以后会自动备份盘头
使用kfed方法备份盘头
kfed read /dev/raw/raw1 text=raw1.txt
dd if=/dev/raw/raw1 of=/tmp/asmheader bs=4096 count=1
磁盘头损坏特指磁盘头前4096字节信息的损坏,如果损坏面积较大,即使恢复头信息,也无法挂载磁盘组。
本小结案例只涉及数据盘组的盘头损坏,并不包含11.2之后的crs盘组盘头损坏。
可通过如下命令扫描磁盘,简单确认里面是否有数据
linux系统
dd if=/dev/data1 bs=4096|hexdump -C
aix系统
dd if=/dev/data1 bs=4096|od -x
从10.2.0.5开始,ASM磁盘头开始有自动备份,头块(4096字节)会自动备份到 AU#1的倒数第二个 block
执行下面的命令查看 ASM disk header 备份信息,备份信息与 ASM disk header 信息完全一致:
kfed read /dev/rhdisk3 AUNUM=1 BLKNUM=254 ausz=1048576 | more
如果算上 aunum=0 的 256块,该块位于整个盘头部第 256+254=510 块
kfed read /dev/rhdisk3 blkn=510 | grep kfbh.type
通过如下命令可查找磁盘头的块号
kfed find /dev/data cnt=1024 type=1ausz=1048576
案例
Block 0 has type 1
Block 510 has type 1
Block 2816 has type 1 (从12c开始有 2个备份块)
以下为各种AU大小环境中,备份块所在位置
AU SIZE:1M: 备份块 :510
AU SIZE:2M: 备份块 :1022
AU SIZE:4M: 备份块 :2046
AU SIZE:8M: 备份块 :4094
AU SIZE:16M: 备份块 :8190
AU SIZE:32M: 备份块 :16382
AU SIZE:64M: 备份块 :32766
使用如下命令可以将自动备份的头块信息写回头部
kfed repair /dev/raw/raw1
(1.2)有手工备份的盘头信息恢复
a.当使用
kfed read /dev/raw/raw1 text=raw1.txt
方式备份时,恢复用如下命令
kfed merge /dev/raw/raw1 text=raw1.txt
dd if=/dev/raw/raw1 of=/tmp/asmheader bs=4096 count=1
方式备份时,恢复用如下命令
dd if=/tmp/asmheader of= /dev/raw/raw1 bs=4096 count=1
磁盘信息主要来源于disk directory(asm的2号文件),以下为确认disk directory位置的3种方式
file directory(asm的1号文件)可以定位所有元数据文件,而file directory的位置指针,是盘头kfdhdb.f1b1locn的值,同一个磁盘组中,只有一块磁盘的kfdhdb.f1b1locn是非零值,该值代表了保存file directory信息的AU号码(位于本磁盘)。AU的第一个块(0号块)是KFBTYP_LISTHEAD,从第二个块(1号块)开始每个块都是一个元文件的位置信息(元文件号码对应信息详见2.1)。
比如假定当前盘的kfdhdb.f1b1locn值为2:
kfed read /dev/data1 aunum=2 blknum=1 --读取1号文件(file directory)文件位置信息,内容节选如下
kfbh.type: |
4 ; 0x002: KFBTYP_FILEDIR |
kfbh.datfmt: |
1 ; 0x003: 0x01 |
kfbh.block.blk: |
1 ; 0x004: blk=1 |
kfbh.block.obj: |
1 ; 0x008: file=1 |
|
|
......省略 |
|
kfffde[0].xptr.au: |
2 ; 0x4a0: 0x00000002 |
kfffde[0].xptr.disk: |
0 ; 0x4a4: 0x0000 |
kfffde[0].xptr.flags: |
0 ; 0x4a6: L=0 E=0 D=0 S=0 |
kfffde[0].xptr.chk: |
40 ; 0x4a7: 0x28 |
kfffde[1].xptr.au: |
21 ; 0x4a8: 0x00000015 |
kfffde[1].xptr.disk: |
1 ; 0x4ac: 0x0001 |
blk=1 代表1号asm文件,au及disk代表了file directory 位于0号磁盘的2号au上。
同样道理,我们要查看disk directory的内容,需要找到2号文件:
kfed read /dev/data1 aunum=2 blknum=2
内容类似如下:
kfbh.type: |
4 ; 0x002: KFBTYP_FILEDIR |
kfbh.datfmt: |
1 ; 0x003: 0x01 |
kfbh.block.blk: |
2 ; 0x004: blk=2 |
kfbh.block.obj: |
1 ; 0x008: file=1 |
|
|
......省略 |
|
kfffde[0].xptr.au: |
2 ; 0x4a0: 0x00000002 |
kfffde[0].xptr.disk: |
2 ; 0x4a4: 0x0002 |
kfffde[0].xptr.flags: |
0 ; 0x4a6: L=0 E=0 D=0 S=0 |
kfffde[0].xptr.chk: |
42 ; 0x4a7: 0x2a |
可见2号文件(disk directory)位于2号磁盘的第2个au上
当kfdhdb.f1b1locn所在盘头损坏,无法定位file directory时,可通过如下命令扫描所有磁盘,找到disk directory
kfed find /dev/data1 cnt=50 type=6 ausz=1048576
amdu -diskstring '/dev/data*' -dump 'DATA'
cd amdu_*
grep F00000002 DATA.map
内容类似
N0003 D0002 R00 A00000002 F00000002 I0 E00000000 U00 C00256 S0001 B0045105152
其中D0002代表2号磁盘,A00000002代表2号au
找到disk directory的位置后,通过如下命令来确认磁盘信息
kfed read /dev/data3 aunum=2 blknum=0
节选信息如下:
kfbh.endian: |
1 ; 0x000: 0x01 |
kfbh.hard: |
130 ; 0x001: 0x82 |
kfbh.type: |
6 ; 0x002: KFBTYP_DISKDIR |
kfbh.datfmt: |
1 ; 0x003: 0x01 |
kfbh.block.blk: |
0 ; 0x004: blk=0 |
kfbh.block.obj: |
2 ; 0x008: file=2 |
|
|
......省略 |
|
kfddde[0].dsknum: |
0 ; 0x034: 0x0000 |
kfddde[0].state: |
2 ; 0x036: KFDSTA_NORMAL |
kfddde[0].ddchgfl: |
132 ; 0x037: 0x84 |
kfddde[0].dskname: |
DATA_0000 ; 0x038: length=9 |
kfddde[0].fgname: |
DATA_0000 ; 0x058: length=9 |
kfddde[0].crestmp.hi: |
33026794 ; 0x078: HOUR=0xa DAYS=0x17 MNTH=0xc YEAR=0x7df |
kfddde[0].crestmp.lo: |
3914748928 ; 0x07c: USEC=0x0 MSEC=0x195 SECS=0x15 MINS=0x3a |
kfddde[0].failstmp.hi: |
0 ; 0x080: HOUR=0x0 DAYS=0x0 MNTH=0x0 YEAR=0x0 |
kfddde[0].failstmp.lo: |
0 ; 0x084: USEC=0x0 MSEC=0x0 SECS=0x0 MINS=0x0 |
kfddde[0].timer: |
0 ; 0x088: 0x00000000 |
kfddde[0].size: |
5114 ; 0x08c: 0x000013fa |
|
|
......省略 |
|
kfddde[1].dsknum: |
1 ; 0x1f4: 0x0001 |
kfddde[1].state: |
2 ; 0x1f6: KFDSTA_NORMAL |
kfddde[1].ddchgfl: |
132 ; 0x1f7: 0x84 |
kfddde[1].dskname: |
DATA_0001 ; 0x1f8: length=9 |
kfddde[1].fgname: |
DATA_0001 ; 0x218: length=9 |
kfddde[1].crestmp.hi: |
33026794 ; 0x238: HOUR=0xa DAYS=0x17 MNTH=0xc YEAR=0x7df |
kfddde[1].crestmp.lo: |
3914748928 ; 0x23c: USEC=0x0 MSEC=0x195 SECS=0x15 MINS=0x3a |
kfddde[1].failstmp.hi: |
0 ; 0x240: HOUR=0x0 DAYS=0x0 MNTH=0x0 YEAR=0x0 |
kfddde[1].failstmp.lo: |
0 ; 0x244: USEC=0x0 MSEC=0x0 SECS=0x0 MINS=0x0 |
kfddde[1].timer: |
0 ; 0x248: 0x00000000 |
kfddde[1].size: |
5114 ; 0x24c: 0x000013fa |
|
|
......省略 |
|
kfddde[2].dsknum: |
2 ; 0x3b4: 0x0002 |
kfddde[2].state: |
2 ; 0x3b6: KFDSTA_NORMAL |
kfddde[2].ddchgfl: |
132 ; 0x3b7: 0x84 |
kfddde[2].dskname: |
DATA_0002 ; 0x3b8: length=9 |
kfddde[2].fgname: |
DATA_0002 ; 0x3d8: length=9 |
kfddde[2].crestmp.hi: |
33026794 ; 0x3f8: HOUR=0xa DAYS=0x17 MNTH=0xc YEAR=0x7df |
kfddde[2].crestmp.lo: |
3914748928 ; 0x3fc: USEC=0x0 MSEC=0x195 SECS=0x15 MINS=0x3a |
kfddde[2].failstmp.hi: |
0 ; 0x400: HOUR=0x0 DAYS=0x0 MNTH=0x0 YEAR=0x0 |
kfddde[2].failstmp.lo: |
0 ; 0x404: USEC=0x0 MSEC=0x0 SECS=0x0 MINS=0x0 |
kfddde[2].timer: |
0 ; 0x408: 0x00000000 |
kfddde[2].size: |
5114 ; 0x40c: 0x000013fa |
可见该block里含有所有磁盘的信息。
如果包含kfdhdb.f1b1locn值的盘头信息被清,可按默认au=2去直接查看,一般file directory位于2号au里。
如果同一磁盘组有其他磁盘是比较理想情况,读取盘头信息根据a中搜索到的本磁盘信息加以调整即可。如果没有其他磁盘,则可以按照下面给出的盘头模板,结合a中 搜索到的信息调整。
注意:有kfdhdb.f1b1locn的盘头需要指定该值
另:如果使用了asmlib,还需要修改kfdhdb.driver.provstr,并做如下操作
/etc/init.d/oracleasm force-renamedisk /dev/sdbg1
/etc/init.d/oracleasm scandisks
/etc/init.d/oracleasm listdisks
现象:
后台alert显示错误信息类似
ORA-15032: not all alterations performed
ORA-15020: discovered duplicate ASM disk "DATA_0000"
处理方法:
由于错误是发现有重复盘名的磁盘,首先需要扫描所有磁盘,确认重名磁盘,方法可以参考(扫描磁盘,读取ASM磁盘组及磁盘信息)
确认重复命名的磁盘后,将未使用的那块磁盘头部清除(注意:不要清理已用盘头,造成磁盘组无法挂载)
命令类似如下
dd if=/dev/zero of=/dev/rhdiskxx bs=4096 count=1
2.ORA-15063 磁盘组无法挂载
现象:
该报错问题案例如下:
ORA-15032: not all alterations performed
ORA-15063: ASM discovered an insufficient number of disks for diskgroup "DG_U1RSB1_000"
原因可能为初始化参数asm_diskstring值为空
解决方法举例:
ALTER SYSTEM SET asm_diskstring='/dev/vx/rdsk/oradata122/*','/dev/vx/rdmp/emc*' scope=both sid='+ASM1';
3.AIX系统中,在有pvid的盘上创建磁盘组的处理
aix系统中的磁盘,pvid存在两个位置,一是磁盘头,占4k大小(和asm磁盘头大小一致),二是odm( Object Data Manager )中。
如果在已属于磁盘组的裸盘上创建pvid,则只能通过恢复盘头来处理
如果在已有pvid的裸盘上创建磁盘组,会破坏pvid,但odm里还存有pvid信息,一旦主机重启,会还原pvid,造成ASM磁盘组无法mount,需要通过以下方式处理
此方法需要rebalance,但可在线做
1、禁止重启任何节点
2、从磁盘组里删掉磁盘
3、清除pvid
chdev -l hdisk5 -a pv=clear
在所有节点都执行,之后执行lspv,看是否有pvid
4、把磁盘加回磁盘组
该方法需要停机时间
1、备份磁盘头
dd if=/dev/rhdisk5 of=/tmp/d5.txt bs=1024 count=1024
2、停asm实例(每个节点)
3、清pvid
chdev -l hdisk5 -a pv=clear
在所有节点都执行,之后执行lspv,看是否有pvid
4、启动asm实例,mount磁盘组
4.11g crs磁盘组被破坏
参考文档
How to Restore ASM Based OCR After Complete Loss of the CRS Diskgroup on Linux/Unix Systems (文档 ID 1062983.1)
1. Locate the latest automatic OCR backup
$ ls -lrt $CRS_HOME/cdata/rac_cluster1/
2. Make sure the Grid Infrastructure is shutdown on all nodes
# $CRS_HOME/bin/crsctl stop crs -f
3. Start the CRS stack in exclusive mode
11.2.0.1:
# $CRS_HOME/bin/crsctl start crs -excl
11.2.0.2 and above:
# $CRS_HOME/bin/crsctl start crs -excl -nocrs
4. Create the CRS diskgroup via sqlplus
create diskgroup CRS external redundancy disk 'ORCL:ASMD40' attribute 'COMPATIBLE.ASM' = '11.2';
5. Restore the latest OCR backup
# cd $CRS_HOME/cdata/rac_cluster1/
# $CRS_HOME/bin/ocrconfig -restore backup00.ocr
6. Start the CRS daemon on the current node (11.2.0.1 only !)
# $CRS_HOME/bin/crsctl start res ora.crsd -init
7. Recreate the Voting file
# $CRS_HOME/bin/crsctl replace votedisk +CRS
8. Recreate the SPFILE for ASM (optional)
Prepare a pfile (e.g. /tmp/asm_pfile.ora)
*.asm_power_limit=1
*.diagnostic_dest='/u01/app/oragrid'
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='EXCLUSIVE'
Now the SPFILE can be created using this PFILE:
$ sqlplus / as sysasm
SQL*Plus: Release 11.2.0.1.0 Production on Tue Mar 30 11:52:39 2010
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Real Application Clusters and Automatic Storage Management options
SQL> create spfile='+CRS' from pfile='/tmp/asm_pfile.ora';
9. Shutdown CRS
Since CRS is running in exclusive mode, it needs to be shutdown to allow CRS to run on all nodes again. Use of the force (-f) option may be required:
# $CRS_HOME/bin/crsctl stop crs -f
10. Start CRS
As the root user submit the CRS startup on all cluster nodes:
# $CRS_HOME/bin/crsctl start crs
11. Verify CRS
To verify that CRS is fully functional again:
# $CRS_HOME/bin/crsctl check cluster -all
# $CRS_HOME/bin/crsctl status resource -t