特别适合于源CDB和目标CDB不在同一台机器的情况,拔下的PDB,就只有一个文件,包含PDB的元文件和数据文件,方便拷贝。
环境:
源端:CDB2: PDB1
目标端:CDB1
数据库版本:19.20
1.登陆到源CDB :cdb2
[oracle@dbserver ~]$ sqlplus /nolog
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Oct 22 14:19:45 2023
Version 19.20.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
@ >conn / as sysdba
Connected.
SYS@cdb2 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB2 READ WRITE NO
4 PDB1 READ WRITE NO
SYS@cdb2 >
2.关闭PDB1
SYS@cdb2 >alter pluggable database pdb1 close;
Pluggable database altered.
SYS@cdb2 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB2 READ WRITE NO
4 PDB1 MOUNTED
SYS@cdb2 >
3.拔下到归档文件
SYS@cdb2 >alter pluggable database pdb1
2 unplug into '/tmp/pdb1.arch';
unplug into '/tmp/pdb1.arch'
*
ERROR at line 2:
ORA-65125: valid XML or PDB archive file name is required
SYS@cdb2 >
SYS@cdb2 >alter pluggable database pdb1
2 unplug into '/tmp/pdb1.pdb';
Pluggable database altered.
--4.确认文件类型
SYS@cdb2 >! ls -ltr /tmp/pdb1.pdb -h
-rw-r--r-- 1 oracle asmadmin 303M Oct 22 14:24 /tmp/pdb1.pdb
SYS@cdb2 >! file /tmp/pdb1.pdb
/tmp/pdb1.pdb: Zip archive data, at least v4.5 to extract
SYS@cdb2 >
5.从源端删除PDB1
SYS@cdb2 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB2 READ WRITE NO
4 PDB1 MOUNTED
SYS@cdb2 >
SYS@cdb2 >
SYS@cdb2 >drop pluggable database pdb1;
Pluggable database dropped.
SYS@cdb2 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB2 READ WRITE NO
SYS@cdb2 >
6.进入目标端 CDB1
[oracle@dbserver ~]$ . oraenv
ORACLE_SID = [cdb1] ?
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@dbserver ~]$
[oracle@dbserver ~]$
[oracle@dbserver ~]$ sqlplus /nolog
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Oct 22 14:27:19 2023
Version 19.20.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
@ >conn / as sysdba
Connected.
SYS@cdb1 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
4 PDB3 MOUNTED
6 PDB_ORCL READ WRITE NO
SYS@cdb1 >
7.插入PDB1
SYS@cdb1 >show parameter db_create_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string /u01/app/oracle/oradata/
SYS@cdb1 >create pluggable database pdb1
2 using '/tmp/pdb1.pdb';
Pluggable database created.
SYS@cdb1 >
8.确认文件路径
SYS@cdb1 >SHOw PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED
4 PDB3 MOUNTED
6 PDB_ORCL READ WRITE NO
SYS@cdb1 >SELECT name from v$datafile where con_id=3;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/CDB1/07BE9065CAE69697E0637885A8C080A5/datafile/o1_mf_sys
tem_lm9j99m2_.dbf
/u01/app/oracle/oradata/CDB1/07BE9065CAE69697E0637885A8C080A5/datafile/o1_mf_sys
aux_lm9j99mc_.dbf
/u01/app/oracle/oradata/CDB1/07BE9065CAE69697E0637885A8C080A5/datafile/o1_mf_und
otbs1_lm9j99md_.dbf
/u01/app/oracle/oradata/CDB1/07BE9065CAE69697E0637885A8C080A5/datafile/o1_mf_tsp
_pdb1_lm9j99mf_.dbf
NAME
--------------------------------------------------------------------------------
9.打开PDB
SYS@cdb1 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED
4 PDB3 MOUNTED
6 PDB_ORCL READ WRITE NO
SYS@cdb1 >alter pluggable database pdb1 open;
Pluggable database altered.
SYS@cdb1 >show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB3 MOUNTED
6 PDB_ORCL READ WRITE NO
SYS@cdb1 >