The
Container database cdb12c originally has one pluggable database testpdb (as
well as the seed PDB). We will see how we can plugin the 12C non-cdb database
testdb12c into the container database cdb12c.
Note
that to plugin a non-CDB database into a CDB, the non-CDB database needs to be
of version 12c as well. So existing 11g databases will need to be upgraded to
12c before they can be part of a 12c CDB.
Steps
involved.
The
first thing we need to do is to connect to the non-CDB, and run the
DBMS_PDB.DESCRIBE procedure to construct an XML file that contains the metadata
which describes the non-CDB.
We need to run this procedure while the
database is in a read only mode.
SQL>
shutdown immediate;
Database
closed.
SQL>
startup mount
ORACLE
instance started.
SQL>
alter database open read only;
Database
altered.
SQL> BEGIN
DBMS_PDB.DESCRIBE(
Now
shutdown and open the non-CDB in read write node. We need to then check if the
non-CDB is now ready for conversion into a Pluggable Database (PDD) which is
going to be contained in the Container Database.
Connect
to the CDB and run the DBMS_PDB.CHECK_PLUG_COMPATIBILITY package where we
provide the location of the XML metadata file which was generated in the first
step we executed.
  SQL> SET SERVEROUTPUT ON
NO
PL/SQL
procedure successfully completed.
Next
we shutdown the non-CDB and plug it in to the CDB by converting it to a
PLUGGABLE DATABASE.
SQL>
CREATE PLUGGABLE DATABASE testdb12c using '/home/oracle/testdb12c.xml'
nocopy
Pluggable
database created.
The
XML file accurately describes the current locations of the files of the PDB.
 Since we are using the existing 12c non-CDB datafiles to create the CDB
pluggable database , we will use the NOCOPY option.
If
we want, we can leave the existing 12c non-cdb database and clone that to
create a pluggable database
We
can see that the testdb12c database is now a PDB and is in a mounted state.
SQL>
select CON_ID, NAME, OPEN_MODE from V$PDBS;
    CON_ID NAME                
          OPEN_MODE
----------
------------------------------ ----------
SQL>
select  PDB_NAME, DBID , CON_ID, STATUS  from CDB_PDBS;
PDB_NAME
                  DBID  
  CON_ID STATUS
--------------------
---------- ---------- -------------
SQL>
ALTER SESSION SET CONTAINER =testdb12c;
Session
altered.
SQL>
show con_name
CON_NAME
------------------------------
Now
run the ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql script. 
This
script must be run before the PDB can be opened for the first time.
After
the script has been run open the PDB testdb12c in READ WRITE mode.
Now
check the status.
SQL>
alter session SET CONTAINER =CDB$ROOT;
Session
altered.
SQL>
 show con_name
CON_NAME
------------------------------
SQL>
select  PDB_NAME, DBID , CON_ID, STATUS  from CDB_PDBS;
PDB_NAME
                  DBID  
  CON_ID STATUS
--------------------
---------- ---------- -------------
3
rows selected.
Connect
to the newly plugged-in PDB testdb12c
[oracle@server-
testdb12c]$ sqlplus sh/sh@localhost:1525/testdb12c
SQL>
select count(*) from sales;
COUNT(*)
———-
Note that to plugin a non-CDB database into a CDB, the non-CDB database needs to be of version 12c as well. So existing 11g databases will need to be upgraded to 12c before they can be part of a 12c CDB.
Steps involved.
SQL> shutdown immediate;
SQL> startup mount
SQL> alter database open read only;
SQL> BEGIN
Now shutdown and open the non-CDB in read write node. We need to then check if the non-CDB is now ready for conversion into a Pluggable Database (PDD) which is going to be contained in the Container Database.
Connect to the CDB and run the DBMS_PDB.CHECK_PLUG_COMPATIBILITY package where we provide the location of the XML metadata file which was generated in the first step we executed.
SQL> SET SERVEROUTPUT ON
NO
PL/SQL procedure successfully completed.
Next we shutdown the non-CDB and plug it in to the CDB by converting it to a PLUGGABLE DATABASE.
SQL> CREATE PLUGGABLE DATABASE testdb12c using '/home/oracle/testdb12c.xml'
Pluggable database created.
The XML file accurately describes the current locations of the files of the PDB. Since we are using the existing 12c non-CDB datafiles to create the CDB pluggable database , we will use the NOCOPY option.
If we want, we can leave the existing 12c non-cdb database and clone that to create a pluggable database
We can see that the testdb12c database is now a PDB and is in a mounted state.
SQL> select CON_ID, NAME, OPEN_MODE from V$PDBS;
CON_ID NAME OPEN_MODE
SQL> select PDB_NAME, DBID , CON_ID, STATUS from CDB_PDBS;
PDB_NAME DBID CON_ID STATUS
SQL> ALTER SESSION SET CONTAINER =testdb12c;
SQL> show con_name
CON_NAME
Now run the ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql script.
After the script has been run open the PDB testdb12c in READ WRITE mode.
SQL> alter session SET CONTAINER =CDB$ROOT;
SQL> show con_name
SQL> select PDB_NAME, DBID , CON_ID, STATUS from CDB_PDBS;
3 rows selected.
Connect to the newly plugged-in PDB testdb12c
[oracle@server- testdb12c]$ sqlplus sh/sh@localhost:1525/testdb12c
SQL> select count(*) from sales;
COUNT(*)
 
No comments:
Post a Comment