客户遇到个DG的问题,存储使用的ASM管理,有多个磁盘盘。
在主库创建数据文件,备库自己主动创建的数据文件都在同一磁盘组,而且在主库创建数据文件是指定的是类似**.DBF的名字,到备库也变成了使用ASM的数字格式**.266.123456
这是由于使用了OMF特性。
OMF,全称是Oracle_Managed Files,即Oracle文件管理。
使用OMF能够简化管理员的管理工作,不用指定文件的名字、大小、路径,其名字,大小,路径由oracle 自己主动分配。在删除不再使用的日志、数据、控制文件时,OMF也能够自己主动删除其相应的OS文件。
Oracle数据库是否启用OMF特性能够通过查看DB_CREATE_FILE_DEST參数来获得。
当DB_CREATE_FILE_DEST參数值为空时表示未启用OMF功能,设置为文件夹名则是开启OMF。
实验数据库版本号:11.2.0.4.0,
一、启用OMF时的数据文件创建情况
1.主库在指定磁盘组创建数据文件,备库会在DB_CREATE_FILE_DEST=+DG1指定的磁盘组创建
备库參数
SQL> show parameter standby_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_file_management string AUTO
SQL> show parameter DB_CREATE_FILE_DEST
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DG1
SQL> col name for a50
SQL> set linesize 1000
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
1 +DG1/dg2/datafile/system.258.852146097
2 +DG1/dg2/datafile/sysaux.257.852146099
3 +DG1/dg2/datafile/undotbs1.256.852146101
4 +DG1/dg2/datafile/users.259.852146107
5 +DG2/dg/datafile/test1.dbf
主库创建在DG2磁盘组创建表空间:
SQL> col name for a50
SQL> set linesize 1000
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
1 +DG1/dg/datafile/system.260.852134271
2 +DG1/dg/datafile/sysaux.261.852134303
3 +DG1/dg/datafile/undotbs1.262.852134329
4 +DG1/dg/datafile/users.264.852134361
5 +DG2/dg/datafile/test1.dbf
SQL>
create tablespace test2 datafile '+DG2/dg/datafile/test2.dbf' size 10m;
Tablespace created.
SQL> alter system switch logfile;
System altered.
在备份库上查询表空间及数据文件创建情况:在DB_CREATE_FILE_DEST指定的磁盘组+DG1中创建
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
1 +DG1/dg2/datafile/system.258.852146097
2 +DG1/dg2/datafile/sysaux.257.852146099
3 +DG1/dg2/datafile/undotbs1.256.852146101
4 +DG1/dg2/datafile/users.259.852146107
5 +DG2/dg/datafile/test1.dbf
6 +DG1/dg2/datafile/test2.272.852147911
改动备库DB_CREATE_FILE_DEST參数为+DG2:
SQL> SQL> show parameter DB_CREATE_FILE_DEST
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DG2
在主库创建表空间:
SQL> create tablespace test3 datafile
'+DG1/dg/datafile/test3.dbf' size 10m;
Tablespace created.
SQL> alter system switch logfile;
System altered.
在备库查询:
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
1 +DG1/dg2/datafile/system.258.852146097
2 +DG1/dg2/datafile/sysaux.257.852146099
3 +DG1/dg2/datafile/undotbs1.256.852146101
4 +DG1/dg2/datafile/users.259.852146107
5 +DG2/dg/datafile/test1.dbf
6 +DG1/dg2/datafile/test2.272.852147911
7 +DG2/dg2/datafile/test3.260.852148535
二、关闭OMF特性
改动备库DB_CREATE_FILE_DEST參数为空,关闭OMF特性。--我这里仅仅关闭了备库的
SQL> show parameter DB_CREATE_FILE_DEST
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DG2
SQL> alter system set DB_CREATE_FILE_DEST='';
System altered.
SQL> show parameter DB_CREATE_FILE_DEST
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string
主库做操作:
SQL> create tablespace test4 datafile '+DG1/dg/datafile/test4.dbf' size 10m;
Tablespace created.
SQL> create tablespace test5 datafile '+DG2/dg/datafile/test5.dbf' size 10m;
Tablespace created.
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
1 +DG1/dg/datafile/system.260.852134271
2 +DG1/dg/datafile/sysaux.261.852134303
3 +DG1/dg/datafile/undotbs1.262.852134329
4 +DG1/dg/datafile/users.264.852134361
5 +DG2/dg/datafile/test1.dbf
6 +DG2/dg/datafile/test2.dbf
7 +DG1/dg/datafile/test4.dbf
8 +DG2/dg/datafile/test5.dbf
备库做查询:
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
1 +DG1/dg2/datafile/system.258.852146097
2 +DG1/dg2/datafile/sysaux.257.852146099
3 +DG1/dg2/datafile/undotbs1.256.852146101
4 +DG1/dg2/datafile/users.259.852146107
5 +DG2/dg/datafile/test1.dbf
6 +DG1/dg2/datafile/test2.272.852147911
7 +DG1/dg/datafile/test4.dbf
8 +DG2/dg/datafile/test5.dbf
三、观察下ASM磁盘组中对于数据文件别名的存储形式
ASMCMD> ls -al
WARNING:option 'a' is deprecated for 'ls'
please use 'absolutepath'
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y none => SYSAUX.257.852146099
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y none => SYSTEM.258.852146097
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y none => TEST2.272.852147911
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y +DG1/dg/datafile/test4.dbf => TEST4.279.852157365
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y none => UNDOTBS1.256.852146101
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y none => USERS.259.852146107
ASMCMD> ls -al
WARNING:option 'a' is deprecated for 'ls'
please use 'absolutepath'
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y +DG2/dg/datafile/test1.dbf => TEST1.256.852146103
DATAFILE UNPROT COARSE JUL 05 22:00:00 Y +DG2/dg/datafile/test5.dbf => TEST5.260.852157413
四、为ASM中SYSTEM表空间使用别名
比方上面创建的表空间test4其相应的数据文件TEST4.DBF是一个别名,真实的数据文件与别名的相应是:+DG1/dg/datafile/test4.dbf => TEST4.279.852157365
,然而(system,undotbs,sysaux,users)相应的都是真实的数据文件,没有别名,这时假设要对这些表空间使用别名,就须要重建控制文件。示比例如以下:
alter diskgroup dg1 add alias '+DG1/dg2/datafile/SYSTEM1.DBF' FOR '+DG1/dg2/datafile/system.258.852146097';
此时ASMCMD中查看:
ASMCMD> ls -al
WARNING:option 'a' is deprecated for 'ls'
please use 'absolutepath'
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE JUL 05 23:00:00 Y none => SYSAUX.257.852146099
DATAFILE UNPROT COARSE JUL 05 23:00:00 Y +DG1/DG2/DATAFILE/SYSTEM1.DBF => SYSTEM.258.852146097
N SYSTEM1.DBF => +DG1/DG2/DATAFILE/SYSTEM.258.852146097
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 418484224 bytes
Fixed Size 1365040 bytes
Variable Size 255855568 bytes
Database Buffers 155189248 bytes
Redo Buffers 6074368 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "DG" RESETLOGS FORCE LOGGING ARCHIVELOG …………
重建控制文件完毕后数据库是MOUNT状态,此时查询:
SQL> select * from v$dbfile;
FILE# NAME
---------- --------------------------------------------------
8 +DG2/dg/datafile/test5.dbf
7 +DG1/dg/datafile/test4.dbf
6 +DG1/dg2/datafile/test2.272.852147911
5 +DG2/dg/datafile/test1.dbf
4 +DG1/dg2/datafile/users.259.852146107
3 +DG1/dg2/datafile/undotbs1.256.852146101
2 +DG1/dg2/datafile/sysaux.257.852146099
1 +DG1/dg2/datafile/system1.dbf