首页 > 数据库 > Oracle > pdb库单库升级文档
数据库为12.1.0.2.0单机环境,目标升级为12.2.0.1环境,操作系统为RHEL6.4,
实例名称:orcl
1) 确保所有的数据库组件是可用的
|
SQL> set lin 200 SQL> col comp_name for a40 SQL> select comp_name,version,status from dba_registry;
COMP_NAME VERSION STATUS ---------------------------------------- ------------------------------ ---------------------- Oracle Database Vault 12.1.0.2.0 VALID Oracle Application Express 4.2.5.00.08 VALID Oracle Label Security 12.1.0.2.0 VALID Spatial 12.1.0.2.0 VALID Oracle Multimedia 12.1.0.2.0 VALID Oracle Text 12.1.0.2.0 VALID Oracle Workspace Manager 12.1.0.2.0 VALID Oracle XML Database 12.1.0.2.0 VALID Oracle Database Catalog Views 12.1.0.2.0 VALID Oracle Database Packages and Types 12.1.0.2.0 VALID JServer JAVA Virtual Machine 12.1.0.2.0 VALID Oracle XDK 12.1.0.2.0 VALID Oracle Database Java Packages 12.1.0.2.0 VALID OLAP Analytic Workspace 12.1.0.2.0 VALID Oracle OLAP API 12.1.0.2.0 VALID Oracle Real Application Clusters 12.1.0.2.0 OPTION OFF 16 rows selected. |
2) 禁用传统的触发器,等到升级完成后再开启
3) 如果你的环境中启用了APEX,那么升级到5.1,来减少升级的时间
4) 检查pdb的状态,要处于read write状态
|
SQL> select name, open_mode,cdb,i.con_id, version from V$database,v$instance i;
NAME OPEN_MODE CDB CON_ID VERSION --------- -------------------- --- ---------- ----------------- ORCL1 READ WRITE YES 0 12.1.0.2.0
SQL> select CON_ID, NAME, OPEN_MODE from V$PDBS;
CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 TESTUP READ WRITE |
方法一:在cdb里面备份
|
rman nocatalog target / BACKUP PLUGGABLE DATABASE TESTUP TAG pdb_backup; Else you can take full CDB backup as below BACKUP DATABASE TAG before_upgrade; BACKUP CURRENT CONTROLFILE TO '<controlfile_backup_directory>'; |
用dbupgdiag.sql诊断,如果dbupgdiag.sql跑出来有无效对象,编译无效对象$ORACLE_HOME/rdbms/admin/utlrp.sql。
|
$ cd $ORACLE_HOME/rdbms/admin $ sqlplus "/ as sysdba" SQL> alter session set container=testup; SQL> @utlrp.sql |
Note 556610.1 Script to Collect DB Upgrade/Migrate Diagnostic Information (dbupgdiag.sql)
数据库必须在老版本中运行正常
1) 下载并运行最新预检工具Note 884522.1 , 或者从高版本中复制 preupgrade.jar
2)
Oracle Database 12
c release 2 introduces the
preupgrade.jar
Pre-Upgrade Information Tool
将工具放在$ORACLE_HOME/rdbms/admin下面
|
状态检查 sql> show pdbs; 使其处于读写状态 sql> alter pluggable database testup open; 在pbd里面执行升级前脚本可以用下面方法 cd $ORACLE_HOME/rdbms/admin 1. $ORACLE_HOME/jdk/bin/java -jar /oracle/product/12.1.0/db_1/rdbms/admin/preupgrade.jar TERMINAL TEXT -c 'testup' 会生成以下了两个脚本: Preupgrade generated files: /oracle/cfgtoollogs/orcl1/preupgrade/preupgrade_fixups.sql /oracle/cfgtoollogs/orcl1/preupgrade/postupgrade_fixups.sql 跟据建议升级前运行( 要切换到pdb执行 )
|
|
$ sqlplus "/as sysdba" SQL> alter session set container=testup; SQL> exec dbms_stats.gather_dictionary_stats; |
|
SQL> select s.obj#,o.obj#,s.containerobj#,lastrefreshdate,pflags,xpflags,o.name,o.owner#, bitand(s.mflags, 8) from obj$ o, sum$ s where o.obj# = s.obj# and o.type# = 42 AND bitand(s.mflags, 8) = 8; |
|
SQL> select * from v$recover_file; |
|
SQL> select * from v$backup WHERE status != 'NOT ACTIVE'; |
|
1. Issue the following statement: SQL> Select * from dba_2pc_pending; 2. If the query in the previous step returns any rows, then issue the following statements: SQL> select local_tran_id FROM dba_2pc_pending; SQL> execute dbms_transaction.purge_lost_db_entry(''); SQL> commit; |
|
SQL> purge dba_recyclebin; |
Note 404238.1 : How to Disable an Entry from DBMS_SCHEDULER
Note 1335741.1 : How To Stop A Running Job Using DBMS_JOB
Note 67695.1 : PROCEDURE DBMS_JOB.BROKEN Specification
确认sys和system用户的默认表空间是’SYSTEM’.
要保证system表空间有足够的空间
|
SQL> alter session set container=testup; SQL> SELECT username, default_tablespace FROM dba_users WHERE username in ('SYS','SYSTEM'); |
如果默认表空间不是system表空间,修改sys和system 的默认表空间为system:
|
SQL> alter user SYS default tablespace SYSTEM; SQL> alter user SYSTEM default tablespace SYSTEM; |
查询方法
|
SQL> alter session set container=testup; SQL> SELECT name, value from SYS.V$PARAMETER WHERE name LIKE '\_%' ESCAPE '\' order by name; |
1、 操作系统要满足12c R2安装的环境
2、 确保数据库软件安装的事后没有relink错误
3、 安装最新的partchset
4、 适用最新的OPatch工具
5、 对源端做个冷备或者热备,建议冷备
6、 确保目标端的CDB里面不包含与源端一样的pdb名字
7、 检查CDB的字符集
建议cdb字符集设置成AL32UTF8
1) 从旧版本软件中的ORACLE_HOME目录拷贝配置文件到新环境中。
Unix 中:$ORACLE_HOME/dbs
Windows 中:ORACLE_HOME/database
2) 从源端将密码文件拷贝到目标端。
3) 用下面的步骤调整参数:
|
·Adjust the values of the initialization parameters to at least the minimum values indicated by the Pre-Upgrade Information Tool. ·Make sure all path names in the parameter file are fully specified. You should not have relative path names in the parameter file. ·If you are upgrading a cluster database, then you may need to modify the SPFILE or initORACLE_SID.ora files.set the CLUSTER_DATABASE initialization parameter to false. After the upgrade, you must set this initialization parameter back to true. |
关闭数据库
|
SQL> SHUTDOWN IMMEDIATE; |
确保环境变量指向12.2路径
|
$ export ORACLE_HOME=<location of Oracle 12.2> $ export PATH=$ORACLE_HOME/bin:$PATH $ export ORACLE_BASE=<Oracle_Base set during installation> |
注意:如果不知道ORACLE_BASE可以用下面命令
$ orabase
更新oratab,禁用自启动
#orcl1:/oracle/product/12.1.0/db_1:N
orcl1:/oracle/product/12.2.0/db_1:N
注意: After /etc/oratab is updated to have SID and Oracle Home (12.2.0.1), you can execute oraenv (/usr/local/bin/oraenv) and set the environment.
启动 cdb到升级模式
|
SQL> startup upgrade pfile=/oracle/product/12.2.0/db_1/dbs/initorcl1.ora
Start all PDB in upgrade mode
SQL> alter pluggable database all open upgrade;
Exit SQL*Plus before proceeding to the next step.
SQL> exit; |
要升级整个CDB,在新环境中运行dbupgrade脚本:
|
cd $ORACLE_HOME/rdbms/admin dbupgrade -d $ORACLE_HOME/rdbms/admin |
catupgrade logs的日志将会产生在每个 seed database和 pdb
重要: catuppst.sql 脚本是升级中的一部分,如果升级的过程中报错
检查 "BEGIN catuppst.sql"的日志,如果 catuppst.sql没有运行,那么运行如下语句
Run catuppst.sql as follows:
|
$ORACLE_HOME/perl/bin/perl catcon.pl -n 1 -e -b catuppst -d '''.''' catuppst.sql Run catcon.pl to invoke utlrp.sql to recompile any remaining stored PL/SQL and Java code. Use the following syntax: $ORACLE_HOME/perl/bin/perl catcon.pl -n 1 -e -b utlrp -d '''.''' utlrp.sql Run utlu121s.sql to verify that all issues have been fixed $ORACLE_HOME/perl/bin/perl catcon.pl -n 1 -e -b utlu121s -d '''.''' utlu121s.sql Shutdown and start the database in normal mode SQL> shutdown immediate; |
1) 执行升级后脚本
运行以下脚本:
|
SQL> startup upgrade pfile=/oracle/product/12.2.0/db_1/dbs/initorcl1.ora
SQL> alter pluggable database all open;
Execute the postupgrade_fixups.sql:
$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -d \ $ORACLE_HOME/cfgtoollogs/cdbupgr/preupgrade -l /home/oracle/upgrdDBA -b \ postupgrade_fixups postupgrade_fixups.sql |
退出sqlplus,然后将$ORACLE_HOME/rdbms/admin指向新的路径。
cd $ORACLE_HOME/rdbms/admin
运行 catcon.pl脚本
|
$ORACLE_HOME/perl/bin/perl catcon.pl -n 1 -e -b utlrp -d '''.''' utlrp.sql |
运行 postupgrade_fixups.sql脚本
SQL> @rdbms/admin/postupgrade_fixups.sql
运行 utlu122s.sql脚本
SQL> @rdbms/admin/utlu122s.sql
2 )环境变量设置
3 )创建spfile
SQL> create spfile from pfile;
4 )收集统计信息
EXECUTE DBMS_STATS.UPGRADE_STAT_TABLE('SYS','dictstattab');
5 )编译无效对象
升级后运行$ORACLE_HOME/rdbms/admin/下面的utluiobj.sql,然后在执行utlrp.sql重新编译无效对象
6.1 从源端的CDB里面卸载PDB
|
cd $ORACLE_HOME/rdbms/admin sqlplus /nolog SQL> connect / as sysdba SQL> alter session set container=cdb$root; SQL> alter pluggable database orcl close; SQL> alter pluggable database orcl unplug into '/oracle/orcl.xml'; SQL> exit; |
6.2 在目标端CDB中插入PDB
复制下面的文件到目标服务器
|
1) PDB database files 2) /oracle/orcl.xml 3) postupgrade_fixups.sql Connect to CDB database cd $ORACLE_HOME/rdbms/admin sqlplus /nolog SQL> connect / as sysdba SQL> alter session set container=CDB$ROOT; SQL> create pluggable database orcl using '/oracle/orcl.xml' file_name_convert=('/oracle/pdborcl', '/oracle/oradata/test/orcl'); file_name_convert is required when directory structure is different between source and target server 如果文件已经在正确的路径: SQL> create pluggable database orcl using '/oracle/orcl.xml' NOCOPY; A file with the same name as the temp file specified in the XML file exists in the target location, then the TEMPFILE REUSE clause is required. SQL> create pluggable database orcl using '/oracle/orcl.xml' NOCOPY TEMPFILE REUSE; SQL> alter pluggable database orcl open upgrade; SQL> exit; On the command prompt: cd $ORACLE_HOME/rdbms/admin $ORACLE_HOME/perl/bin/perl catctl.pl -c "orcl" -l /home/oracle/upgrade catupgrd.sql |
5.1 执行脚本
|
SQL> startup pfile=<location of pfile>; SQL> alter pluggable database <PDB_Name> open; |
运行fixups.sql脚本
|
$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -d <post upgrade script location> -l <Log location> -c <PDB_Name> -b postupgrade_fixups postupgrade_fixups.sql Or SQL> alter session set container=<PDB_Name>; SQL> @<Post_upgrade_script_location>/postupgrade_fixups.sql |
5.2 编译无效对象
在升级后运行utluiobj.sql,位置在$ORACLE_HOME/rdbms/admin/。目的是辨认/比较是否有新的无效对象产生在升级过程中。
然后运行utlrp.sql
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23825935/viewspace-2932986/ ,如需转载,请注明出处,否则将追究法律责任。