The document describes how to clone an existing pluggable database (PDB) in an Oracle multitenant container database (CDB) to create a new PDB. It involves opening the source PDB in read-only mode, running the CREATE PLUGGABLE DATABASE command specifying the source and target file paths, and then opening the new PDB. The process is demonstrated by cloning an existing local PDB called PDB001 to create a new PDB called PDB003, copying over the user, tables, and data.
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
How to create a pluggable database by cloning an existing local pdb
1. Articles from Database administrator
workshop
How to create a pluggable database by cloning an
existing local PDB
Using the CREATE PLUGGABLE DATABASE ... FROM command you can clone
an existing pluggable database (the source pdb) to create a new pdb (the clone
pdb).
The source pdb could be in the current local container or it can be located in a
remote container (in a next post): during a clone of a remote pdb you need to use a
database link referencing the remote container in the FROM clause.
Let's start cloning a local pluggable database. Be sure the current container is the
root
view plainprint?
1. SQL> show con_name;
2.
3. CON_NAME
4. ------------------------------
5. CDB$ROOT
Here are my current pluggable databases and I want to clone PDB001 which
contains the user MARCOV and the table T1 (with 100 rows)
view plainprint?
1. SQL> select name, open_mode from V$PDBS;
2.
3. NAME OPEN_MODE
4. ------------------------------ ----------
5. PDB$SEED READ ONLY
6. PDB001 READ WRITE
7. PDB002 READ WRITE
8.
9. SQL> alter session set container=PDB001;
10.
11. Session altered.
12.
13. SQL> create user marcov identified by marcov quota unlimited on users;
14.
15. User created.
16.
17. SQL> grant create session to marcov;
18.
19. Grant succeeded.
20.
21. SQL> grant create table to marcov;
22.
23. Grant succeeded.
24.
25. SQL> connect marcov/marcov@PDB001
26. Connected.
27. SQL> show user
28. USER is "MARCOV"
29. SQL> show con_name
30.
31. CON_NAME
32. ------------------------------
33. PDB001
34.
35. SQL> create table T1 (a number);
36.
37. Table created.
38.
39. SQL> create table T1 (a number);
40.
41. Table created.
42.
43. SQL> insert into T1 select level from dual connect by level < 101;
44.
45. 100 rows created.
46.
47. SQL> commit;
48.
49. Commit complete.
50.
51. SQL> connect / as sysdba
52. Connected.
53. SQL> show user
54. USER is "SYS"
55. SQL> show con_name
56.
57. CON_NAME
58. ------------------------------
59. CDB$ROOT
Here is the content of my tnsnames.ora file
view plainprint?
1. CDB001 =
3. After the command is sucessfully completed the status and the open mode of the
new pluggable database are NEW and MOUNTED.
view plainprint?
1. SQL> select PDB_NAME, STATUS from CDB_PDBS;
2.
3. PDB_NAME STATUS
4. ---------- -------------
5. PDB$SEED NORMAL
6. PDB001 NORMAL
7. PDB002 NORMAL
8. PDB003 NEW
9.
10. SQL> select name, open_mode from V$PDBS;
11.
12. NAME OPEN_MODE
13. ------------------------------ ----------
14. PDB$SEED READ ONLY
15. PDB001 READ ONLY
16. PDB002 READ WRITE
17. PDB003 MOUNTED
A new service is created too.
view plainprint?
1. SQL> select name, pdb from V$SERVICES order by creation_date;
2.
3. NAME PDB
4. -------------------- ------------------------------
5. CDB001XDB CDB$ROOT
6. SYS$BACKGROUND CDB$ROOT
7. CDB001 CDB$ROOT
8. SYS$USERS CDB$ROOT
9. pdb001 PDB001
10. pdb002 PDB002
11. pdb003 PDB003
You can now open both pluggable databases with one simply command (have a
look at this post for more information about the syntax and examples)
view plainprint?
1. SQL> alter pluggable database PDB001,PDB003 open READ WRITE FORCE;
2.
3. Pluggable database altered.
4.
5. SQL> select name, open_mode from V$PDBS;
6.
7. NAME OPEN_MODE
8. -------------------- ----------
9. PDB$SEED READ ONLY
10. PDB001 READ WRITE
11. PDB002 READ WRITE
12. PDB003 READ WRITE
13.
14. SQL> select PDB_NAME, STATUS from CDB_PDBS;
15.
16. PDB_NAME STATUS
17. ---------- -------------
18. PDB$SEED NORMAL
19. PDB001 NORMAL
20. PDB002 NORMAL
21. PDB003 NORMAL
Add the following entry on the tnsnames.ora file.
view plainprint?
1. PDB003 =
2. (DESCRIPTION =
3. (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))
4. (CONNECT_DATA =
5. (SERVER = DEDICATED)
6. (SERVICE_NAME = PDB003)
7. )
8. )
Let's see my data on PDB003 and on PDB001
view plainprint?
1. SQL> connect marcov/marcov@PDB003
2. Connected.
3. SQL> show con_name
4.
5. CON_NAME
6. ------------------------------
7. PDB003
8. SQL> select count(*) from marcov.T1;
9.
10. COUNT(*)
11. ----------
12. 100
13.
14. SQL> connect marcov/marcov@PDB001
15. Connected.
16. SQL> show con_name
17.
4. 18. CON_NAME
19. ------------------------------
20. PDB001
21. SQL> select count(*) from marcov.T1;
22.
23. COUNT(*)
24. ----------
25. 100
It is not possible to create a new pdb cloning a local or a remote seed: to create a
new pdb from the seed you have to follow this post. If you try to clone from the seed
template you will receive the ORA-65000 error, described below:
view plainprint?
1. SQL> create pluggable database PDB004 from PDB$SEED file_name_convert=('/app/oracle/oradata/CDB001/pdbseed','/app/oracle/oradata/CDB001/PDB004');
2. create pluggable database PDB004 from PDB$SEED file_name_convert=('/app/oracle/oradata/CDB001/pdbseed','/app/oracle/oradata/CDB001/PDB004')
3. *
4. ERROR at line 1:
5. ORA-65000: missing or invalid pluggable database name
6.
7. [oracle@localhost pdbseed]$ oerr ora 65000
8. 65000, 00000, "missing or invalid pluggable database name"
9. // *Cause: A valid pluggable database name was not present where required
10. // by the syntax of a CREATE PLUGGABLE DATABASE, ALTER PLUGGABLE
11. // DATABASE or DROP PLUGGABLE DATABASE statement.
12. // *Action: Reissue the statement with a valid pluggable database name.
That's all.