NON-CDB转换为PDB

0.测试环境中一套11.2.0.4的数据库(SID=sdswhxcx),本地升级到了19C,最后打算将这个数据库转换成pdb。以下过程为主要的步骤。

1.先在升级后的19C环境中,创建一个CDB数据库(SID=cdb).
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         
2.针对NON-CDB数据库生成XML文件
[oracle@oem oradata]$ echo $ORACLE_SID
sdswhxcx
[oracle@oem oradata]$ sqlplus / as sysdba

SQL> shutdown immediate

SQL> startup open read only

SQL> BEGIN
  2  DBMS_PDB.DESCRIBE(pdb_descr_file => '/tmp/sdswhxcx.xml');
  3  END;
  4  /
PL/SQL procedure successfully completed.


SQL> shutdown immediate


3. 检测该数据库与当前CDB数据库的兼容性
[oracle@oem ~]$ export ORACLE_SID=cdb
[oracle@oem ~]$ sqlplus / as sysdba

SQL> SET SERVEROUTPUT ON;
DECLARE
SQL>   2  compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/tmp/sdswhxcx.xml')
  3  WHEN TRUE THEN 'YES'
  4  ELSE 'NO'
  5  END;
  6  BEGIN
  7  DBMS_OUTPUT.PUT_LINE(compatible);
  8  END;
  9  /
NO

PL/SQL procedure successfully completed.

SQL>

4. 查看兼容性失败的详细原因
SQL> col cause for a20
SQL> col name for a20
SQL> col message for a35 word_wrapped
SQL> select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS;
NAME                 CAUSE                TYPE      MESSAGE                             STATUS
-------------------- -------------------- --------- ----------------------------------- ---------
SDSWHXCX             Non-CDB to PDB       WARNING   PDB plugged in is a non-CDB,        PENDING
                                                    requires noncdb_to_pdb.sql be run.

SDSWHXCX             OPTION               ERROR     Database option APS mismatch: PDB   PENDING
                                                    installed version 19.0.0.0.0. CDB
                                                    installed version NULL.
在本示例中,由于数据库(SID=sdswhxcx)安装了APS组件,而CDB数据库未安装该组件,所以无法兼容。解决办法是删除数据库(SID=sdswhxcx)中的APS组件,最终需要满足兼容才能继续后续步骤。
SQL> SET SERVEROUTPUT ON;
SQL> DECLARE
  2  compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/tmp/sdswhxcx.xml')
  3  WHEN TRUE THEN 'YES'
  4  ELSE 'NO'
  5  END;
  6  BEGIN
  7  DBMS_OUTPUT.PUT_LINE(compatible);
  8  END;
  9  /
YES

PL/SQL procedure successfully completed.


5. 将数据库(SID=sdswhxcx)插入到CDB中
SQL> CREATE PLUGGABLE DATABASE sdswhxcx USING '/tmp/sdswhxcx.xml'
  2  COPY
  3  FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/sdswhxcx/', '/u01/app/oracle/oradata/CDB/sdswhxcx/');

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 SDSWHXCX                       MOUNTED
SQL>


6. 执行noncdb_to_pdb.sql脚本
SQL> ALTER SESSION SET CONTAINER=sdswhxcx;
Session altered.

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql


7. 打开新的pdb数据库,并保存当前状态
SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 SDSWHXCX                       READ WRITE NO
SQL> alter pluggable database all save state;

Pluggable database altered.





posted @ 2023-02-09 16:48  石云华  阅读(183)  评论(0编辑  收藏  举报