Saturday, 2 January 2016

12c : Clone a Remote Pluggable Database PDB

---------------------------------------------------------------------------
Multitenant : Clone a Remote Pluggable Database (PDB)
---------------------------------------------------------------------------

SQL> select name from v$database;

NAME
----------
CDB3

SQL> show con_name

-- create a user we can point a database link to.


SQL> drop user remote_clone_user CASCADE;


SQL> CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user;
create user remote_clone_user identified by remote_clone_user
            *
ERROR at line 1:
ORA-65096: invalid common user or role name


SQL> alter session set "_ORACLE_SCRIPT"=true;


SQL> CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user;


SQL> grant create session,create pluggable database to remote_clone_user;


-- Switch the remote PDB to read-only mode.
SQL> alter pluggable database pdb5 close;

sql> ALTER PLUGGABLE DATABASE pdb5 open read only;


-- Connect to root container in the local CDB.
SQL> conn sys/oracle@cdb1 AS sysdba


-- Check database name.
SQL> select name from v$database;

NAME
--------
CDB1

-- Create a database link to the remote PDB
SQL> Drop database link clone_link


SQL> Create Database Link clone_link connect to remote_clone_user identified by remote_clone_user using pdb5;

-- Clone the remote PDB over the database link.
-- If You are not using OMF, Convert the paths if necessary.
SQL> Create Pluggable Database pdb5new from pdb5@clone_link
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb3/pdb5/',
'/u01/app/oracle/oradata/cdb1/pdb5new/');


SQL> alter pluggable database pdb5new open;


-- Check the PDBs.
SQL> select name,open_mode from v$pdbs order by name;

-- Open the remote PDB in read-write mode again.
SQL> conn sys/oracle@pdb5 as sysdba

alter pluggable database pdb5 close;

alter pluggable database pdb5 open;


-- Clean up new clone
conn sys/oracle@cdb1 as sysdba

alter pluggable database pdb5new close

drop pluggable database pdb5new including datafiles;

-- Check the PDBs.

SQL> select name,open_mode from v$pdbs order by name;


No comments: