Oracle Database 12c: How to create a pdb from a non-cdb using dbms_pdb package

498 views

Published on

Oracle Database 12c: How to create a pdb from a non cdb using dbms pdb package

http://dbaworkshop.blogspot.it/2013/08/How-to-create-a-PDB-from-a-Non-CDB-using-DBMS-PDB-package.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
498
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oracle Database 12c: How to create a pdb from a non-cdb using dbms_pdb package

  1. 1. Articles from Database administrator workshop How to create a PDB from a Non-CDB using DBMS_PDB package To test this scenario I have recently created using DBCA a non container database named ORCL. CDB001 and CDBTEST are instead two container databases. view plainprint? 1. [oracle@vsi08devpom ~]$ ps -ef|grep smon 2. oracle 4081 1 0 Jul15 ? 00:01:30 ora_smon_CDB001 3. oracle 11394 1 0 10:20 ? 00:00:00 ora_smon_ORCL 4. oracle 12586 9609 0 10:46 pts/0 00:00:00 grep smon 5. oracle 16455 1 0 Jul17 ? 00:01:34 ora_smon_CDBTEST I want to consolidate this database plugging it into a container database. In this scenario I'm going to use the DBMS_PDB package to create the XML file with the metadata of ORCL database. Before using the DBMS_PDB.DESCRIBE procedure, the ORCL database needs to be in READ ONLY mode. view plainprint? 1. [oracle@vsi08devpom ~]$ export ORACLE_SID=ORCL 2. [oracle@vsi08devpom ~]$ sqlplus / as sysdba 3. 4. SQL*Plus: Release 12.1.0.1.0 Production on Wed Aug 7 10:47:29 2013 5. 6. Copyright (c) 1982, 2013, Oracle. All rights reserved. 7. 8. Connected to: 9. Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 10. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options 11. 12. SQL@ORCL> show con_name; 13. 14. CON_NAME 15. ------------------------------ 16. Non Consolidated 17. SQL@ORCL> select name, open_mode from V$DATABASE; 18. 19. NAME OPEN_MODE 20. --------- -------------------- 21. ORCL READ WRITE 22. 23. SQL@ORCL> shutdown immediate; 24. Database closed. 25. Database dismounted. 26. ORACLE instance shut down. 27. 28. SQL@ORCL> startup mount; 29. ORACLE instance started. 30. 31. Total System Global Area 471830528 bytes 32. Fixed Size 2289688 bytes 33. Variable Size 264245224 bytes 34. Database Buffers 197132288 bytes 35. Redo Buffers 8163328 bytes 36. Database mounted. 37. SQL@ORCL> alter database open read only; 38. 39. Database altered. view plainprint? 1. SQL@ORCL> begin 2. 2 dbms_pdb.describe( pdb_descr_file => '/opt/app/oracle/oradata/orcl.xml'); 3. 3 end; 4. 4 / 5. 6. PL/SQL procedure successfully completed. 7. 8. SQL@ORCL> host ls /opt/app/oracle/oradata/orcl* 9. /opt/app/oracle/oradata/orcl.xml 10. 11. SQL@ORCL> shutdown immediate; 12. Database closed. 13. Database dismounted. 14. ORACLE instance shut down. 15. SQL@ORCL> exit Now connect to the container database. In my case I want to plug ORCL database into the CDBTEST container. It currently contains 4 pluggable databases. view plainprint? 1. [oracle@vsi08devpom ~]$ export ORACLE_SID=CDBTEST 2. [oracle@vsi08devpom ~]$ sqlplus / as sysdba 3. 4. SQL*Plus: Release 12.1.0.1.0 Production on Wed Aug 7 11:07:12 2013 5. 6. Copyright (c) 1982, 2013, Oracle. All rights reserved. 7. 8. Connected to: 9. Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 10. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options 11. 12. SQL@CDBTEST> show con_name; 13. 14. CON_NAME 15. ------------------------------ 16. CDB$ROOT 17. 18. SQL@CDBTEST> select name, open_mode from V$PDBS; 19. 20. NAME OPEN_MODE 21. ------------------------------ ---------- 22. PDB$SEED READ ONLY 23. PDBTEST1 READ WRITE
  2. 2. 24. PDBTEST2 READ WRITE 25. PDBTEST3 READ WRITE 26. PDB003 READ ONLY Here is the situation of the directories for the CDBTEST container database: view plainprint? 1. [oracle@vsi08devpom ~]$ cd /opt/app/oracle/oradata/CDBTEST/ 2. [oracle@vsi08devpom CDBTEST]$ ll 3. total 3459784 4. -rw-r----- 1 oracle oinstall 17973248 Aug 7 11:13 control01.ctl 5. drwxr-x--- 2 oracle oinstall 4096 Aug 1 14:54 PDB003 6. drwxr-x--- 2 oracle oinstall 4096 Jul 17 11:25 pdbseed 7. drwxr-x--- 2 oracle oinstall 4096 Jul 17 13:16 PDBTEST1 8. drwxr-x--- 2 oracle oinstall 4096 Jul 17 13:17 PDBTEST2 9. drwxr-x--- 2 oracle oinstall 4096 Jul 17 13:18 PDBTEST3 10. -rw-r----- 1 oracle oinstall 52429312 Aug 7 11:12 redo01.log 11. -rw-r----- 1 oracle oinstall 52429312 Aug 7 00:16 redo02.log 12. -rw-r----- 1 oracle oinstall 52429312 Aug 7 06:00 redo03.log 13. -rw-r----- 1 oracle oinstall 1310728192 Aug 7 11:12 sysaux01.dbf 14. -rw-r----- 1 oracle oinstall 828383232 Aug 7 11:12 system01.dbf 15. -rw-r----- 1 oracle oinstall 63971328 Aug 7 11:01 temp01.dbf 16. -rw-r----- 1 oracle oinstall 1205870592 Aug 7 11:12 undotbs01.dbf 17. -rw-r----- 1 oracle oinstall 5251072 Aug 7 06:05 users01.dbf Now you can plug the ORCL database into the CDBTEST container database using the usual syntax (have a look at this post) view plainprint? 1. SQL@CDBTEST> create pluggable database ORCL using '/opt/app/oracle/oradata/orcl.xml' copy file_name_convert=('/opt/app/oracle/oradata/ORCL','/opt/app/oracle/oradata/CDBTEST/ORCL'); 2. 3. Pluggable database created. The Oracle software copies under the directory /opt/app/oracle/oradata/CDBTEST/ORCL all the datafiles coming from /opt/app/oracle/oradata/ORCL location. view plainprint? 1. [oracle@vsi08devpom CDBTEST]$ ll 2. total 3459788 3. -rw-r----- 1 oracle oinstall 17973248 Aug 7 12:10 control01.ctl 4. drwxr-x--- 2 oracle oinstall 4096 Aug 7 11:49 ORCL 5. drwxr-x--- 2 oracle oinstall 4096 Aug 1 14:54 PDB003 6. drwxr-x--- 2 oracle oinstall 4096 Jul 17 11:25 pdbseed 7. drwxr-x--- 2 oracle oinstall 4096 Jul 17 13:16 PDBTEST1 8. drwxr-x--- 2 oracle oinstall 4096 Jul 17 13:17 PDBTEST2 9. drwxr-x--- 2 oracle oinstall 4096 Jul 17 13:18 PDBTEST3 10. -rw-r----- 1 oracle oinstall 52429312 Aug 7 12:10 redo01.log 11. -rw-r----- 1 oracle oinstall 52429312 Aug 7 00:16 redo02.log 12. -rw-r----- 1 oracle oinstall 52429312 Aug 7 06:00 redo03.log 13. -rw-r----- 1 oracle oinstall 1310728192 Aug 7 12:10 sysaux01.dbf 14. -rw-r----- 1 oracle oinstall 828383232 Aug 7 12:07 system01.dbf 15. -rw-r----- 1 oracle oinstall 63971328 Aug 7 12:03 temp01.dbf 16. -rw-r----- 1 oracle oinstall 1205870592 Aug 7 12:10 undotbs01.dbf 17. -rw-r----- 1 oracle oinstall 5251072 Aug 7 06:05 users01.dbf A new pluggable database is created with a NEW status view plainprint? 1. SQL@CDBTEST> select pdb_id, pdb_name, dbid, status, creation_scn, con_id from CDB_PDBS; 2. 3. PDB_ID PDB_NAME DBID STATUS CREATION_SCN CON_ID 4. ---------- ---------- ---------- ------------- ------------ ---------- 5. 2 PDB$SEED 4063610283 NORMAL 217 1 6. 3 PDBTEST1 3064465721 NORMAL 1547881 1 7. 4 PDBTEST2 2395404598 NORMAL 1548944 1 8. 5 PDBTEST3 2434165039 NORMAL 1550036 1 9. 6 PDB003 1448206714 NORMAL 2744910 1 10. 7 ORCL 1350603571 NEW 3226095 1 It's still not the time to open the new PDB. You need first to execute, while connected to the new pluggable database, the script $ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql: view plainprint? 1. [oracle@vsi08devpom CDBTEST]$ ll /opt/app/oracle/product/12.1.0/db_1/rdbms/admin/noncdb_to_pdb.sql 2. -rw-r--r-- 1 oracle oinstall 19191 Apr 15 22:27 /opt/app/oracle/product/12.1.0/db_1/rdbms/admin/noncdb_to_pdb.sql 3. 4. SQL@CDBTEST> alter session set container=ORCL; 5. 6. Session altered. 7. 8. SQL@CDBTEST> @/opt/app/oracle/product/12.1.0/db_1/rdbms/admin/noncdb_to_pdb.sql 9. SQL@CDBTEST> SET SERVEROUTPUT ON 10. SQL@CDBTEST> SET FEEDBACK 1 11. SQL@CDBTEST> SET NUMWIDTH 10 12. ... 13. ... 14. ... 15. SQL@CDBTEST> -- leave the PDB in the same state it was when we started 16. SQL@CDBTEST> BEGIN 17. 2 execute immediate '&open_sql &restricted_state'; 18. 3 EXCEPTION 19. 4 WHEN OTHERS THEN 20. 5 BEGIN 21. 6 IF (sqlcode <> -900) THEN 22. 7 RAISE; 23. 8 END IF; 24. 9 END; 25. 10 END; 26. 11 / 27. 28. PL/SQL procedure successfully completed. 29. 30. SQL@CDBTEST> 31. SQL@CDBTEST> WHENEVER SQLERROR CONTINUE; 32. SQL@CDBTEST> Now you can open the new ORCL pluggable database. view plainprint? 1. SQL@CDBTEST> show con_name; 2.
  3. 3. 3. CON_NAME 4. ------------------------------ 5. ORCL 6. SQL@CDBTEST> alter database open; 7. 8. Database altered. The database is so available and ready to be used. view plainprint? 1. SQL@CDBTEST> select pdb_id, pdb_name, dbid, status, creation_scn, con_id from CDB_PDBS; 2. 3. PDB_ID PDB_NAME DBID STATUS CREATION_SCN CON_ID 4. ---------- ---------- ---------- ------------- ------------ ---------- 5. 2 PDB$SEED 4063610283 NORMAL 217 1 6. 3 PDBTEST1 3064465721 NORMAL 1547881 1 7. 4 PDBTEST2 2395404598 NORMAL 1548944 1 8. 5 PDBTEST3 2434165039 NORMAL 1550036 1 9. 6 PDB003 1448206714 NORMAL 2744910 1 10. 7 ORCL 1350603571 NORMAL 3226095 1 That's all.

×