全部博文(389)
分类: Oracle
2013-12-12 19:58:31
ASMCMD的文件操作API
ASMCMD是一个很方便管理ASM工具,可以用来创建,删除文件,其本身是由ASM实例的dbms_diskgroup这个包
来完成的.主要的过程有
dbms_diskgroup.write(:handle,:offset,:length,:buffer);
dbms_diskgroup.read(:handle,:offset,:length,:buffer);
dbms_diskgroup.renamefile(:NAME,:tname,:type,:genfname);
dbms_diskgroup.dropfile(:NAME,:type);
dbms_diskgroup.resizefile(:handle,:fsz);
dbms_diskgroup.abortfile(:handle);
dbms_diskgroup.commitfile(:handle);
dbms_diskgroup.createfile(:NAME,:type,:lblksize,:fsz,:handle,:pblksz,:genfname);
dbms_diskgroup.close(:handle);
dbms_diskgroup.mapextent(:NAME,:xsn,:mapcount,:extsize,:disk1,:au1,:disk2,:au2,:disk3,:au3);
dbms_diskgroup.getfileattr(:NAME,:type,:fsz,:lblksize);
dbms_diskgroup.getfileattr(:NAME,:type,:fsz,:lblksize, 1);
dbms_diskgroup.open(:NAME,:fmode,:type,:lblksize,:handle,:pblksz,:fsz);
dbms_diskgroup.gpnpsetds(:diskstring,:skipdsflag);
dbms_diskgroup.deletevotingfiles(:dgname);
dbms_diskgroup.createvotingfiles(:dgname,:cnt,:vfile1,:vfile2,:vfile3,:vfile4,:vfile5);
dbms_diskgroup.patchfile(:NAME,:type,:lblksize,1,0,:fsz,:fsname,2,1,1);
比如我通过下面的一个过程可以实现查看文件的大小,类型和块大小
SQL> declare ---execute on ASM instance
2 v_type number;
3 v_filesize number;
4 v_lblksize number;
5 begin
6 dbms_diskgroup.getfileattr('+DATA/testasm/datafile/tt.268.833938801',v_type,v_filesize,v_lblksize);
7 dbms_output.put_line('+DATA/testasm/datafile/tt.268.833938801');
8 dbms_output.put_line('type '||v_type);
9 dbms_output.put_line('size '||v_filesize);
10 dbms_output.put_line('lblksize '||v_lblksize);
11 end;
12 /
+DATA/testasm/datafile/tt.268.833938801
type 2
size 131072
lblksize 8192
PL/SQL procedure successfully completed.
SQL> select blocks from v$datafile where name='+DATA/testasm/datafile/tt.268.833938801'; --execute on RDBMS instance
BLOCKS
----------
131072
可以看出两个结果的块数是一样的.
复制文件主要是通过dbms_diskgroup.patchfile过程来完成,比如我现在把+DATA/testasm/datafile/tt.268.833938801文件复制到
/home/oracle/tt.268.833938801这个文件
SQL> declare
2 v_type number;
3 v_filesize number;
4 v_lblksize number;
5 v_handle number;
6 v_pblksz number;
7 v_fsz number;
8 begin
9 dbms_diskgroup.open('+DATA/testasm/datafile/tt.268.833938801','r',2,8192,v_handle,v_pblksz,v_fsz);
10 dbms_output.put_line('open file sucess file,file handle NO. '||v_handle);
11 dbms_output.put_line('physical size '||v_pblksz);
12 dbms_output.put_line('file size ' ||v_fsz);
13 dbms_diskgroup.patchfile('+DATA/testasm/datafile/tt.268.833938801',2,8192,1,0,v_fsz,'/home/oracle/tt.268.833938801',2,1,1);
14 dbms_output.put_line('file copy complete');
15 dbms_diskgroup.close(v_handle);
16 end;
17 /
open file sucess file,file handle NO. 0
physical size 512
file size 131072
file copy complete
PL/SQL procedure successfully completed.
[oracle@asm ~]$ pwd
/home/oracle
[oracle@asm ~]$ ls -l tt*
-rw-r----- 1 oracle oinstall 1073750016 Dec 13 03:49 tt.268.833938801
目前没有很完整的文档来描述这些api,所以得到的资料也比较有限.比如读和写。这里的读和写和数据库直接读写ASM磁盘是不是有某种关联性,
还得进一步了解.