Rename a Pluggable Database In Oracle

How to rename a PDB databaes in Oracle

Following are the steps involved in rename the PDB database in Oracle:

1) Connect with the CDB database and run the following commands:

select name, open_mode, restricted from v$pdbs;

select name, con_id, dbid,con_uid,guid from v$containers;

select service_id,name,network_name,creation_date,pdb,con_id from cdb_services;

2) If you want to rename the PDB_OLD to PDB_NEW database name, then put the PDB_OLD database in restricted mode first:

alter pluggable database PDB_OLD close;

alter pluggable database PDBOLD open restricted;

-- Verify
select name, open_mode, restricted from v$pdbs; 

3) Connect the session with PDB_OLD and fire the rename command:

alter session set container=PDB_OLD;

alter pluggable database rename PDB_OLD to PDB_NEW;

4) Restart the PDB database:

alter pluggable database close immediate;
alter pluggable database open;

5) Connect to the CDB and verify:

alter session set container=CDB$ROOT;
select name, open_mode, restricted from v$pdbs;
select name, con_id, dbid,con_uid,guid from v$containers;
select service_id,name,network_name,creation_date,pdb,con_id from cdb_services;

6) if you want to move the datafiles then use the following commands:

select name from dba_Data_Files;

-- Create a new directory with new PDB name
mkdir PDB_NEW

--Use the alter database command to move files:
alter database move datafile '/u01/oradata/CDB1/pdb_old/system01.dbf' to '/u01/oradata/CDB1/pdb_new/system01.dbf'

-- Follow the upper steps for all datafiles

--For temp files you need to drop and create new one:
alter database tempfile '/u01/oradata/CDB1/pdb_old/temp01.dbf' drop including datafiles;

SQL> alter tablespace TEMP add tempfile '/u01/oradata/CDB1/pdb_new/temp01.dbf' size 10M reuse;

Leave a Reply