在oracle 12.2中可以对pdb执行relocate失踪,下面的例子将介绍对远程CDB中将名为jypdb的PDB进行迁移操作。假设满足以下条件:
.当前用户在被迁移PDB所在的CDB的root容器中有create pluggable database系统权限
.目标CDB连接PDB当前CDB的dblink名为jycdb_link。dblink的创建语句如下:
create public database link jycdb_link connect to c##yyl identified by "yyl" using 'jy';
PDB的当前CDB中的公共用户c##yyl有sysoper管理权限与create pluggable database系统权限
.不指定path_prefix子句
.不指定file_name_convert与create_file_dest子句。当启用OMF或设置pdb_file_name_convert参数时,基于OMF的配置或参数的设置文件会被移动到新目录。
.对PDB不指定存储限制。因此不指定storage子句
.在目标目录中不存在相同名字的temp文件,那么新的temp文件会被创建。因此不指定tempfile reuse子句。
.连接会被自动从源PDB迁移到迁移后的PDB。因此指定availability max子句。
执行以下语句来将PDB(jypdb)从远程CDB迁移到当前CDB中:
1.在远程CDB中创建公共用户c##yyl
SQL> create user c##yyl identified by "yyl" container=all; User created. SQL> grant sysoper,connect,resource,create pluggable database to c##yyl container=all; Grant succeeded.
2.检查远程CDB是否使用本地undo与归档
SQL> COLUMN property_name FORMAT A30 SQL> COLUMN property_value FORMAT A30 SQL> SQL> SELECT property_name, property_value 2 FROM database_properties 3 WHERE property_name = 'LOCAL_UNDO_ENABLED'; PROPERTY_NAME PROPERTY_VALUE ------------------------------ ------------------------------ LOCAL_UNDO_ENABLED TRUE SQL> SELECT log_mode FROM v$database; LOG_MODE ------------ ARCHIVELOG
因为远程CDB使用本地undo与归档,因此不需要将远程数据库设置为只读模式
3.在本地CDB(jy)中创建指定远和CBD(jy)的dblink。连接串中要包含(SERVER=DEDICATED)条目录,否则会收到 “ORA-01031: insufficient privileges”错误
SQL> create public database link jycdb 2 connect to c##yyl identified by "yyl" 3 using '(DESCRIPTION = 4 (ADDRESS_LIST = 5 (ADDRESS = (PROTOCOL = TCP)(HOST =10.138.130.173)(PORT = 1521)) 6 ) 7 (CONNECT_DATA = 8 (SERVER = DEDICATED) 9 (SERVICE_NAME =jy) 10 ) 11 )'; Database link created. SQL> select * from dual@jycdb; D - X
4.检查本地CDB是否使用了本地undo与归档
SQL> COLUMN property_name FORMAT A30 SQL> COLUMN property_value FORMAT A30 SQL> SQL> SELECT property_name, property_value 2 FROM database_properties 3 WHERE property_name = 'LOCAL_UNDO_ENABLED'; PROPERTY_NAME PROPERTY_VALUE ------------------------------ ------------------------------ LOCAL_UNDO_ENABLED TRUE SQL> SELECT log_mode FROM v$database; LOG_MODE ------------ ARCHIVELOG
5.在本地CDB执行下面的语句来克隆可刷新的PDB
SQL> create pluggable database jypdb from jypdb@jycdb relocate availability max; Pluggable database created. SQL> select name,open_mode from v$pdbs; NAME OPEN_MODE -------------------------------------------------------------------------------------------------------------------------------- ---------- PDB$SEED READ ONLY JYPDB READ WRITE
以read write方式来打开PDB以完成迁移操作
SQL> alter pluggable database jypdb open; Pluggable database altered. SQL> alter session set container=jypdb; Session altered. SQL> set long 200 SQL> set linesize 200 SQL> select name,open_mode from v$pdbs; NAME OPEN_MODE -------------------------------------------------------------------------------------------------------------------------------- ---------- JYPDB READ WRITE
删除公共dblink
SQL> drop public database link jycdb; Database link dropped.
检查远程PDB可以看到已经被删除了
SQL> alter session set container=jypdb; Session altered. SQL> select name,open_mode from v$pdbs; no rows selected