一、先Unplugging PDB
参考:http://blog.itpub.net/29785807/viewspace-2683385/
1.1 方法一:图形界面操作
1.2 方法二:命令行操作
[oracle@ol8-19c ~]$ . oraenv
ORACLE_SID = [ykt] ?
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@ol8-19c ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 25 11:36:54 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> show pdbs;
CON_ID CON_NAM OPEN MODE RESTRICTED
---------- ------------ ------------------ ----------
2 PDB$SEED READ ONLY NO
3 ZYTK35 READ WRITE NO
4 GBKPDB READ WRITE NO
SQL> alter pluggable database gbkpdb close immediate;
Pluggable database altered.
SQL> alter pluggable database gbkpdb unplug into '/home/oracle/gbkpdb.xml';
Pluggable database altered.
SQL> drop pluggable database gbkpdb keep datafiles;
Pluggable database dropped.
SQL> select pdb_name, status from cdb_pdbs where pdb_name in ('GBKPDB');
no rows selected
二、传输文件到目标数据库
三、再Plug Unplugging PDB
3.1 方法一:图形界面操作
第二步:选择 Create a Pluggable database
第三步:选择目标数据库,并输入账号与密码,使用 sys 账户
第四步:选择 Create Pluggable database from an unplugged PDB
并选择xml格式的 metadata file
第五步:为新的 PDB 创建一个数据库名,以及用户信息(可作为管理员用户)
3.2 方法二:命令行操作
-
- 修改文件的属主:
chown oracle.dba *.xml
chown oracle.dba *.dbf
如果是docker容器,那么以root用户进入容器的命令是
docker exec -it -u root a3f2b334dcf3 /bin/bash
-- 其中a3f2b334dcf3为容器的ID
如果oracle用户没有读写文件权限的话,会报如下错误:
ORA-65026: XML metadata file error : LPX-00202: could not open
"/home/oracle/ykt_GBKPDB.xml" (error 200)
ORA-06512: at "SYS.DBMS_PDB", line 32
ORA-06512: at line 2
-
- 对文件做兼容性检查
不同版本之间的数据库是不允许进行插拔安装的。
- 对文件做兼容性检查
SET SERVEROUTPUT ON
DECLARE
compatible CONSTANT VARCHAR2(3) :=
CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/home/oracle/gbkpdb.xml')
WHEN TRUE THEN 'YES'
ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/
-
- 查看校验结果
如果为NO,则需要查看PDB_PLUG_IN_VIOLATIONS详细内容.如果为YES,该视图也可能会包含一些内容,因此都需要查看该视图了解内容。
- 查看校验结果
SET LINES 300 PAGES 999 FEED OFF
COL TIME FOR A30
COL NAME FOR A20
COL CAUSE FOR A20
COL MESSAGE FOR A60
COL ACTION FOR A60
SELECT * FROM PDB_PLUG_IN_VIOLATIONS;
-
- 替换XML文件中数据文件的位置
将gbkpdb.xml
中/u02/oradata/YKT/GBKPDB/
路径改成/home/oracle/
。 这一步很关键。
- 替换XML文件中数据文件的位置
-
- 创建pluggable database
SQL> create pluggable database lzudw using '/home/oracle/gbkpdb.xml'
copy
file_name_convert = ('/home/oracle/','/opt/oracle/oradata/MYCDB/lzudw/')
tempfile reuse;
主要参考: https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/pdb/pdb_unplug_plug/pdb_unplug_plug.html
How to Unplug and Plug In Your Pluggable Database in Oracle 12c
https://docs.oracle.com/en/database/oracle/oracle-database/18/multi/plugging-in-a-pdb.html#GUID-EE58804F-A999-4F7C-93DE-D641B3C1047B