探索Oracle之数据库升级七 11gR2 to 12c 升级完成后插入PDB

探索Oracle之数据库升级七
11gR2 to 12c
升级完成后插入PDB

前言:

       Oracle 12c开始,引入了容器数据库的概念,可以实现数据库插拔操作,如下图:
 

 
      现在我们就来看看如何将11.2.0.4的数据库插入到12cCDP里面去,让其成为一个PDB

数据库。

一、查看数据库信息:

 

  1. SQL> col BANNER format a80
  2. SQL> set line 300
  3. SQL> select * from v$version;

  4. BANNER CON_ID
  5. -------------------------------------------------------------------------------- ----------
  6. Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
  7. PL/SQL Release 12.1.0.1.0 - Production 0
  8. CORE 12.1.0.1.0 Production 0
  9. TNS for Linux: Version 12.1.0.1.0 - Production 0
  10. NLSRTL Version 12.1.0.1.0 - Production

  11. SQL> select cdb,name,dbid from v$database;

  12. CDB NAME DBID
  13. --- --------- ----------
  14. NO WOO 4199532651

     从这里我们可以看到实际上通过升级之后上来的数据库还是一个non-CDB,并非CDB数据库,那么这个时候我们需要在这个none-CDB库中生成用户PDBXML文件,再创建CDB数据库进行插入进去。

二、查看表空间及数据文件信息:

  1. SQL> select * from v$tablespace;

  2.        TS# NAME INC BIG FLA ENC CON_ID
  3. ---------- ------------------------------ --- --- --- --- ----------
  4.          0 SYSTEM YES NO YES 0
  5.          1 SYSAUX YES NO YES 0
  6.          2 UNDOTBS1 YES NO YES 0
  7.          4 USERS YES NO YES 0
  8.          3 TEMP NO NO YES 0

  9. SQL> set line 300
  10. SQL> col file_name format a40
  11. SQL> col tablespace_name format a10
  12. SQL> select tablespace_name,file_name from dba_data_files;

  13. TABLESPACE FILE_NAME
  14. ---------- ----------------------------------------
  15. USERS /DBData/woo/woo/users01.dbf
  16. UNDOTBS1 /DBData/woo/woo/undotbs01.dbf
  17. SYSAUX /DBData/woo/woo/sysaux01.dbf
  18. SYSTEM /DBData/woo/woo/system01.dbf

三、创建用于生成PDB的XML文件
  1. SQL> shutdown immediate
  2. Database closed.
  3. Database dismounted.
  4. ORACLE instance shut down.
  5. SQL> startup mount
  6. ORACLE instance started.

  7. Total System Global Area 2772574208 bytes
  8. Fixed Size 2292240 bytes
  9. Variable Size 2533361136 bytes
  10. Database Buffers 218103808 bytes
  11. Redo Buffers 18817024 bytes
  12. Database mounted.

  13. SQL> alter database open read only;
  14. Database altered.

  15. SQL> exec dbms_pdb.describe(pdb_descr_file => \‘/home/oracle/woo_ora11g.xml\‘);
  16. PL/SQL procedure successfully completed.

  17. SQL> host ls -rtl /home/oracle/woo*.xml
  18. -rw-r--r-- 1 oracle oinstall 4147 Nov 27 19:17 /home/oracle/woo_ora11g.xml

  19. SQL> shutdown immediate
  20. Database closed.
  21. Database dismounted.
  22. ORACLE instance shut down.

四、检查升级后的数据库是否适合以PDB的方式插入到CDB中

  1. SQL> set serveroutput on;
  2. SQL> declare
  3.   2         compat boolean := FALSE;
  4.   3 begin
  5.   4         compat := dbms_pdb.check_plug_compatibility(pdb_descr_file => \‘/home/oracle/woo_ora11g.xml\‘);
  6.   5     if compat
  7.   6     then
  8.   7         dbms_output.put_line(\‘YES\‘);
  9.   8     else
  10.   9         dbms_output.put_line(\‘No\‘);
  11.  10     end if;
  12.  11 end;
  13.  12 /

  14. No

  15. PL/SQL procedure successfully completed.

      因为是第一次插入,所以执行结果显示为NO,可以忽略继续插入。

五、创建CDB数据库
   5.1 执行dbca创建cdb数据库

    5.2 指定需要创建的cdb数据库名称

     5.3 创建CDB前检查

    5.4 Summar 点击Finish开始创建

    5.5  现在正在开始创建

  5.6 至此已经创建完成,告诉我们CDB数据库的信息

   5.7 点击Close 关闭创建页面


