Skip to content
Home » Oracle Database » How Oracle Rename PDB

How Oracle Rename PDB

Rename Pluggable Database

After creating a new PDB or cloning a remote PDB, you might want to change its name for your own purpose. In this post, there're two ways to change the name of a PDB, you can either:

  1. Change PDB name in CDB or
  2. Change PDB name in PDB.

In CDB

We can manage every PDB in the container database (CDB), including changing its name.

Check Current PDB Status

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ WRITE NO

Since changing the name of a PDB is actually a process of renaming GLOBAL_NAME of a PDB, we should make the PDB restricted to user sessions first.

Enable Restricted Mode

Before we rename its GLOBAL_NAME, we need to enable restricted mode of the PDB.

SQL> alter pluggable database ORCLPDB1 open restricted force;

Pluggable database altered.

Here we use FORCE keyword to enable restricted mode on the PDB.

Please note that, for RAC databases with multiple instances, we should close the target PDB on all instances, then open it in restricted mode only on one instance.

SQL> alter pluggable database ORCLPDB1 close immediate instances=all;

Pluggable database altered.

SQL> alter pluggable database ORCLPDB1 open restricted;

Pluggable database altered.

Check Current Status

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ WRITE YES

As you can see, RESTRICTED now becomes YES, so we can safely rename GLOBAL_NAME.

Change GLOBAL_NAME

SQL> alter pluggable database ORCLPDB1 rename global_name to ORCLPDBX;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDBX                       READ WRITE YES

If you saw error ORA-65025, you may check how we solved ORA-65025 when renaming a PDB.

The PDB name has been changed. From now on, we should use the new name to operate the PDB.

Disable Restricted Mode

For later public connections, we have to disable restricted mode with the new PDB name.

SQL> alter pluggable database orclpdbx open force;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDBX                       READ WRITE NO

Check Listener

[oracle@test ~]$ lsnrctl status
...
Service "orclpdbx" has 1 instance(s).
  Instance "ORCLCDB", status READY, has 1 handler(s) for this service...

Looking good! The new service name is working.

Please note that, even though the PDB name has been changed, the path of data files does not change. They are still in the original directory.

[oracle@test ~]$ ll /u01/app/oracle/oradata/ORCLCDB/ORCLPDB1
total 1075024
-rw-r----- 1 oracle oinstall 209723392 Jan 17 01:48 example01.dbf
-rw-r----- 1 oracle oinstall 398467072 May  7 01:51 sysaux01.dbf
-rw-r----- 1 oracle oinstall 346038272 May  7 02:17 system01.dbf
-rw-r----- 1 oracle oinstall  51388416 Dec 16  2020 temp01.dbf
-rw-r----- 1 oracle oinstall 136323072 May  7 02:17 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Jan 17 01:48 users01.dbf

They remain no change.

In PDB

Here we treat the PDB as a normal, typical database (non-CDB).

Log into the PDB.

[oracle@test ~]$ sqlplus [email protected]:1521/ORCLPDB1 as sysdba
...
Enter password:
...

Enable Restricted Mode

SQL> alter system enable restricted session;

System altered.

Check Current PDB Name

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
ORCLPDB1

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ORCLPDB1                       READ WRITE YES

Change GLOBAL_NAME

SQL> alter database rename global_name to ORCLPDBX;

Database altered.

Disable Restricted Mode

SQL> alter system disable restricted session;

System altered.

Check the Result

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
ORCLPDBX

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ORCLPDBX                       READ WRITE NO

Use New PDB Name

[oracle@test ~]$ sqlplus [email protected]:1521/ORCLPDBX as sysdba

We're done.

If you have ever save the state for opening the PDB automatically, you have to do it again.

Leave a Reply

Your email address will not be published. Required fields are marked *