Oracle 12C Non-CDB database switching to CDB test

Keywords: Database SQL Oracle xml

If the database is upgraded from 11g to 12c, or created in 12c, that is NON CDB, then such a database is a common single instance, and there is no difference from the database before 12c, but the characteristics of 12C is CDB management, so since the 12c, or to switch to CDB management.

So the next test step is to switch NON CDB to CDB.

1. Current environmental description

Two instances have been started in the current database: bishuo and test.

bishuo:/home/oracle@oracle>ps -ef |grep pmon
oracle     3666      1  0 13:25 ?        00:00:00 ora_pmon_bishuo
oracle     4507      1  0 13:49 ?        00:00:00 ora_pmon_test
oracle     4693 189245  0 13:49 pts/1    00:00:00 grep pmon

The bishuo database is a 12C CDB database:

SQL> select name,CDB from v$database;

NAME	  CDB
--------- ---
BISHUO	  YES

The test database is a 12C non-cdb database

SQL> select name,CDB from v$database;

NAME	  CDB
--------- ---
TEST	  NO

SQL> set lin 130;
SQL> select * from v$version;

BANNER                                             CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production          0
PL/SQL Release 12.1.0.2.0 - Production                              0
CORE    12.1.0.2.0    Production                              0
TNS for Linux: Version 12.1.0.2.0 - Production                          0
NLSRTL Version 12.1.0.2.0 - Production                              0 

2. Start switching
2.1 Cleanly shutdown database and open it with read only

SQL> select name,cdb from v$database;

NAME	  CDB
--------- ---
TEST	  NO

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup open read only;
ORACLE instance started.

Total System Global Area 6442450944 bytes
Fixed Size		    4511656 bytes
Variable Size		 1124075608 bytes
Database Buffers	 5301600256 bytes
Redo Buffers		   12263424 bytes
Database mounted.
Database opened.

SQL> select name,open_mode,cdb from v$database;

NAME	  OPEN_MODE	       CDB
--------- -------------------- ---
TEST	  READ ONLY	       NO

2.2 Generate database description file in xml format

SQL> BEGIN
  DBMS_PDB.DESCRIBE(pdb_descr_file => '/tmp/test.xml');
END;
/  2    3    4  

PL/SQL procedure successfully completed.

2.3 Close the database

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2.4 Connect CDB and create PDB


bishuo:/home/oracle@oracle>sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Tue Nov 21 14:02:06 2017

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select name,open_mode,cdb from v$database;

NAME	  OPEN_MODE	       CDB
--------- -------------------- ---
BISHUO	  READ WRITE	       YES


//Create PDB:

SQL> select con_id,dbid,name,open_mode from v$pdbs;

    CON_ID	 DBID NAME			     OPEN_MODE
---------- ---------- ------------------------------ ----------
	 2 1534143422 PDB$SEED			     READ ONLY

SQL> CREATE PLUGGABLE DATABASE test USING '/tmp/test.xml'
COPY
FILE_NAME_CONVERT = ('/home/oracle/oradata/12ctest/TEST/', '//home/oracle/oradata/bishuo/test/');  2    3  

Pluggable database created.
//The database replication was successful:
test:/home/oracle/oradata/bishuo/test@oracle>pwd
/home/oracle/oradata/bishuo/test
test:/home/oracle/oradata/bishuo/test@oracle>ls
sysaux01.dbf  system01.dbf  temp01.dbf  users01.dbf 

2.5 Switch to PDB and execute scripts

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 TEST 			  MOUNTED
SQL> alter session set container=test;
Session altered.

- Execute scripts:
sql> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

This script takes a little longer, about 20 minutes to execute.


2.6 Start PDB and check status

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 TEST                           MOUNTED
SQL> show con_name 

CON_NAME
------------------------------
TEST
SQL> alter pluggable database test open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 TEST                           READ WRITE NO
SQL> SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
TEST                           READ WRITE

1 row selected.

//This is the test data previously inserted:
SQL> select * from test;

        ID NAME
---------- ----------
         1 shiyu

1 row selected.





Posted by benzrf on Thu, 07 Feb 2019 07:54:19 -0800