六、查看当前pdb信息

  1. [oracle@db01 ~]$ export ORACLE_SID=woo12c
  2. SQL> show pdbs;

  3.     CON_ID CON_NAME OPEN MODE RESTRICTED
  4. ---------- ------------------------------ ---------- ----------
  5.          2 PDB$SEED READ ONLY NO
  6.          3 PDB01 READ WRITE NO

  7. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;

  8.     CON_ID DBID NAME OPEN_MODE
  9. ---------- ---------- ------------------------------ ----------
  10.          2 4107385256 PDB$SEED READ ONLY
  11.          3 3926295770 PDB01 READ WRITE
七、将non-cdb数据库插入到cdb中成为一个pdb
  1. SQL> CREATE PLUGGABLE DATABASE woo_ora11g USING \‘/home/oracle/woo_ora11g.xml\‘;
  2. Pluggable database created.
八、查看alert日志相关信息
  
            Non-CDB插入到CDB中成为一个PDB输出的Alert 日志。
  1. CREATE PLUGGABLE DATABASE woo_ora11g USING ‘/home/oracle/woo_ora11g.xml‘
    Thu Nov 27 23:45:05 2014
    ****************************************************************
    Pluggable Database WOO_ORA11G with pdb id - 4 is created as UNUSABLE.
    If any errors are encountered before the pdb is marked as NEW,
    then the pdb must be dropped
    ****************************************************************
    Deleting old file#1 from file$
    Deleting old file#2 from file$
    Deleting old file#3 from file$
    Deleting old file#4 from file$
    Deleting old file#5 from file$
    Adding new file#13 to file$(old file#1)
    Adding new file#14 to file$(old file#2)
    Adding new file#15 to file$(old file#4)
    Marking tablespace #2 invalid since it is not present               in the describe file
    Marking tablespace #5 invalid since it is not present               in the describe file
    Successfully created internal service woo_ora11g at open
    ALTER SYSTEM: Flushing buffer cache inst=0 container=4 local
    ****************************************************************
    Post plug operations are now complete.
    Pluggable database WOO_ORA11G with pdb id - 4 is now marked as NEW.
    ****************************************************************
    Completed: CREATE PLUGGABLE DATABASE woo_ora11g USING ‘/home/oracle/woo_ora11g.xml‘

九、插入完成后查看pdbs信息

  1. SQL> show pdbs

  2.     CON_ID CON_NAME OPEN MODE RESTRICTED
  3. ---------- ------------------------------ ---------- ----------
  4.          2 PDB$SEED READ ONLY NO
  5.          3 PDB01 READ WRITE NO
  6.          4 WOO_ORA11G MOUNTED
  7. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;

  8.     CON_ID DBID NAME OPEN_MODE
  9. ---------- ---------- ------------------------------ ----------
  10.          2 4107385256 PDB$SEED READ ONLY
  11.          3 3926295770 PDB01 READ WRITE
  12.          4 4199532651 WOO_ORA11G MOUNTED

  13. 第一次no-cdb plug cdb是mount状态,需要将其open;
  14. SQL> alter pluggable database open;
  15. Pluggable database altered.

  16. SQL> show pdbs;

  17.     CON_ID CON_NAME OPEN MODE RESTRICTED
  18. ---------- ------------------------------ ---------- ----------
  19.          2 PDB$SEED READ ONLY NO
  20.          3 PDB01 MOUNTED
  21.          4 WOO_ORA11G READ WRITE YES

插入完成之后需要执行noncdb_to_pdb脚本,修复原non-cdb 和新的pdb不兼容的问题:

十、执行noncdb_pdb脚本
  1. SQL> alter session set container=WOO_ORA11G;
  2. Session altered.

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

  4. ………

  5. #### 遇到warning,脚本会自动忽略错误,继续执行。在最后脚本编译的时候会修复这些问题。

  6. 更新完之后需要同步pdb信息
  7. SQL> show pdbs

  8.     CON_ID CON_NAME OPEN MODE RESTRICTED
  9. ---------- ------------------------------ ---------- ----------
  10.          4 WOO_ORA11G MOUNTED
  11. SQL> alter pluggable database open restricted;

  12. Pluggable database altered.

  13. SQL> show pdbs

  14.     CON_ID CON_NAME OPEN MODE RESTRICTED
  15. ---------- ------------------------------ ---------- ----------
  16.          4 WOO_ORA11G READ WRITE YES
  17. SQL> exec dbms_pdb.sync_pdb();

  18. PL/SQL procedure successfully completed.

  19. SQL> alter pluggable database close immediate;

  20. Pluggable database altered.

  21. SQL> alter pluggable database open;

  22. Pluggable database altered.

十一、至此no-cdb plug to cdb 成功
  1. SQL> show pdbs;

  2.     CON_ID CON_NAME OPEN MODE RESTRICTED
  3. ---------- ------------------------------ ---------- ----------
  4.          2 PDB$SEED READ ONLY NO
  5.          3 PDB01 MOUNTED
  6.          4 WOO_ORA11G READ WRITE NO
  7. SQL>


 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。