问题描述
如果在CDB 最初创建时,启用了OMF 文件管理功能进行创建,那么生成的所有文件将会使用OMF 文件命名格式,此时我们应该如何创建出非OMF 文件命名格式的PDB 呢。
使用file_name_convert 包含全部数据文件创建PDB
查看种子容器
// 连接种子容器,查看db_create_file_dest参数:
SQL> alter session set container=PDB$SEED;
Session altered.
SQL> show parameter db_create_file_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DATA_DISK
// 为OMF文件管理
// 查看种子容器数据文件位置
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.265.1044631095
+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.266.1044631095
+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.267.1044631095
克隆种子容器
连接至根容器,在根容器进行创建salespdb
create pluggable database salespdb
admin user byh identified by oracle
file_name_convert = ('+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE',
'+DATA_DISK/ORCL/SALESPDB' );
// 如果使用OMF功能,就不需要file_name_convert参数,自动管理创建文件名称以及位置
create pluggable database salespdb
admin user byh identified by oracle
//+DATA_DISK/ORCL/SALESPDB/ 该目录需要事先被创建
ASMCMD> pwd
+DATA_DISK/ORCL
ASMCMD> mkdir SALESPDB
当种子容器的数据文件文件名为OMF文件名格式,在我们不使用OMF功能创建PDB时,db_file_name_convert必须包含全部的数据文件,否则会出现如下错误
create pluggable database salespdb
admin user byh identified by oracle
file_name_convert =('+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.265.1044631095',
'+DATA_DISK/ORCL/SALESPDB/system01.dbf','+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.266.1044631095','+DATA_DISK/ORCL/SALESPDB/sysaux01.dbf','+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.267.1044631095','+DATA_DISK/ORCL/SALESPDB/undotbs1.dbf', '+DATA_DISK/ORCL/A95D17FF830756CDE0539BEEA8C08D7A/TEMPFILE/temp.268.1044631129','+DATA_DISK/ORCL/SALESPDB/temp01.dbf')
注意在file_name_convert中加入临时文件(否则会出如下错误)
查看新创建PDB 的数据文件命名
SQL> alter session set container=salespdb;
Session altered.
SQL> show con_name;
CON_NAME
------------------------------
SALESPDB
SQL> show parameter db_create_file_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DATA_DISK
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA_DISK/ORCL/SALESPDB/system01.dbf
+DATA_DISK/ORCL/SALESPDB/sysaux01.dbf
+DATA_DISK/ORCL/SALESPDB/undotbs1.dbf
的参数继承
启动新创建的PDB:
SQL> alter session set container=salespdb;
Session altered.
SQL> alter database open;
Database altered.
SQL> show con_name;
CON_NAME
------------------------------
SALESPDB
SQL> create tablespace bao;
Tablespace created.
SQL> select file_name,tablespace_name from dba_data_files where tablespace_name='BAO';
FILE_NAME TABLESPACE_NAME
---------- ------------------------------
+DATA_DISK BAO
/ORCL/A9AE
0C853DEE18
46E0539BEE
A8C03069/D
ATAFILE/ba
o.294.1044
980091
// 由于此时还没有修改db_create_file_dest参数,那么就依然可以使用OMF功能。
SQL> drop tablespace bao including contents and datafiles;
SQL> show parameter db_create_file_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DATA_DISK
修改这个参数:
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
//PDB 级别的参数修改仅在该PDB有效,不会影响其他PDB。
//PDB 级别的初始化参数不是存储在SPFILE 中,而是存储在 CDB 的数据字典 PDB_SPFILE$ 内部表中,该参数修改完成后,可以在根容器的pdb_spfile$中查看
SQL> select pdb_uid,name,value$ from pdb_spfile$; // 在CDB中查看,在PDB中为空
PDB_UID NAME VALUE$
---------- -------------------- --------------------
3809949089 db_create_file_dest ''
// 在CDB中查看PDB_UID
SQL> select con_uid,pdb_name from cdb_pdbs;
CON_UID PDB_NAME
---------- --------------------
2670145786 PDBBAO
1457981965 PDB$SEED
3809949089 SALESPDB
// 再次创建表空间
SQL> create tablespace bao;
create tablespace bao
*
ERROR at line 1:
ORA-02199: missing DATAFILE/TEMPFILE clause
//OMF 管理功能已经关闭。
SQL> create tablespace bao datafile '+DATA_DISK/ORCL/SALESPDB/bao.dbf' size 50M;
Tablespace created.
结论
说明:
当我们的种子容器或者其他PDB文件格式为OMF文件名格式,在我们不使用OMF功能创建PDB时,db_file_name_convert必须包含全部的数据文件,因为是在ASM上。
根据种子容器生成的数据文件(也就是说通过file_name_convert转换出来的文件)为非OMF文件名格式的文件,但是创建出来的PDB,会继承根容器的参数配置,根容器的db_create_file_dest参数是设置的,也就是说根容器启动了OMF管理,新创建出来的PDB也就会继承这个参数,也是开启了OMF功能,但是克隆生成的system,sysaux,undo还有temp文件,属于非OMF管理生成的文件(非OMF文件名格式的文件),我们可以在PDB级别修改这个参数,来关闭OMF文件管理功能,进而在PDB中创建数据文件。
不指定所有的数据文件创建PDB
方法描述
那么如何才能不需要指定所有的数据文件创建PDB呢
那么我们就需要构造一个模版,将这个模版中的数据文件(之前使用OMF功能创建的数据文件)将其重命名为非OMF文件名格式
然后再次创建PDB。
使用RMAN copy 数据文件
CDB 操作:
//mount 状态
SQL>shutdown immediate
SQL>startup mount
RMAN> copy datafile '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.265.1044631095' to '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.dbf';
RMAN> copy datafile '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.266.1044631095' to '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.dbf';
RMAN> copy datafile '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.267.1044631095' to '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.dbf';
临时文件我们无法使用RMAN COPY 故采用操作系统cp命令
ASMCMD> cp TEMP.268.1044631129 TEMP01.dbf
copying +DATA_DISK/ORCL/A95D17FF830756CDE0539BEEA8C08D7A/TEMPFILE/TEMP.268.1044631129 -> +DATA_DISK/ORCL/A95D17FF830756CDE0539BEEA8C08D7A/TEMPFILE/TEMP01.dbf
种子容器数据文件重命名
// 进入到PDB$SEED
SQL>alter session set container=PDB$SEED
SQL>alter pluggable database rename file '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.265.1044631095' to '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.dbf';
SQL>alter pluggable database rename file '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.266.1044631095' to '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.dbf';
SQL>alter pluggable database rename file '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.267.1044631095' to '+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.dbf';
SQL> alter pluggable database rename file '+DATA_DISK/ORCL/A95D17FF830756CDE0539BEEA8C08D7A/TEMPFILE/TEMP.268.1044631129' to '+DATA_DISK/ORCL/A95D17FF830756CDE0539BEEA8C08D7A/TEMPFILE/TEMP01.dbf'
// 重命名完毕
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.dbf
+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.dbf
+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.dbf
创建PDB
再次创建PDB
打开CDB
SQL> alter database open;
SQL>
create pluggable database salespdb
admin user byh identified by oracle
file_name_convert =('+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE',
'+DATA_DISK/ORCL/SALESPDB','+DATA_DISK/ORCL/A95D17FF830756CDE0539BEEA8C08D7A/TEMPFILE','+DATA_DISK/ORCL/SALESPDB')
查看新建PDB 的数据文件命名格式
SQL> alter session set container=salespdb;
Session altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA_DISK/ORCL/SALESPDB/system.dbf
+DATA_DISK/ORCL/SALESPDB/sysaux.dbf
+DATA_DISK/ORCL/SALESPDB/undotbs1.dbf
如果CDB关闭了OMF,再次进行创建时,不指定全部的数据文件结果会如何:
SQL> alter pluggable database SALESPDB close immediate
SQL> drop pluggable database SALESPDB including datafiles
SQL> create pluggable database salespdb
admin user byh identified by oracle
file_name_convert =('+DATA_DISK/ORCL/86B637B62FE07A65E053F706E80A27CA/DATAFILE',
'+DATA_DISK/ORCL/SALESPDB')
// 看来之前使用OMF文件管理功能创建出来的数据文件(数据文件命名格式为OMF),即使后面将OMF关闭,也不可以。
克隆现存PDB的方式也可以
[grid@rac1 ~]$ asmcmd
ASMCMD> cd DATA_DISK/
ASMCMD> cd ORCL
ASMCMD> mkdir SALESPDB2
create pluggable database salespdb2 from PDB$SEED
不可以将种子容器做为源PDB来克隆PDB
根据现存的PDB创建PDB
create pluggable database salespdb2 from PDBBAO
file_name_convert =('+DATA_DISK/ORCL/A95D6F0AF6250D91E0539BEEA8C09172/DATAFILE/system.274.1044632559',
'+DATA_DISK/ORCL/SALESPDB2/system01.dbf','+DATA_DISK/ORCL/A95D6F0AF6250D91E0539BEEA8C09172/DATAFILE/sysaux.275.1044632559','+DATA_DISK/ORCL/SALESPDB2/sysaux01.dbf','+DATA_DISK/ORCL/A95D6F0AF6250D91E0539BEEA8C09172/DATAFILE/undotbs1.273.1044632557','+DATA_DISK/ORCL/SALESPDB2/undo01.dbf','+DATA_DISK/ORCL/A95D6F0AF6250D91E0539BEEA8C09172/DATAFILE/undo_2.277.1044632629','+DATA_DISK/ORCL/SALESPDB2/undo02.dbf'
,'+DATA_DISK/ORCL/A95D6F0AF6250D91E0539BEEA8C09172/DATAFILE/users.278.1044632637','+DATA_DISK/ORCL/SALESPDB2/user01.dbf',
'+DATA_DISK/ORCL/A95D6F0AF6250D91E0539BEEA8C09172/TEMPFILE/temp.276.1044632567','+DATA_DISK/ORCL/SALESPDB2/temp01.dbf')
Pluggable database created.
SQL> alter session set container=salespdb2;
Session altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA_DISK/ORCL/SALESPDB2/system01.dbf
+DATA_DISK/ORCL/SALESPDB2/sysaux01.dbf
+DATA_DISK/ORCL/SALESPDB2/undo01.dbf
+DATA_DISK/ORCL/SALESPDB2/undo02.dbf
+DATA_DISK/ORCL/SALESPDB2/user01.dbf