We have a requirement to perform some archiving and purging of a database, and we need to take a copy of Production which we can use to test.
One option is to create a PDB clone from the Production database since it is using containers.
I created an OEL7 VM in Proxmox, then installed Oracle ASM V19C and the 19C database software. then created a container database (orcl) and a pluggable database (orclpdb). I won't go through this, it's pretty straight-forward.
I then cloned the VM to save me having to re-create one from scratch.
When the clone was done, I changed the hostname and IP address. So I ended up with 2 VMs, one called OEL7ASM1 and OEL7ASM2.
I also dropped the orclpdb pluggable database from the OEL7ASM2 host so that I can create it from the OEL7ASM1 host.
I added the source host oel7asm1 into the oel7asm2 /etc/hosts file and also created a tnsnames.ora entry for the source database. Make sure you use the FQDN
I couldn't get the tnsping or sqlplus connection to the ORCL_REMOTE database, even after enabling port 1521, so I ended up disabling the firewall and then it worked. Needless to say, don't do this on any client or host that you care about.
On the oel7asm2 host, trying to contact the source host before the firewall was disabled:
Disabling the firewall on the source host:
Trying the connection again from the target host
Before doing the clone, create a staging directory and set the target database REMOTE_RECOVERY_FILE_DEST parameter:
mkdir /tmp/pdbclone
You also need to put the source database in archivelog mode and open
You can now try the pdb clone using RMAN duplicate.
On the target host, connect to RMAN target and auxiliary and issue the RMAN command to perform the PDB duplicate. The target is the source, the auxiliary is where the database is to be cloned to.
The pdb should now be there
This method requires a staging area (/tmp/pdbclone).
We can also use a database link which doesn't, so we'll do that now.
Drop the newly created pdb
Create a user on the source PDB database and give them DBA access and grants to create a pluggable database
Create a new tnsnames.ora entry on the target host pointing to the pdb service on the source
On the target CDB, create a database link to the source as that user, using the tnsnames.ora entry that points to the source pdb:
Run the command to create the target pluggable database, then open it:
You can then drop the database link.