标签 容器克隆 下的文章

迁移时在目标库上兼容性检查:
SET SERVEROUTPUT ON
DECLARE
compatible CONSTANT VARCHAR2(3) :=

CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file=>'PDB1.xml',pdb_name =>'testpdb2')
WHEN TRUE THEN 'YES'  
ELSE 'NO'  

END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;

select con_id, name, type, message, statusfrom PDB_PLUG_IN_VIOLATIONSwhere status<>'RESOLVED' order by name,time;

创建管理用户:

使用SEED创建PDB
CREATE PLUGGABLE DATABASE salespdb
ADMIN USER salesadm IDENTIFIED BY password
ROLES = (dba)
DEFAULT TABLESPACE sales

DATAFILE '/disk1/oracle/dbs/salespdb/sales01.dbf' SIZE 250M AUTOEXTEND ON

FILE_NAME_CONVERT = ('/disk1/oracle/dbs/pdbseed/',

                   '/disk1/oracle/dbs/salespdb/')

STORAGE (MAXSIZE 2G)
PATH_PREFIX = '/disk1/oracle/dbs/salespdb/';

从现有的一个PDB克隆一个新的PDB
REATE PLUGGABLE DATABASE newpdb FROM salespdb
FILE_NAME_CONVERT = ('/disk1/oracle/dbs/salespdb/', '/disk1/oracle/dbs/newpdb/')
PATH_PREFIX = '/disk1/oracle/dbs/newpdb';

把一个PDB放进另外一个CDB
CREATE PLUGGABLE DATABASE salespdb
USING '/disk1/usr/salespdb.xml'
SOURCE_FILE_NAME_CONVERT =

('/disk1/oracle/dbs/salespdb/', '/disk2/oracle/dbs/salespdb/')

NOCOPY
STORAGE (MAXSIZE 2G)
TEMPFILE REUSE;

例子:把一个PDB放进另外一个CDB
有两个实例oracle12c和cdb1,原oracle12c实例有一个pdb2,现在需要把这个pdb2插入到cdb1实例中。
解决方法:
方法1
export ORACLE_SID=oracle12c
sqlplus / as sysdba
alter pluggable database pdb2 open read only;
begin
dbms_pdb.describe
(
pdb_descr_file=>'/u01/pdb2.xml',
pdb_name=>'pdb2'
);
end;
/
不unplug pdb2直接把pdb2 插入到cdb1容器中
export ORACLE_SID=cdb1
sqlplus / as sysdba
create pluggable database salespdb using '/u01/pdb2.xml'
copy
file_name_convert=('/u01/app/oracle/oradata/pdb2/','/u01/app/oracle/oradata/cdb1/pdb2/');
alter pluggable database salespdb open;

方法2
也可以通过把pdb2先unplug 然后在插入到cdb1容器中如下
export ORACLE_SID=oracle12c
sqlplus / as sysdba
alter pluggable database pdb2 close immediate;
alter pluggable database pdb2 unplug into '/u01/pdb2.xml';
unplug之后的pdb是不能打开的,把unplug的pdb2插入到cdb1中
加上AS CLONE字句可以确保新的pdb有唯一的标识
create pluggable database salespdb as clone using '/u01/pdb2.xml'
copy
file_name_convert=('/u01/app/oracle/oradata/pdb2/','/u01/app/oracle/oradata/cdb1/pdb2/');

方法3
通过dblink方式进行源库到目标库的pdb复制迁移
源库
export ORACLE_SID=oracle12c
sqlplus / as sysdba
alter session set container=pdb1;
create user createdb identified by createdb;
grant create session,create pluggable database to creatadb;
目标库
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
PDB1 =
(DESCRIPTION =

(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVER = DEDICATED)
  (SERVICE_NAME = pdb1)
)

)
export ORACLE_SID=cdb1
sqlplus / as sysdba
create public database link node2_node1 connect to createdb identified by createdb
using 'pdb1';
create pluggable database pdb1 from pdb1@node2_node1
file_name_convert=('/u01/app/oracle/oradata/oracle12c/pdb1/','/u01/app/oracle/oradata/cdb1/pdb1/');

show con_name