如果把数据库从11g 升级到12c,或者在12c中创建的,就是NON CDB,那么这样的数据库就是普通的单实例,和12c 之前的数据库没有区别,但12c 的特点就是CDB 管理,所以既然上12c,还是要切换成CDB 进行管理。
所以下面的测试步骤,就是把NON CDB 切换成CDB的步骤。
1 当前环境说明
当前数据库里已经启动了2个实例: cndba 和 dave。
[oracle@Ora12c dbs]$ ps -ef|grep ora_smon oracle 15219 1 0 Apr22 ? 00:00:00 ora_smon_cndba oracle 15516 1 0 Apr22 ? 00:00:01 ora_smon_dave oracle 25999 25592 0 07:35 pts/1 00:00:00 grep ora_smon[oracle@Ora12c dbs]$
DAVE 是12c 的CDB 数据库:
SQL> select name,CDB from v$database; NAME CDB --------- --- DAVE YES
CNDBA 是non cdb 数据库:
SQL> select name,cdb from v$database; NAME CDB --------- --- CNDBA 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 开始切换
2.1 Cleanly shutdown 数据库并用read only 打开
SQL> select name,cdb from v$database; NAME CDB --------- --- CNDBA NO SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup open read only ORACLE instance started. Total System Global Area 1224736768 bytes Fixed Size 2923824 bytes Variable Size 436208336 bytes Database Buffers 771751936 bytes Redo Buffers 13852672 bytes Database mounted. Database opened. SQL> select name,open_mode,cdb from v$database; NAME OPEN_MODE CDB --------- -------------------- --- CNDBA READ ONLY NO
2.2 生成xml格式的数据库描述文件
SQL> BEGIN DBMS_PDB.DESCRIBE(pdb_descr_file => '/tmp/CNDBA.xml'); END; / PL/SQL procedure successfully completed.
查看XML 文件:http://www.cndba.cn/cndba/dave/article/220
[oracle@Ora12c tmp]$ ll -h CNDBA.xml -rw-r--r--. 1 oracle oinstall 6.8K Apr 23 09:10 CNDBA.xml[oracle@Ora12c tmp]$ cat CNDBA.xml |more <?xml version="1.0" encoding="UTF-8"?> <PDB> <xmlversion>1</xmlversion> <pdbname>cndba</pdbname> <cid>0</cid> <byteorder>1</byteorder> <vsn>202375680</vsn> <vsns> <vsnnum>12.1.0.2.0</vsnnum> <cdbcompt>12.1.0.2.0</cdbcompt> <pdbcompt>12.1.0.2.0</pdbcompt> <vsnlibnum>0.0.0.0.22</vsnlibnum> <vsnsql>22</vsnsql> <vsnbsv>8.0.0.0.0</vsnbsv> </vsns> <dbid>142169581</dbid> <ncdb2pdb>1</ncdb2pdb> <cdbid>142169581</cdbid> <guid>144C163289BF0781E0531E02A8C0AFE3</guid> <uscnbas>1750676</uscnbas> <uscnwrp>0</uscnwrp> <rdba>4194824</rdba> <tablespace> <name>SYSTEM</name> <type>0</type> <tsn>0</tsn> <status>1</status> <issft>0</issft> <file> <path>/u01/app/oracle/oradata/CNDBA/datafile/o1_mf_system_bmgm6d53_.dbf</path> ….
2.3 关闭数据库http://www.cndba.cn/cndba/dave/article/220
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down.
2.4 连接CDB并创建PDBhttp://www.cndba.cn/cndba/dave/article/220
[oracle@Ora12c ~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Thu Apr 23 09:16:02 2015 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 --------- -------------------- --- DAVE READ WRITE YES SQL> 创建PDB: SQL> alter session set container=PDB1; Session altered. SQL> select file_name from dba_data_files; FILE_NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/dave/pdb1/system01.dbf /u01/app/oracle/oradata/dave/pdb1/sysaux01.dbf /u01/app/oracle/oradata/dave/pdb1_users02.dbf /u01/app/oracle/oradata/dave/pdb1/ado1.dbf /u01/app/oracle/oradata/dave/pdb1/ado2.dbf /u01/app/oracle/oradata/dave/pdb1/cndba01.dbf[oracle@Ora12c tmp]$ mkdir -p /u01/app/oracle/oradata/dave/cndba SQL> CREATE PLUGGABLE DATABASE cndba USING '/tmp/CNDBA.xml' COPY FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CNDBA/datafile/', '/u01/app/oracle/oradata/dave/cndba/'); CREATE PLUGGABLE DATABASE cndba USING '/tmp/CNDBA.xml' * ERROR at line 1: ORA-01276: Cannot add file /u01/app/oracle/oradata/dave/cndba/o1_mf_system_bmgm6d53_.dbf. File has an Oracle Managed Files file name. 这里报错,说文件是OMF 管理的,不能添加到新位置。 这里可以指定NOCOPY,从而不进行convert,也可以单个指定。 CREATE PLUGGABLE DATABASE cndba USING '/tmp/CNDBA.xml' NOCOPY; 我们这里数据文件不错,也保留这个CDB 的环境,所以单个指定数据文件,完成创建。 SQL> CREATE PLUGGABLE DATABASE cndba USING '/tmp/CNDBA.xml' COPY FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CNDBA/datafile/o1_mf_sysaux_bmgm4yrq_.dbf', '/u01/app/oracle/oradata/dave/cndba/sysaux.dbf', '/u01/app/oracle/oradata/CNDBA/datafile/o1_mf_system_bmgm6d53_.dbf', '/u01/app/oracle/oradata/dave/cndba/system.dbf', '/u01/app/oracle/oradata/CNDBA/datafile/o1_mf_temp_bmgm9xqf_.tmp', '/u01/app/oracle/oradata/dave/cndba/temp.dbf', '/u01/app/oracle/oradata/CNDBA/datafile/o1_mf_undotbs1_bmgm8glj_.dbf', '/u01/app/oracle/oradata/dave/cndba/undotbs1.dbf', '/u01/app/oracle/oradata/CNDBA/datafile/ado1.dbf', '/u01/app/oracle/oradata/dave/cndba/ado1.dbf', '/u01/app/oracle/oradata/CNDBA/datafile/ado1.dbf', '/u01/app/oracle/oradata/dave/cndba/ado1.dbf', '/u01/app/oracle/oradata/CNDBA/datafile/o1_mf_users_bmgm8ffh_.dbf', '/u01/app/oracle/oradata/dave/cndba/users.dbf'); Pluggable database created. 数据文件复制成功:[root@Ora12c cndba]# pwd /u01/app/oracle/oradata/dave/cndba[root@Ora12c cndba]# ls ado1.dbf ado2.dbf sysaux.dbf system.dbf temp.dbf users.dbf[root@Ora12c cndba]#
2.5 切换到PDB并执行脚本http://www.cndba.cn/cndba/dave/article/220
SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1 READ WRITE NO 4 CNDBA MOUNTED SQL> SQL> alter session set container=CNDBA; Session altered. --执行脚本: sql> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql …..刷屏….. …..约30分钟…..
2.6 启动PDB并检查状态
SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 4 CNDBA MOUNTED SQL> show con_name CON_NAME ------------------------------ CNDBA SQL> alter pluggable database open; Warning: PDB altered with errors. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 4 CNDBA READ WRITE YES SQL> SELECT name, open_mode FROM v$pdbs; NAME OPEN_MODE ------------------------------ ---------- CNDBA READ WRITE 1 row selected. DB已经成功的从NON CDB 切换到了PDB。
2.7 分析处理最后的警告
最后open pdb的时候报了个错误,查看一下:
alter pluggable database open Thu Apr 23 10:35:54 2015 Database Characterset for CNDBA is ZHS16GBK *************************************************************** WARNING: Pluggable Database CNDBA with pdb id - 4 is altered with errors or warnings. Please look into PDB_PLUG_IN_VIOLATIONS view for more details. *************************************************************** Opening pdb CNDBA (4) with no Resource Manager plan active Pluggable database CNDBA opened read write Completed: alter pluggable database open
Log 提示查看PDB_PLUG_IN_VIOLATIONS。
SQL> col action for a70 SQL> select status,action from PDB_PLUG_IN_VIOLATIONS; STATUS ACTION --------- ---------------------------------------------------------------------- RESOLVED Please check the parameter in the current CDB RESOLVED Drop the service and recreate it with an appropriate name. RESOLVED Please check the parameter in the current CDB RESOLVED Please check the parameter in the current CDB RESOLVED Run noncdb_to_pdb.sql. PENDING Call datapatch to install in the PDB or the CDB 6 rows selected. SQL> select message from PDB_PLUG_IN_VIOLATIONS; MESSAGE ---------------------------------------------------------------------------------------------------------------------------------- CDB parameter sga_target mismatch: Previous 1168M Current 0 Service name or network name of service cndba in the PDB is invalid or conflicts with an existing service name or network name in the CDB. CDB parameter heat_map mismatch: Previous 'ON' Current 'OFF' CDB parameter pga_aggregate_target mismatch: Previous 386M Current 0 PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run. PSU bundle patch 4 (Database Patch Set Update : 12.1.0.2.4 (20831110)): Installed in the CDB but not in the PDB. 6 rows selected.
从上面的信息看,因为CDB 已经是12.1.0.2.4,但是PDB 还是12.1.0.2.0。
12.1.0.2.4的补丁安装参考:
Oracle 12c 单实例 从12.1.0.2.0 升级到 12.1.0.2.4 示例
http://www.cndba.cn/dave/article/214
因为之前已经打过patch,所以这里直接执行脚本即可:
[oracle@Ora12c OPatch]$ datapatch -verbose -pdbs CNDBA 或者:[oracle@Ora12c OPatch]$ ./datapatch -verbose SQL Patching tool version 12.1.0.2.0 on Thu Apr 23 10:53:11 2015 Copyright (c) 2015, Oracle. All rights reserved. Log file for this invocation: /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_30149_2015_04_23_10_53_11/sqlpatch_invocation.log Connecting to database...OK Note: Datapatch will only apply or rollback SQL fixes for PDBs that are in an open state, no patches will be applied to closed PDBs. Please refer to Note: Datapatch: Database 12c Post Patch SQL Automation (Doc ID 1585822.1) Bootstrapping registry and package to current versions...done Determining current state... done Current state of SQL patches: Bundle series PSU: ID 4 in the binary registry and ID 4 in PDB CDB$ROOT, ID 4 in PDB PDB$SEED, ID 4 in PDB PDB1 Adding patches to installation queue and performing prereq checks... Installation queue: For the following PDBs: CDB$ROOT PDB$SEED PDB1 Nothing to roll back Nothing to apply For the following PDBs: CNDBA Nothing to roll back The following patches will be applied: 20831110 (Database Patch Set Update : 12.1.0.2.4 (20831110)) Installing patches... Patch installation complete. Total patches installed: 1 Validating logfiles... Patch 20831110 apply (pdb CNDBA): SUCCESS logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/20831110/18977826/20831110_apply_DAVE_CNDBA_2015Apr23_10_57_44.log (no errors) SQL Patching tool complete on Thu Apr 23 10:57:47 2015[oracle@Ora12c OPatch]$
这里提示我们已经打上了。
但是查看状态依旧:
SQL> select status,action from PDB_PLUG_IN_VIOLATIONS; STATUS ACTION --------- ---------------------------------------------------------------------- RESOLVED Please check the parameter in the current CDB RESOLVED Drop the service and recreate it with an appropriate name. RESOLVED Please check the parameter in the current CDB RESOLVED Please check the parameter in the current CDB RESOLVED Run noncdb_to_pdb.sql. PENDING Call datapatch to install in the PDB or the CDB 再次确认一下: SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1 READ WRITE NO 4 CNDBA READ WRITE YES 库是首先方式打开的,重启一下。 SQL> alter pluggable database cndba close; Pluggable database altered. SQL> alter pluggable database cndba open; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1 READ WRITE NO 4 CNDBA READ WRITE NO SQL> select status,action from PDB_PLUG_IN_VIOLATIONS; STATUS ACTION --------- ---------------------------------------------------------------------- RESOLVED Please check the parameter in the current CDB RESOLVED Drop the service and recreate it with an appropriate name. RESOLVED Please check the parameter in the current CDB RESOLVED Please check the parameter in the current CDB RESOLVED Run noncdb_to_pdb.sql. RESOLVED Call datapatch to install in the PDB or the CDB 6 rows selected. SQL> col DESCRIPTION for a50 SQL> set lin 130 SQL> SELECT s.con_id, s.patch_id, s.patch_uid, s.description FROM cdb_registry_sqlpatch s order by 1,2; CON_ID PATCH_ID PATCH_UID DESCRIPTION ---------- ---------- ---------- -------------------------------------------------- 1 20831110 18977826 Database Patch Set Update : 12.1.0.2.4 (20831110) 3 20831110 18977826 Database Patch Set Update : 12.1.0.2.4 (20831110) 4 20831110 18977826 Database Patch Set Update : 12.1.0.2.4 (20831110) SQL>
问题解决,在open 之前没有确认打开方式,所以建议在OPEN PDB 之后,在关闭PDB,重新打开,以正常的方式打开,而不是受限模式。http://www.cndba.cn/cndba/dave/article/220
http://www.cndba.cn/cndba/dave/article/220http://www.cndba.cn/cndba/dave/article/220
版权声明:本文为博主原创文章,未经博主允许不得转载。