How to Clone Local PDB

  • by

Clone Local PDB

This time, we'd like to clone a PDB for testing purpose in the same CDB on DB level.

[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.

1. Close the source PDB.

SQL> alter pluggable database finanpdb close immediate;

Pluggable database altered.

2. 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

3. 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.

4. Open the target PDB to READ WRITE.

SQL> alter pluggable database finance_pdb open;

Pluggable database altered.

SQL> show pdbs;

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

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

For cloning a PDB remotely, you may refer to: How to Clone Remote PDB.

Leave a Reply

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