参考,如何在 12.2.0.1 通过 dblink 在线拷贝 PDB (文档 ID 24726-43.1)
对于数据量小的库而言,这个功能简单,操作方便,可以一试。
源 DB: cdb - orcl, pdb - PDB.
目标 DB: cdb - R12201
我们将在不关闭 PDB,也不需要将 PDB 设置为只读模式的情况下,将 orcl 在线拷贝 到 R12201
1. 检查源 DB 是否使用了 local undo(应启用 local undo):
SQL> SELECT property_name, property_value FROM database_properties WHERE
SQL> property_name = 'LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
------------------------------ ------------------------------
LOCAL_UNDO_ENABLED TRUE
2. 检查源 DB 是否启用归档模式(必须启用归档模式):
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch2
Oldest online log sequence 2
Next log sequence to archive 3
Current log sequence 3
3. 在源 DB 创建执行拷贝 操作的 DB 用户:
CREATE USER c##adminpdb IDENTIFIED BY adminpdb CONTAINER=ALL;
GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO c##adminpdb CONTAINER=ALL;
4. 在目标 DB 上创建一个 tns 别名以指向源 DB:
orcl=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = <IP_ADDRESS>)(PORT = 1521)) <====== 应将 IP 地址更改为源 DB IP
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
5. 在目标 DB 创建 dblink:
$ sqlplus / as sysdba
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 6-4 bit Production
SQL> CREATE DATABASE LINK to_source CONNECT TO c##adminpdb IDENTIFIED BY
SQL> adminpdb USING 'orcl';
Database link created.
SQL> select * from dual@to_source;
D
-
X
6. 在目标 DB 执行下面的操作,将 pdb 在线拷贝 到 pdbnew(注意:FILE_NAME_CONVERT 应相应更改):
SQL> CREATE PLUGGABLE DATABASE pdbnew FROM pdb@to_source FILE_NAME_CONVERT = ('+DATA/ORCL/6A7DB47A934B3D53E0534838A8C0FE32/DATAFILE/system.296.974205945', '/u01/data/R12201/pdbnew/system.dbf','+DATA/ORCL/6A7DB47A934B3D53E0534838A8C0FE32/DATAFILE/sysaux.297.974205947','/u01/data/R12201/pdbnew/sysaux.dbf','+DATA/ORCL/6A7DB47A934B3D53E0534838A8C0FE32/DATAFILE/undotbs1.293.974205945','/u01/data/R12201/pdbnew/undotbs1.dbf','+DATA/ORCL/6A7DB47A934B3D53E0534838A8C0FE32/DATAFILE/undo_2.306.974206187','/u01/data/R12201/pdbnew/undo_2.dbf','+DATA/ORCL/6A7DB47A934B3D53E0534838A8C0FE32/DATAFILE/users.304.974206191','/u01/data/R12201/pdbnew/users.dbf','+DATA/ORCL/6A7DB47A934B3D53E0534838A8C0FE32/TEMPFILE/temp.307.974205955','/u01/data/R12201/pdbnew/temp.dbf');
Pluggable database created.
7. 在目标 DB 启动 pdb:
SQL> alter pluggable database pdb open;
8. 检查目标 DB 上的 PDB_PLUG_IN_VIOLATIONS 是否有错误