Navigation Bar

Saturday, October 23, 2021

PDB Cloning

There are 2 main ways to clone a database Local cloning and Remote cloning 

Local Cloning 

This a one of the easiest methods of creating a copy or a clone PDB from another PDB. You create a clone of the PDB within the same CDB. You need to be connected to the root container or application root when executing the command. 

The basic command for cloning
create pluggable database ALPHA_PDB_CLONE from ALPHAPDB;
This command will work if OMF is enabled else you will get the below error

SQL Error: ORA-65016: FILE_NAME_CONVERT must be specified
65016. 00000 -  "FILE_NAME_CONVERT must be specified"
*Cause:    Data files, and possibly other files, needed to be copied as a
           part of creating a pluggable database.  However, Oracle Managed
           Files (OMF) was not enabled, PDB_FILE_NAME_CONVERT was not defined,
           and there was a failure to specify the FILE_NAME_CONVERT clause.
*Action:   Enable OMF or define PDB_FILE_NAME_CONVERT system parameter before
           issuing CREATE PLUGGABLE DATABASE statement, or specify
           FILE_NAME_CONVERT clause as a part of the statement.
If OMF is not configured you can locally clone your database with the below command using FILE_NAME_CONVERT parameter.
CREATE PLUGGABLE DATABASE ALPHA_PDB_CLONE 
from ALPHAPDB_PLUG_NOCOPY 
FILE_NAME_CONVERT=('D:\APP\ORACLE\ORADATA\ORCL\ORCLPDB3','D:\app\oracle\oradata\ALPHA\pdb_clone');
When the FILE_NAME_CONVERT parameter is specified the clone process will copy the files of the source database to the clone db location. 
You can also clone a PDB using the DBCA command. 

There is a feature to clone the database with only the metadata information and not actual data in the tables using the NO DATA clause. But when I have tried the below command, the new cloned database had the tables with their data included. 
This needs to be further investigated.
create pluggable database ALPHA_PDB_CLONE 
from ALPHAPDB_PLUG_NOCOPY 
FILE_NAME_CONVERT=('D:\APP\ORACLE\ORADATA\ORCL\ORCLPDB3','D:\app\oracle\oradata\ALPHA\pdb_clone')  NO DATA;

Remote cloning a PDB via a DB Link 

When doing a remote cloning if you get any errors you can consider the following prerequisites that may be required for your cloning method 
  • The user in the local database must have the CREATE PLUGGABLE DATABASE privilege in the root container. 
  • The local database must have a database link to the remote database. 
  • If the remote database is a PDB, the database link can point to the remote CDB using a common user, or the PDB using a local or common user. 
  • The user in the remote database that the database link connects to must have the CREATE PLUGGABLE DATABASE, SESSION, and SYSOPER privilege. 
  • The local and remote databases must have the same endianness, options installed and character sets. The default tablespaces for each common user in the remote PDB *must* exist in local CDB. If this is not true, create the missing tablespaces in the root container of the local PDB.  If you don''t do this your new PDB will only be able to open in restricted mode 
  • When cloning from a non-CDB, both the the local and remote databases must using version 12.1.0.2 or higher. 
  • The remote and local CDBs are in ARCHIVELOG mode.
  
 SELECT log_mode FROM v$database;
  • The remote CDB is in local undo mode.
  • If the remote CDB is not in local undo mode, then the source PDB must be open in read-only mode.
SELECT PROPERTY_NAME, PROPERTY_VALUE
FROM   DATABASE_PROPERTIES
WHERE  PROPERTY_NAME = 'LOCAL_UNDO_ENABLED';
Remote database alpha from where to clone the PDB 
Database - ALPHA 
PDB - ALPHAPDB3 
Local User - PDB3HR 
Path for database files - D:\APP\ORACLE\ORADATA\ALPHA\ALPHAPDB3 

Local database on which to clone the remote PDB 
Database - ORCL 
PDB - ORCLPDB2 
Local User - PDB2HR
Create the database link as ROOT CONTAINER connecting to a user on remote PDB
CREATE DATABASE LINK DBLINK_PDB3HR
CONNECT TO PDB3HR IDENTIFIED BY PDB3HR
USING 'ALPHAPDB3';

