① ASM文件转化

以创建的asmtest表空间为例

㈠ 将os文件转换为ASM文件

sys@ORCL> create tablespace asmtest datafile size 10m;

Tablespace created.

sys@ORCL> alter tablespace asmtest offline;

Tablespace altered.

[oracle@localhost ~]$ rman target /

RMAN> backup as copy tablespace asmtest format '+DATA';

RMAN> switch tablespace asmtest to copy;

datafile 6 switched to datafile copy "+DATA/orcl/datafile/asmtest.256.798497595"

sys@ORCL> alter tablespace asmtest online;

Tablespace altered.

sys@ORCL> select file_name from dba_data_files where tablespace_name='ASMTEST';

FILE_NAME

----------------------------------------------------------------------------------------------------

+DATA/orcl/datafile/asmtest.256.798497595

ASMCMD> mkalias ASMTEST.256.798497595 asmtest.dbf

ASMCMD> ls -al

Type Redund Striped Time Sys Name

DATAFILE MIRROR COARSE NOV 04 20:00:00 Y +DATA/ORCL/DATAFILE/asmtest.dbf => ASMTEST.256.798497595

N asmtest.dbf => +DATA/ORCL/DATAFILE/ASMTEST.256.798497595

㈡ 将数据文件从一个diskgroup迁移到另一个diskgroup

idle> select file_id from dba_data_files where tablespace_name='ASMTEST';

FILE_ID

----------

6

idle> alter tablespace asmtest offline;

[oracle@localhost ~]$ rman target /

RMAN> backup as copy datafile 6 format '+THINK';

RMAN> switch datafile 6 to copy;

RMAN> recover datafile 6;

RMAN> sql "alter tablespace asmtest online";

ASMCMD> find THINK/ *

+THINK/ORCL/

+THINK/ORCL/DATAFILE/

+THINK/ORCL/DATAFILE/ASMTEST.256.798503425

㈢ 将ASM文件转发成OS文件

sys@ORCL> select file_name from dba_data_files where tablespace_name='ASMTEST';

FILE_NAME

----------------------------------------------------------------------------------------------------

+THINK/orcl/datafile/asmtest.256.798503425

sys@ORCL> alter tablespace asmtest offline;

sys@ORCL> create directory o***c as '/home/oracle';

sys@ORCL> create directory asmsrc as '+THINK/orcl/datafile';

sys@ORCL> begin

2 dbms_file_transfer.copy_file('ASMSRC','ASMTEST.256.798503425','O×××C','ASM.DBF');

3 end;

4 /

PL/SQL procedure successfully completed.

sys@ORCL> alter database rename file '+THINK/orcl/datafile/asmtest.256.798503425' to '/home/oracle/ASM.DBF';

[oracle@localhost ~]$ rman target /

RMAN> recover datafile 6;

RMAN> sql "alter tablespace asmtest online";

sys@ORCL> select file_name from dba_data_files where tablespace_name='ASMTEST';

FILE_NAME

----------------------------------------------------------------------------------------------------

/home/oracle/ASM.DBF

② ASM中的文件名

ASM文件名,诸如:

+THINK/orcl/datafile/asmtest.256.798503425

上述名称的生成格式为:

+diskgroup/dbname/file_type/file_type_tag.file.incarnation

● +diskgroup :磁盘组名称

● dbname :数据库的DB_UNIQUE_NAME参数值

● file_type :创建的文件类型,比如CONTROLFILE/DATAFILE/ONLINELOG/ARCHIVELOG/TEMPFILE/BACKUPSET/FLASHBACK等等

● file_type_tag :文件类型的标签,比如表空间对应的通常为该表空间名称

● file.incarnation :文件序号+incarnation,用来确保文件的唯一

文件创建时无法指定实际文件名及路径,完全由ORACLE的OMF控制和管理

例如:

sys@ORCL> alter tablespace asmtest add datafile '+DATA' size 10m;

Tablespace altered.

如果设置了初始化参数db_create_file_dest,甚至连磁盘组名都不需要写了

其它类型文件,比如重做日志文件等,操作方式都是同理的

但像trace文件、alert文件、dump文件等还不能直接被存储到ASM中

oracle视频教程请关注: