How to create a pluggable database by cloning an existing local pdb

643 views

Published on

How to create a pluggable database by cloning an existing local pdb

http://dbaworkshop.blogspot.com/2013/07/How-to-create-a-pluggable-database-by-cloning-an-existing-local-PDB.html

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
643
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

How to create a pluggable database by cloning an existing local pdb

  1. 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 =
  2. 2. 2. (DESCRIPTION = 3. (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521)) 4. (CONNECT_DATA = 5. (SERVER = DEDICATED) 6. (SERVICE_NAME = CDB001) 7. ) 8. ) 9. 10. PDB001 = 11. (DESCRIPTION = 12. (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521)) 13. (CONNECT_DATA = 14. (SERVER = DEDICATED) 15. (SERVICE_NAME = PDB001) 16. ) 17. ) To clone the source pluggable database PDB001 I need to open it in READ ONLY mode 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 pluggable database PDB001 open read only force; 10. 11. Pluggable database altered. On my file system I have the following directories and files. view plainprint? 1. [oracle@localhost CDB001]$ pwd 2. /app/oracle/oradata/CDB001 3. [oracle@localhost CDB001]$ ll 4. total 2163224 5. -rw-r-----. 1 oracle oinstall 17973248 Jul 30 13:12 control01.ctl 6. drwxr-x---. 2 oracle oinstall 4096 Jul 20 15:29 PDB001 7. drwxr-x---. 2 oracle oinstall 4096 Jul 20 16:22 PDB002 8. drwxr-x---. 2 oracle oinstall 4096 Jul 15 22:07 pdbseed 9. -rw-r-----. 1 oracle oinstall 52429312 Jul 30 13:12 redo01.log 10. -rw-r-----. 1 oracle oinstall 52429312 Jul 29 22:06 redo02.log 11. -rw-r-----. 1 oracle oinstall 52429312 Jul 30 02:32 redo03.log 12. -rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:11 sysaux01.dbf 13. -rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:06 system01.dbf 14. -rw-r-----. 1 oracle oinstall 76554240 Jul 30 13:11 temp01.dbf 15. -rw-r-----. 1 oracle oinstall 325066752 Jul 30 13:10 undotbs01.dbf 16. -rw-r-----. 1 oracle oinstall 5251072 Jul 30 02:37 users01.dbf Here is the content of PDB001 directory. view plainprint? 1. [oracle@localhost CDB001]$ ll PDB001/ 2. total 922516 3. -rw-r-----. 1 oracle oinstall 5251072 Jul 30 13:08 PDB001_users01.dbf 4. -rw-r-----. 1 oracle oinstall 665853952 Jul 30 13:08 sysaux01.dbf 5. -rw-r-----. 1 oracle oinstall 272637952 Jul 30 13:08 system01.dbf 6. -rw-r-----. 1 oracle oinstall 20979712 Jul 21 17:51 temp01.dbf I'm going to create a new pluggable database called PDB003, cloning PDB001. The command to clone a pluggable database locally is the following: view plainprint? 1. SQL> create pluggable database PDB003 from PDB001 file_name_convert=('/app/oracle/oradata/CDB001/PDB001','/app/oracle/oradata/CDB001/PDB003'); 2. 3. Pluggable database created. New files and directories are created. Note also the same name of the datafile PDB001_users01.dbf used as default tablespace for PDB003. view plainprint? 1. [oracle@localhost CDB001]$ ll 2. total 2163228 3. -rw-r-----. 1 oracle oinstall 17973248 Jul 30 13:19 control01.ctl 4. drwxr-x---. 2 oracle oinstall 4096 Jul 20 15:29 PDB001 5. drwxr-x---. 2 oracle oinstall 4096 Jul 20 16:22 PDB002 6. drwxr-x---. 2 oracle oinstall 4096 Jul 30 13:17 PDB003 7. drwxr-x---. 2 oracle oinstall 4096 Jul 15 22:07 pdbseed 8. -rw-r-----. 1 oracle oinstall 52429312 Jul 30 13:18 redo01.log 9. -rw-r-----. 1 oracle oinstall 52429312 Jul 29 22:06 redo02.log 10. -rw-r-----. 1 oracle oinstall 52429312 Jul 30 02:32 redo03.log 11. -rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:18 sysaux01.dbf 12. -rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:17 system01.dbf 13. -rw-r-----. 1 oracle oinstall 76554240 Jul 30 13:18 temp01.dbf 14. -rw-r-----. 1 oracle oinstall 325066752 Jul 30 13:16 undotbs01.dbf 15. -rw-r-----. 1 oracle oinstall 5251072 Jul 30 02:37 users01.dbf 16. [oracle@localhost CDB001]$ ll PDB003 17. total 921688 18. -rw-r-----. 1 oracle oinstall 5251072 Jul 30 13:18 PDB001_users01.dbf 19. -rw-r-----. 1 oracle oinstall 665853952 Jul 30 13:18 sysaux01.dbf 20. -rw-r-----. 1 oracle oinstall 272637952 Jul 30 13:18 system01.dbf 21. -rw-r-----. 1 oracle oinstall 20979712 Jul 30 13:17 temp01.dbf
  3. 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. 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.

×