SELECT * FROM DUAL@PDB2HR_TO_PDB3HR;
On the local database
CREATE PLUGGABLE DATABASE orcl_pdb_rmt_cln FROM ALPHAPDB3@PDB2HR_TO_PDB3HR
FILE_NAME_CONVERT=('D:\APP\ORACLE\ORADATA\ALPHA\ALPHAPDB3', 'D:\APP\ORACLE\ORADATA\ORCL\ORCLRMTCLN');
In Oracle version 19.0.0.0 we get the below error when doing the remote cloning. As per https://oraclebptech.wordpress.com/2016/06/25/how-to-clone-local-pdb-from-remote-pdb-using-dblink/ In 12.1.0.1 we cannot clone local PDB from remote PDB using DBlink as we get the following error “ORA-17628: Oracle error 19505 returned by remote Oracle server”. 
Oracle said this is bug in 12.1.0.1 and there is no work around on this.
SQL Error: ORA-17628: Oracle error 1031 returned by remote Oracle server
ORA-01031: insufficient privileges
17628. 00000 -  "Oracle error %s returned by remote Oracle server"
*Cause:    Oracle server on the remote instance has returned an error.
*Action:   Look at remote instance alert log/trace file for more information
           and take appropriate action or contact Oracle Support Services
           for further assistance

Remote Cloning Using the DBCA cmd

TO clone ORCLPDB1 remotely on ALPHA DB using dblink and DBCA cmd 
Container DB - ORCL 
Pluggable DB - ORCLPDB1 
Container DB - ALPHA 
Pluggable DB - ORCLRMCLALPHA
dbca -silent -createPluggableDatabase -createFromRemotePDB -sourceDB ALPHA  -remotePDBName ORCLPDB1  -remoteDBConnString DESKTOP-OJM4FS4:1521/ORCL -remoteDBSYSDBAUserName SYS -remoteDBSYSDBAUserPassword N0WayIn! -dbLinkUsername c##link_user -dbLinkUserPassword Oracle4U -sysDBAUserName SYS -sysDBAPassword N0WayIn! -pdbName ORCLRMCLALPHA -pdbDatafileDestination D:\app\oracle\oradata\ALPHA\ORCLRMCLALPHA;

In Oracle version 19.0.0.0 we are getting the below error
Prepare for db operation
50% complete
Create pluggable database using remote clone operation
100% complete
[FATAL] [DBT-05505] Unable to execute sql script: (CREATE PLUGGABLE DATABASE ORCLRMCLALPHA FROM ORCLPDB1@ORCLRMCLALPHA_CLONE_LINK file_name_convert=('D:\APP\ORACLE\ORADATA\ORCL\ORCLPDB1','D:\app\oracle\oradata\ORCL\ORCLRMCLALPHA') ).
Look at the log file "D:\app\oracle\Administrator\cfgtoollogs\dbca\alpha\ORCLRMCLALPHA\alpha0.log" for further details.


God's Word for the day

Discipline of the Tongue
Listen, my children, to instruction concerning the mouth,
  the one who observes it will never be caught.
Sinners are overtaken through their lips;
  By them the reviler and the arrogant are tripped up.
Do not accustom your mouth to oaths,
  nor habitually utter the name of the Holy One.
for as a servant who is constantly under scrutiny
  will not lack buises,
so also the person who always swears and utters the Name,
  will neverr be cleansed from sin.
Sirach 23:7-10

Gospel teachings of Jesus

Jesus cures many people
After Jesus had left that place,  he passed along the sea of Galilee,
  And he went up the mountain, where he sat down.
Great crowds came to him, bringing with them the lame, 
  the maimed, the blind, the mute, and many others.
They put them at his feet, and he cured them, 
  so that the crowd was amazed when they saw the mute speaking,
the maimed whole, the lame walking, and the blind seeing.
  And they praised the God of Israel. 
Mathew 15:29-31

No comments:

Post a Comment