Oracle 12c nocdb轉換成cdb

chenoracle發表於2020-01-14

Oracle 12c nocdb 轉換成cdb

 

環境說明:

OS:Oracle Linux Server release 6.3

DB:Oracle 12.2.0.1.0

DBName:dapuchai

場景:

Oracle 11.2.0.4.0 升級到Oracle 12.2.0.1.0 ,預設是no-cdb 模式,升級後根據需要將no-cdb 轉換成cdb 裡,即將之前的11.2.0.4.0 資料完全遷移到PDB(Creating a PDB Using a Non-CDB)

實施方案:

一: 連線non-CDB(dapuchai) ,生成XML 格式資料庫描述檔案

二:DBCA 新建cdb 資料庫(cjcdb)

三: Plug in the non-CDB (cjcpdb)

四:執行 noncdb_to_pdb.sql

五:驗證資料

參考:

Oracle 12c nocdb轉換成cdb

一: 連線 non-CDB(dapuchai) ,生成 XML 格式資料庫描述檔案

Connect to the non-CDB, and run the  DBMS_PDB.DESCRIBE  procedure to construct an XML file that describes the non-CDB.

[root@cjc ~]# ps -ef|grep pmon

oracle    2677     1  0 22:35 ?        00:00:00 ora_pmon_dapuchai

root      3057  2634  0 22:37 pts/1    00:00:00 grep pmon

SQL> select name,cdb from v$database;

NAME         CDB

--------- ---

DAPUCHAI  NO

SQL> show pdbs

SQL> show con_id

CON_ID

------------------------------

0

SQL> shutdown immediate

---只讀方式開啟dapuchai資料庫

SQL> startup open read only;

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

NAME         OPEN_MODE              CDB

--------- -------------------- ---

DAPUCHAI  READ ONLY                NO

---生成xml 格式的資料庫描述檔案

SQL> BEGIN

  DBMS_PDB.DESCRIBE(pdb_descr_file => '/home/oracle/20200113.xml');

END;  2    3 

  4  /

PL/SQL procedure successfully completed.

Oracle 12c nocdb轉換成cdb

二: DBCA 新建 cdb 資料庫 (cjcdb)

[oracle@cjc ~]$ dbca

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

三: Plug in the non-CDB (cjcpdb)

[oracle@cjc oracle12]$ ps -ef|grep pmon

oracle    3106     1  0 22:38 ?        00:00:00 ora_pmon_dapuchai

oracle    4326     1  0 23:05 ?        00:00:00 ora_pmon_cjcdb

oracle    5651  3249  0 23:16 pts/1    00:00:00 grep pmon

[oracle@cjc ~]$ export ORACLE_SID=cjcdb

[oracle@cjc ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Mon Jan 13 23:18:52 2020

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

Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> show pdbs

    CON_ID CON_NAME                            OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

          2 PDB$SEED                       READ ONLY  NO

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

NAME         OPEN_MODE              CDB

--------- -------------------- ---

CJCDB        READ WRITE               YES

[oracle@cjc oradata]$ mkdir cjcpdb

[oracle@cjc oradata]$ cd cjcpdb/

[oracle@cjc cjcpdb]$ pwd

/u01/app/oracle12/oradata/cjcpdb

SQL> select name from v$dbfile;

NAME

--------------------------------------------------------------------------------

/u01/app/oracle12/oradata/cjcdb/users01.dbf

/u01/app/oracle12/oradata/cjcdb/undotbs01.dbf

/u01/app/oracle12/oradata/cjcdb/system01.dbf

/u01/app/oracle12/oradata/cjcdb/sysaux01.dbf

/u01/app/oracle12/oradata/cjcdb/pdbseed/system01.dbf

/u01/app/oracle12/oradata/cjcdb/pdbseed/sysaux01.dbf

/u01/app/oracle12/oradata/cjcdb/pdbseed/undotbs01.dbf

7 rows selected.

SQL> create pluggable database cjcpdb using '/home/oracle/20200113.xml' copy FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/dapuchai/', '/u01/app/oracle12/oradata/cjcpdb/');

Pluggable database created.

---資料檔案遷移完成

[oracle@cjc cjcpdb]$ pwd

/u01/app/oracle12/oradata/cjcpdb

[oracle@cjc cjcpdb]$ ll -rth

total 2.5G

-rw-r----- 1 oracle oinstall  58M Jan 13 23:26 temp01.dbf

-rw-r----- 1 oracle oinstall  11M Jan 13 23:26 ogg_temtbs01.dbf

-rw-r----- 1 oracle oinstall  11M Jan 13 23:26 ogg_tbs01.dbf

-rw-r----- 1 oracle oinstall  11M Jan 13 23:26 cjc_tbs01a.dbf

-rw-r----- 1 oracle oinstall  16M Jan 13 23:26 users01.dbf

-rw-r----- 1 oracle oinstall 446M Jan 13 23:26 undotbs01.dbf

-rw-r----- 1 oracle oinstall 1.2G Jan 13 23:26 system01.dbf

-rw-r----- 1 oracle oinstall 881M Jan 13 23:26 sysaux01.dbf

SQL> show pdbs

    CON_ID CON_NAME                            OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

          2 PDB$SEED                       READ ONLY  NO

          3 CJCPDB                            MOUNTED

四:執行 noncdb_to_pdb.sql

虛擬機器記憶體只分配4G ,並且是機械硬碟,指令碼執行了1 小時;

切換到PDB 並執行指令碼

SQL> alter session set container=cjcpdb;

SQL> @?/rdbms/admin/noncdb_to_pdb.sql

......

Oracle 12c nocdb轉換成cdb

......

Oracle 12c nocdb轉換成cdb

......

Oracle 12c nocdb轉換成cdb

---啟動pdb

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         3 CJCPDB                         MOUNTED

SQL> alter pluggable database cjcpdb open;

Pluggable database altered.

告警日誌檢視pdb 啟動過程;

Oracle 12c nocdb轉換成cdb

五:驗證資料

[oracle@cjc ~]$ cd /u01/app/oracle12/product/12.2.0.1/db_1/network/admin/

[oracle@cjc admin]$ vi tnsnames.ora

......

CJCPDB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = cjc)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = CJCPDB)

    )

  )

Oracle 12c nocdb轉換成cdb

---修改環境變數,指定cdb 例項

[oracle@cjc ~]$ vi .bash_profile

......

#export ORACLE_SID=dapuchai

export ORACLE_SID=cjcdb

......

[oracle@cjc ~]$ source .bash_profile

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb

---關掉no-cdb

Oracle 12c nocdb轉換成cdb

歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!

Oracle 12c nocdb轉換成cdb

Oracle 12c nocdb轉換成cdb




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2673268/,如需轉載,請註明出處,否則將追究法律責任。

相關文章