Skip to content
Home » Oracle » How to Create PDB from Another PDB

How to Create PDB from Another PDB

Create Pluggable Database from Another PDB

Cloning a new PDB from another PDB for testing purpose in the same CDB is a very common practice during development phase of an IT project.

For cloning a PDB to a remote CDB, you may refer to: How to Clone PDB to Another CDB.

To create a PDB from another PDB, we may take the following steps:

  1. Close the source PDB.
  2. Open the source PDB to READ ONLY.
  3. Clone the target PDB from the source PDB with FILE_NAME_CONVERT.
  4. Open Both PDB to READ WRITE.

Before cloning, let's see the current status of all PDB.

[oracle@test1 ~]$ sqlplus / as sysdba
...
SQL> show pdbs;

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

Just remember, we are on the host test1. And we choose FINANPDB as our source PDB.

Please note that, if the CDB is in shared undo mode, then the source PDB must be in open read-only. That is to say, if your CDB is local undo mode, then you can skip step 1 and step 2. For your reference, there're more about how to switch CDB into local undo mode.

Close the source PDB.

SQL> alter pluggable database finanpdb close immediate;

Pluggable database altered.

Open the source PDB to READ ONLY.

SQL> alter pluggable database finanpdb open read only;

Pluggable database altered.

SQL> show pdbs;

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

Clone the target PDB from the source PDB with FILE_NAME_CONVERT.

SQL> create pluggable database finance_pdb from finanpdb storage unlimited tempfile reuse file_name_convert=('FINANPDB', 'FINANCE_PDB');

Pluggable database created.

Actually, we don't have to specify STORAGE UNLIMITED for the target PDB, because it's unlimited by default. On the other side, TEMPFILE REUSE might be necessary in case of existing tempfiles.

Please note that, the values of FILE_NAME_CONVERT should be case-sensitive. Otherwise, the clone may fail with ORA-65005: missing or invalid file name pattern for file.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 FINANPDB                       READ ONLY  NO
         4 FINANCE_PDB                    MOUNTED

Parallelism

You can add some degrees of parallelism to speed up the creation.

SQL> create pluggable database finance_pdb from finanpdb storage unlimited tempfile reuse file_name_convert=('FINANPDB', 'FINANCE_PDB') parallel 8;

Pluggable database created.

Open Both PDB to READ WRITE.

Target PDB

SQL> alter pluggable database FINANCE_PDB open;

Pluggable database altered.

Source PDB

SQL> alter pluggable database FINANPDB open force;

Pluggable database altered.

Next, we check the result.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 FINANPDB                       READ WRITE NO
         4 FINANCE_PDB                    READ WRITE NO

As you can see, the cloning is actually a creation of database from a source one.

Later on, if don't like its name, you still have chances to rename the PDB. Moreover, you can add a service name to the PDB or switch a service name from other PDB to this one.

Leave a Reply

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