CLONE REMOTE PDB da un Container ad un altro usando DBLINK
--->>>>DOC 2882174.1 ---
How to clone remote pdb from one cdb to another cdb using db link
We are cloning the pluggable database, PDB1 from root container database, CDB1 to PDB2 in root container database, CDB2.
a) Close and Open the PDB1 in READ WRITE mode to create cloneuser.
SQL> alter pluggable database pdb1 close;
Pluggable database altered.
SQL> alter pluggable database pdb1 open;
Pluggable database altered.
Login to PDB1 e creare l'utente cloneuser usato dal dblink creato su CDB2
SQL> alter session set container=pdb1;
SQL> create user cloneuser identified by cloneuser;
Grant create session and create pluggable database privileges to cloneuser.
SQL> grant create session, create pluggable database to cloneuser;
Controlla i privileges granted to the cloneuser.
SQL> select * from dba_sys_privs where grantee = 'CLONEUSER';
Aprire PDB1 in modalità read only.
SQL> alter session set container=PDB1;
SQL> alter pluggable database close;
SQL> alter database open read only;
Verify PDB1 is in READ ONLY mode.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
-------- --------- ------------- --------------
3 PDB1 READ ONLY NO
c) Login to Target Container Database, CDB2
Create the database link in the target server to clone the pdb1 from cdb1 to cdb2.
SQL> create database link clone_pdb connect to cloneuser identified by cloneuser using 'PDB1';
-- Conviene usare la seguente stringa di connessione invece del SID del pluggable database
create database link clone_pdb connect to cloneuser identified by cloneuser using
'(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = hostcdb1.dominio)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = PDB1)))';
-- Checking tnsping and database connection to pdb1 pluggable database inside container database, CDB1
# tnsping pdb1
# sqlplus connection status check
# sqlplus sys/sys@pdb1 as sysdba
SQL> sho con_name
CON_NAME
------------------------------
PDB1
SQL> show parameter instance_name
NAME TYPE VALUE
-------------- -------- -------
instance_name string cdb1
-- su PDB1 in CDB1 vedere il path dei datafile
SQL> select name from v$datafile;
/u01/app/oracle/oradata/CDB1/PDB1/sysaux01.dbf
......................
Quindi creare le direcory sul server che contiene il CBD2
# mkdir /u01/app/oracle/oradata/CDB2/PDB2
Lanciare sul server che contiene il CBD2
SQL> create pluggable database PDB2 from PDB1@clone_pdb file_name_convert=('/u01/app/oracle/oradata/CDB1/PDB1/','/u01/app/oracle/oradata/CDB2/PDB2/');
Verifiche
che PDB2 sia nello stato MOUNTED.
SQL> sho pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ---------- ---------- -------------
2 PDB$SEED READ ONLY NO
3 PDB2 MOUNTED NO
Verifica la creazione dei datafile nel datafile path corretto.
SQL> select name from v$datafile;
Aprire PDB2 database in CDB2.
SQL> alter database open;
Database altered.
SQL> alter session set container=cdb$root;
SQL> show pdbs
-- Verifica gli oggetti clonati
SQL> alter session set container=pdb2;
Session altered.
SQL> select count(*),owner , object_type, status
from dba_objects
where owner in (<schema>)
group by owner, object_type , status
order by owner;
SQL> select * from dba_registry_sqlpatch ;