plug and unPlug the Oracle 12c Pluggable Database
Unplug the PDB database from Container Database
Step 1 : Check the database version and environment detail
set echo on
SET LINESIZE 200
SET PAGESIZE 10000
SET SERVEROUTPUT ON
COLUMN "DB DETAILS" FORMAT A100
SELECT 'DB_NAME: ' ||sys_context('userenv', 'db_name')||
' / CDB?: ' ||(select cdb from v$database)||
' / AUTH_ID: ' ||sys_context('userenv', 'authenticated_identity')||
' / USER: ' ||sys_context('userenv', 'current_user')||
' / CONTAINER: '||nvl(sys_Context('userenv', 'con_Name'), 'NON-CDB')
"DB DETAILS"
FROM DUAL;
Step 2: Check all pluggable database present in the CDB database.
SET SERVEROUTPUT ON
COLUMN "RESTRICTED" FORMAT A10
select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d
using (GUID)
order by v.create_scn;
Step 3: Close the pluggable database:
alter pluggable database C01P01P close;
Step 4: Execute the following command for unplug the database and create a xml file.
alter pluggable database C01P01P unplug into '/u01/app/oracle/oradata/c01p/c01p01p/c01p01pxml'
Step 5: Execute the following command for verify:
SET SERVEROUTPUT ON
COLUMN "RESTRICTED" FORMAT A10
select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d
using (GUID)
order by v.create_scn
/
Step 6: Drop the pluggable database from cdb and keep its file for future use.
drop pluggable database C01P01P keep datafiles;
Step 7: Check the PDB database
COLUMN "RESTRICTED" FORMAT A10
select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d
using (GUID)
order by v.create_scn
/
Plug the PDB database to Another Container
Step 8: Connect with another container database.
Note: Version of container and pluggable database must be same and same patches should be applied on both.
Step 9: Check the compatibility of the database:
begin
if not dbms_pdb.check_plug_compatibility( pdb_descr_file => '/u01/app/oracle/oradata/c01p/c01p01p/c01p01p.xml')
then
raise_application_error(-20000, 'PDB is not compatible to plug in');
end if;
end;
/
Step 10: Create the pluggable with the xml file created above:
create pluggable database C01P01P using '/u01/app/oracle/oradata/c01p/c01p01p/c01p01p.xml'
move
file_name_convert = ('/c01p/', '/c02p/');
Step 11: Open the pluggable database by connecting with CDB database:
alter pluggable database C01P01P open;
Step 12: Verify the pluggable database in CDB
SET SERVEROUTPUT ON
COLUMN "RESTRICTED" FORMAT A10
select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d
using (GUID)
order by v.create_scn;