根据pdbseed种子克隆
创建步骤:
(a) 使用创建pdb语句:
SQL> create pluggable database pdborcl admin user pdbadmin identified by oracle file_name_convert=('pdbseed','pdborcl');
备注:
1、如果不设置convert参数,pdb将会使用omf管理方式查看状态
2、当db_create_file_dest存在时(也就是使用OMF方式),file_name_convert可以不用加,此时会用omf命名方法生成数据文件。
3、rac环境下可在asm磁盘组提前创建好文件目录结构,omf如果使用的话,使用file_name_convert进行转化路径,并显式分别指定pdbseed的绝对路径(system,sysaux,temp)。如create pluggable database pdborcl admin user admin identified by oracle file_name_convert=(’+DATA/ORCL/77408ECCA64E8959E0530B0410AC5685/DATAFILE/system.267.988496155’,’+DATA/pdborcl/system.dbf’,’+DATA/ORCL/77408ECCA64E8959E0530B0410AC5685/DATAFILE/sysaux.268.988496159’,’+DATA/pdborcl/sysaux.dbf’,’+DATA/ORCL/77408ECCA64E8959E0530B0410AC5685/TEMPFILE/temp.269.988496161’,’+DATA/pdborcl/temp.dbf’);
(b) 查询cdb,pdb状态
SQL> select pdb_name,status from cdb_pdbs;
PDB_NAME STATUS
---------- ----------
PDB$SEED NORMAL
PDBORCL NORMAL
© 打开pdb
SQL> alter pluggable database pdborcl open;
Pluggable database altered.
(d) 查看状态
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- --------------
2 PDB$SEED READ ONLY NO
3 PDBORCL READ WRITE NO
(e) 查看服务名
SQL> select name from v$services;
NAME
-------------------------------------
orclXDB
orcl
SYS$BACKGROUND
SYS$USERS
pdborcl
还可以通过PATH_PREFIX参数,指定数据文件路径,Oracle会自动创建目录,如下:
SQL> create pluggable database cs admin user admin identified by oracle PATH_PREFIX='/u01/app/oracle/oradata/orcl/cs/' file_name_convert=('pdbseed','cs');
Pluggable database created.
SQL> select name from v$datafile;
/u01/app/oracle/oradata/orcl/cs/system01.dbf
/u01/app/oracle/oradata/orcl/cs/sysaux01.dbf
/u01/app/oracle/oradata/orcl/cs/undotbs01.dbf
SQL> create pluggable database test admin user admin identified by oracle file_name_convert=(‘pdbseed’,‘test’);
create pluggable database test admin user admin identified by oracle file_name_convert=(‘pdbseed’,‘test’)
*
ERROR at line 1:
ORA-65005: missing or invalid file name pattern for file -
+DATA/ORCL/FD9AC20F64D244D7E043B6A9E80A2F2F/DATAFILE/system.266.987717117
[oracle@orcldb ~]$ dbca -silent -createPluggableDatabase -sourceDB orcl -pdbName pdborcl -createPDBFrom default -pdbadminusername padmin -pdbadminpassword oracle -pdbdatafiledestination /u01/app/oracle/oradata/orcl/pdborcl
Creating Pluggable Database
2% complete
6% complete
11% complete
20% complete
46% complete
Completing Pluggable Database Creation
53% complete
Executing Post Configuration Actions
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/orcl/pdborcl/orcl.log" for further details.
备注:-sourceDB后面的参数为unique name for RAC database 或者 SID
cdb内用户创建
create user c##cdbadmin identified by oracle;
授权
grant dba to c##cdbadmin;
连接pdb有两种方式
(a)sqlplus内切换
select name,open_mode from v$pdbs;
alter session set container='';
常规方式创建用户
(b)通过tnsname方式连接
sqlplus sys/oracle@pdborcl
一次性打开所有pdb
alter pluggable database all open;
将pdb 启动到只读状态
alter pluggable database pdborcl open read only;
一次性关闭所有pdb
alter pluggable database all close immediate;
在pdb内操作
SQL> alter session set container=pdborcl;
Session altered.
SQL> startup restrict;
Pluggable Database opened.
SQL> alter pluggable database pdborcl rename global_name to pdborclnew;
Pluggable database altered.
SQL> show con_name
CON_NAME
------------------------------
PDBORCLNEW
在pdb内执行
alter pluggable database pdborcl storage(maxsize 10G);
select db_name,con_id,pdb_name,operation,op_timestamp,cloned_from_pdb_name from cdb_pdb_history;
##2.6 禁用RESULT CACHE特性
Bug 20985596 : ORA-00600[KPP_CONCATQ:2] OCCURS WHEN SQL EXECTING
alter system set result_cache_mode=manual;
alter system set result_cache_max_size=0;
alter system set “_optimizer_ads_use_result_cache”=false;
12c r1 12c r2区别:
在oracle 12.1 克隆时需要关闭库,并且需要启动到只读状态
在oracle 12.2 无需关库,可以直接在线克隆
备注:gui方式克隆的pdb,默认会创建users表空间,并且创建完毕之后会自动打开pdb
操作步骤:
在cdb 内执行:
create pluggable database pdborclclone from pdborcl
file_name_convert=('pdborcl','pdborclclone')
service_name_convert=('pdborcl','pdborclclone');
创建PDB时,可以只克隆数据库的数据定义模型而不要数据(用户创建的表或索引的数据被舍弃),创建时指定NO DATA就可以了
create pluggable database pdb2 from pdb1 no data;
1.在新cdb主机内创建dblink
SQL> create database link pdbclone connect to pdbadmin2 identified by oracle using '172.16.4.110:1521/pdborclnew';
2.克隆源pdb
SQL> create pluggable database pdborclnew3 from pdborclnew@pdbclone file_name_convert=('/u01/app/oracle/oradata/orcl/pdborclnew','/u01/app/oracle/oradata/orcl/pdborclnew3');
3.新cdb主机内打开pdb
SQL> alter pluggable database all open;
备注:dblink内用户pdbadmin2权限为pdb_dba
1关闭pdb
alter pluggable database pdborclclone close immediate;
2删除pdb
如果没有拔出pdb可通过including datafiles删除
drop pluggable database pdborclclonbe including datafiles;
拔出之后,数据文件会被清除
先关闭pdb
alter pluggable database pdborclclone2 close immediate;
再执行拔出命令
alter pluggable database pdborclclone2 unplug into '/unplug/pdborclclone2.xml';
拔出之后需要在cdb内删除pdb
drop pluggable database pdborclclone2;
命令方式删除pdb的原数据文件还会存在,temp文件会被删除
step 1
检查下兼容性
set serveroutput on
declare
compatiable constant varchar2(3) :=
case dbms_pdb.check_plug_compatibility(
pdb_descr_file => '/unplug/pdborclclone.xml',
pdb_name => 'pdborclclone')
when true then 'yes'
else 'no'
end;
begin
dbms_output.put_line(compatiable);
end;
/
select message,action from pdb_plug_in_violations;
查看返回结果是否为yes
step 2
执行pdb插入
create pluggable database pdborclclone3 using '/unplug/pdborclclone2.xml' nocopy;--如果插入的数据库路径
备注:1此方法创建的pdb。使用的数据文件路径还是之前的
2数据库版本12c r2无法在12c r1内插入已测试,兼容性检查语句返回为no
(1)在源数据库拔出pdb,生成xml文件
(2)将源pdb数据库的数据文件以及xml文件拷贝到目标主机
(3)兼容性检查
set serveroutput on
declare
compatiable constant varchar2(3) :=
case dbms_pdb.check_plug_compatibility(
pdb_descr_file => '/unplug/pdborcl2.xml',
pdb_name => 'pdborcl2')
when true then 'yes'
else 'no'
end;
begin
dbms_output.put_line(compatiable);
end;
/
(4) 语句创建
备注使用nocopy参数是临时表数据文件不用拷贝
SQL> create pluggable database pdborcl3 using '/unplug/pdborcl2.xml'
file_name_convert=('/u01/app/oracle/oradata/orcl/pdborcl2','/u01/app/oracle/oradata/orcl/pdborcl3');
create pluggable database pdborcl using '/unplug/pdborcl.xml' nocopy;
备注:删除pdb之后再去插入无问题
在cdb内备份会备份所有数据库包括pdb
两种方式
(a)pdb通过tns方式连接rman
与备份非多租户方式一样
(b)cdb内备份pdb
直接连cdb内备份pdb
backup pluggable database pdborcl format '/u01/rman/pdborcl_full_%U.bak';
可以在cdb的mount状态恢复pdb数据库
restore pluggable database pdborclclone3;
recover pluggable database pdborclclone3;
可以在cdb的open状态恢复pdb
restore pluggable database pdborclclone3;
recover pluggable database pdborclclone3;
可在pdb内分配端口号,即可单独通过em连接pdb
exec dbms_xdb_config.sethttpsport(5501);