一、前言
由于11G已经被Oracle淘汰,不再更新补丁,官方建议升级到最新稳定版 19C,因此了解下升级方式。
本文将介绍其中一种方式:DBUA
Complete Checklist to Upgrade the Database to 11gr2 Using DBUA(Doc ID 870814.1)
Complete Checklist for Upgrading to Oracle Database 12c Release 1 using DBUA(Doc ID 1516557.1)
Complete Checklist for Upgrading to Oracle Database 12c Release 2 (12.2) using DBUA(Doc ID 2189854.1)
Oracle 18c - Complete Checklist for Upgrading to Oracle Database 18c (18.x) using DBUA(Doc ID 2418576.1)
Oracle 19c - Complete Checklist for Upgrading to Oracle Database 19c (19.x) using DBUA(Doc ID 2545064.1)
参考MOS文档:Oracle 19c - Complete Checklist for Upgrading to Oracle Database 19c (19.x) using DBUA (Doc ID 2545064.1)
DBUA也支持静默方式:Oracle 19c - DBUA In Silent Mode (Doc ID 2548985.1)
参考文章:使用DBUA升级 Oracle 11.2.0.4到Oracle 19C的问题记录
Database Upgrade Assistant (DBUA) provides a graphical user interface to guide you through the upgrade of Oracle Database.
Oracle对主机版本支持:
11GR2:
19C:
Notes:19C对操作系统支持最低要求为Linux7,如果11GR2主机版本为Linux 6,则需要一台新主机Linux7安装19C。
升级路线:
Direct Upgrade to 19.x:
Source Database | Target Database |
11.2.0.4 and Higher | 19.x |
12.1.0.2 | 19.x |
12.2.0.1 | 19.x |
18.1 | 19.x |
Indirect Upgrade to 19.x:
Source Database | Intermediate upgrade path | Target database | ||
11.2.0.1/11.2.0.2/11.2.0.3 | --> | 11.2.0.4 | --> | 19.x |
11.1.0.6/11.1.0.7 | --> | 11.2.0.4 | --> | 19.x |
10.2.0.2, 10.2.0.3, 10.2.0.4, 10.2.0.5 | --> | 11.2.0.4/12.1.0.2 | --> | 19.x |
10.1.0.5 | --> | 11.2.0.4/12.1.0.2 | --> | 19.x |
9.2.0.8 or earlier | --> | 11.2.0.4 | --> | 19.x |
12.1.0.1 | --> | 12.1.0.2/12.2.0.1 | --> | 19.x |
二、环境准备
本次测试尽量按照生产环境升级进行模拟,故而使用2台主机进行测试:
节点 | 主机版本 | 主机名 | 实例名 | Oracle版本 | IP地址 |
源库 | redhat 6.9 | dbua11g | lucifer | 11204(补丁 31537677) | 10.211.55.110 |
目标库 | redhat 7.9 | dbua19c | lucifer | 11204(补丁 31537677)+ 19.3.0(补丁 32441092) | 10.211.55.100 |
注意:源库为生产环境,目标库为升级环境,需要通过rman的将生产环境实例备份恢复到目标库,保留生产环境用于失败回退。
测试环境安装过程忽略,可参考:
源库
11GR2:
cd /soft
./OracleShellInstall.sh -i 10.211.55.100 `#Public ip`\
-n dbua11g `# hostname`\
-o lucifer `# oraclesid`\
-op oracle `# oracle user password`\
-b /u01/app `# install basedir`\
-s AL32UTF8 `# characterset`\
-opa 31537677 `# oracle psu number`
目标库:
11GR2:
cd /soft
./OracleShellInstall.sh -i 10.211.55.100 `#Public ip`\
-n dbua19c `# hostname`\
-o lucifer `# oraclesid`\
-op oracle `# oracle user password`\
-b /u01/app `# install basedir`\
-s AL32UTF8 `# characterset`\
-opa 31537677 `# oracle psu number` \
-w Y
19C:
cp /home/oracle/.bash_profile /home/oracle/.bash_profile_11G
cd /soft
./OracleShellInstall.sh -i 10.211.55.100 `#Public ip`\
-n dbua19c `# hostname`\
-o lucifer `# oraclesid`\
-op oracle `# oracle user password`\
-b /u01/app `# install basedir`\
-s AL32UTF8 `# characterset`\
-m Y
手动安装Oracle软件和补丁:
##解压替换OPatch包
unzip -o p6880880_190000_Linux-x86-64.zip -d /u01/app/oracle/product/19.3.0/db/
chown -R oracle:oinstall /u01/app/oracle/product/19.3.0/db/OPatch
##解压DB RU补丁
unzip p32545013_190000_Linux-x86-64.zip
chown -R oracle:oinstall 32545013
##安装19c Oracle软件
cd $ORACLE_HOME
./runInstaller -applyRU /soft/32545013/
脚本使用和下载可参考Github:https://github.com/pc-study/InstallOracleshell
安装结束。
源库:
目标库:
11GR2:
19C:
RMAN备份恢复到目标库11GR2中:
#!/bin/sh
source ~/.bash_profile
backtime=`date +"20%y%m%d%H%M%S"`
rman target / log=/backup/level0_backup_${backtime}.log<<EOF
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
crosscheck backup;
crosscheck archivelog all;
sql"alter system switch logfile";
delete noprompt expired backup;
delete noprompt obsolete device type disk;
backup incremental level 0 database include current controlfile format '/backup/backlv0_%d_%T_%t_%s_%p';
backup archivelog all DELETE INPUT;
release channel c1;
release channel c2;
}
EOF
恢复至目标库11GR2:
##源端生成pfile参数文件
create pfile='/backup/11gpfile.ora' from spfile;
##拷贝备份至目标库
scp * 10.211.55.100:/backup/
##恢复至目标端11GR2中
mkdir -p /u01/app/oracle/fast_recovery_area/lucifer
mkdir -p /u01/app/oracle/admin/lucifer/adump
mkdir -p /oradata/lucifer/
chown -R oracle:oinstall /u01/app/oracle/fast_recovery_area
chown -R oracle:oinstall /u01/app/oracle/admin/lucifer/adump
chown -R /oradata/lucifer/
##启动数据库实例到nomount状态
su - oracle
source .bash_profile_11G
sqlplus / as sysdba
startup nomount pfile='/backup/11gpfile.ora'
##rman进行恢复
restore controlfile from '/backup/backlv0_LUCIFER_20210518_1072888737_3_1';
alter database mount;
##注册备份目录
catalog start with '/backup/';
##恢复数据
restore database;
##将源库开启到readonly模式
alter system switch logfile;
shutdown immediate
startup mount
alter database open read only
##拷贝归档日志到目标端
cd /archivelog
scp * 10.211.55.100:/backup
##注册归档日志
catalog start with '/backup/';
recover database;
##打开数据库
alter database open resetlogs;
至此,测试环境搭建完毕。
三、升级前准备
对源数据库的要求和建议:
1.确保数据库组件和对象均为有效。
--检查无效对象和组件
select substr(comp_name,1,40) comp_name, status, substr(version,1,10) version from dba_registry order by comp_name;
select substr(object_name,1,40) object_name,substr(owner,1,15) owner,object_type from dba_objects where status='INVALID' order by owner,object_type;
select owner,object_type,count(*) from dba_objects where status='INVALID' group by owner,object_type order by owner,object_type ;
BEGIN
dbms_preup.invalid_objects;
END;
--ReBuild
sqlplus / as sysdba
@$ORACLE_HOME/rdbms/admin/utlrp.sql
2.确保源库和目标库补丁均升级为最新(包括APEX)。
Doc ID 556610.1-收集数据库升级/迁移诊断信息的脚本(dbupgdiag.sql)
Script to Collect DB Upgrade/Migrate Diagnostic Information (dbupgdiag.sql) (Doc ID 556610.1)
3.如果已安装APEX,则建议先升级源DB中的APEX,然后再升级DB。
下载APEX: http://www.oracle.com/technetwork/developer-tools/apex/all-archives-099381.html
升级APEX:
##1.解压APEX包
unzip apex_19.2.zip
chown -R oracle:oinstall /soft/apex
##2.查看当前APEX版本
SELECT comp_name,
status,
version
FROM dba_registry
WHERE comp_name = 'Oracle Application Express';
--3.2.1.00.12
##3.进入APEX解压目录进行升级
cd /soft/apex
sqlplus / as sysdba @apexins.sql SYSAUX SYSAUX TEMP /i/
##4.升级完后查看APEX版本
--19.2.0.00.18
##5.编译无效对象
sqlplus / as sysdba
@$ORACLE_HOME/rdbms/admin/utlrp.sql
4.时区应小于或等于目标数据库时区版本,19C为 32
SELECT version FROM v$timezone_file;
--14
5.升级之前,请确保对源数据库进行有效备份。
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
crosscheck backup;
crosscheck archivelog all;
sql"alter system switch logfile";
delete noprompt expired backup;
delete noprompt obsolete device type disk;
backup database include current controlfile format '/backup/backlucifer_%d_%T_%t_%s_%p';
backup archivelog all DELETE INPUT;
release channel c1;
release channel c2;
}
6.禁用将在DDL语句之前/之后执行的所有自定义触发器。 升级后重新启用。
7.升级数据库之前,请检查数据库服务器升级/降级兼容性列表。
8.开启日志归档功能。
9.对于Oracle RAC,如果使用DBUA升级群集数据库,则必须将CLUSTER_DATABASE初始化参数设置为TRUE。
ALTER SYSTEM SET CLUSTER_DATABASE=TRUE SCOPE=SPFILE;
10.确保在升级数据库之前运行升级前的检查脚本,并按照建议进行调整。
How to Download and Run Oracle's Database Pre-Upgrade Utility (Doc ID 884522.1)
su - oracle
export Earlier_release_Oracle_home=/u01/app/oracle/product/11.2.0/db
export New_release_Oracle_home=/u01/app/oracle/product/19.3.0/db/
$Earlier_release_Oracle_home/jdk/bin/java -jar $New_release_Oracle_home/rdbms/admin/preupgrade.jar TERMINAL TEXT DIR /soft
根据 /soft/preupgrade.log列出的内容进行修复:
alter system set processes=1500 scope=spfile;
alter system set sga_max_size=4G scope=spfile;
alter system set sga_target=2G scope=spfile;
shutdown immediate
startup
select name from v$datafile;
select name from v$tempfile;
alter tablespace SYSAUX add datafile '/oradata/lucifer/sysaux02.dbf' size 200M autoextend off;
alter tablespace SYSTEM add datafile '/oradata/lucifer/system02.dbf' size 600M autoextend off;
alter tablespace UNDOTBS1 add datafile '/oradata/lucifer/undotbs02.dbf' size 300M autoextend off;
alter tablespace TEMP add tempfile '/oradata/lucifer/temp02.dbf' size 200M autoextend off;
sqlplus / as sysdba @?/rdbms/admin/catnoexf.sql
手动修复完后,执行preupgrade_fixups.sql脚本自动修复:
cd /soft
sqlplus / as sysdba @/soft/preupgrade_fixups.sql
Notes:由于没有物化视图,所以忽略。
11.在升级之前,应停止源数据库中的物化视图。
Doc ID 1406586.1 - How to Handle Materialized Views When You Upgrade or Clone a Database
Database Preupgrade tool check list. (Doc ID 2380601.1)
SELECT o.name FROM sys.obj$ o, sys.user$ u, sys.sum$ s WHERE o.type# = 42 AND bitand(s.mflags, 8) =8;
select owner, mview_name from all_mviews where staleness = 'STALE';
select owner, mview_name from all_mviews where staleness not in ('FRESH', 'STALE', 'UNKNOWN') or compile_state not in ('VALID');
SELECT u.name owner, o.name mview_name FROM sys.obj$ o, sys.user$ u, sys.sum$s WHERE o.type# = 42 AND o.owner# = u.user# and s.obj# = o.obj# and bitand(s.mflags, 8) = 8;
12.禁用计划的数据库自定义JOB和crontab计划任务。
13.升级19.1的COMPATIBLE参数的最小值为“ 11.2.0”,请确保您将COMPATIBLE参数设置为11.2.0或更高。
show parameter compatible
--11.2.0.4.0
14.收集数据字典统计信息以减少Oracle数据库停机时间。
EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;
15.确保当前没有备份或者恢复的文件。
--Execute below query to check for the status of the backup:
SQL> SELECT * FROM v$backup WHERE status != 'NOT ACTIVE';
--Ensure that no files require media recovery:
SQL> SELECT * FROM v$recover_file;
16.升级前清空回收站。
PURGE DBA_RECYCLEBIN;
17.使用emremove.sql删除EM(适用于12.1之前的Oracle数据库版本)。
##停止em
emctl stop dbconsole
##将以下脚本脚本从新安装的Oracle主目录(19c)复制到需要升级的数据库的Oracle主目录(11.2)
ORACLE_HOME/rdbms/admin/olspreupgrade.sql
ORACLE_HOME/rdbms/admin/emremove.sql
ORACLE_HOME/olap/admin/catnoamd.sql
##执行脚本
sqlplus / as sysdba
@?/rdbms/admin/emremove.sql
18.取消对OLAP目录(OLAP AMD)的支持(适用于12.1之前的Oracle数据库版本)。
##执行脚本
sqlplus / as sysdba
@?/rdbms/admin/catnoamd.sql
19.检查用户当前不区分大小写的密码版本。
--如果有10g版本,建议您参考Oracle文档来修复10g版本,如果不这样做,升级完成后具有LOCKED的用户帐户。
SELECT USERNAME,PASSWORD_VERSIONS FROM DBA_USERS;
--查看隐含参数_optimizer_cartesian_enabled,确保设置为TRUE
SELECT name,description from SYS.V$PARAMETER WHERE name LIKE '\_%' ESCAPE '\';
alter system set "_optimizer_cartesian_enabled"=TRUE;
20.PFILE参数文件去除所有隐含参数和event事件。
对目标数据库的要求和建议:
1.验证您的操作系统/平台是否通过了19.x版本的认证。
2.在新的Oracle_Home中下载并安装Oracle 19c(19,x),并确保没有relink错误。
3.确保从My Oracle Support(MOS)下载并安装最新的可用RU或RUR。
4.确保将ORACLE_HOME,PATH,LD_LIBRARY_PATH,LIBPATH等设置为19.x目标主目录。
5.查看文章“在将Oracle GI和DB升级到19c或降级到以前的版本(文档ID 2539751.1)之前要应用的补丁”中给出的补丁建议。
四、开始DBUA升级
因为19C已安装RU补丁,升级完后README的脚本还需要跑一遍。
sqlplus / as sysdba @?/rdbms/admin/utlrp.sql
环境变量切换到19C并运行DBUA:
echo $ORACLE_HOME
/u01/app/oracle/product/19.3.0/db
# dbua
如果按照上述步骤之后出现这种情况,通常是因为RMAN恢复的数据库实例未注册到/etc/oratab中,手动添加:
cat <<EOF>> /etc/oratab
lucifer:/u01/app/oracle/product/11.2.0/db:N
EOF
添加后,点击刷新即可。
选中需要升级的数据库实例,点击下一步。
以上警告可以忽略,点击下一步。
点击下一步。
这里由于已经有RMAN备份,故而选择RMAN Backup,点击下一步。
提前创建19C监听,端口为1522,升级完之后记得改回1521,点击下一步。
不安装EM,点击下一步。
点击FINISH。
由于RMAN恢复的实例,不存在该目录,需要手动创建并授权:
mkdir -p /u01/app/oracle/admin/lucifer/dpdump
chown -R oracle:oinstall /u01/app/oracle/admin/lucifer/dpdump
坑爹,需要重新启动DBUA进行升级。
成功进入,等待自动升级完成。
执行 /soft/postupgrade_fixups.sql脚本:
sqlplus / as sysdb @/soft/postupgrade_fixups.sql
更新后检查和修复:
1、运行dbupgdiag.sql检查19C数据库情况:
Doc ID 556610.1-收集数据库升级/迁移诊断信息的脚本(dbupgdiag.sql)
Script to Collect DB Upgrade/Migrate Diagnostic Information (dbupgdiag.sql) (Doc ID 556610.1)
chown -R oracle:oinstall /soft/dbupgdiag.sql
su - oracle
cd /soft
sqlplus / as sysdba @dbupgdiag.sql
--1.填写输出目录:/soft
2、编译无效对象
##检查无效对象
select substr(comp_name,1,40) comp_name, status, substr(version,1,10) version from dba_registry order by comp_name;
select substr(object_name,1,40) object_name,substr(owner,1,15) owner,object_type from dba_objects where status='INVALID' order by owner,object_type;
select owner,object_type,count(*) from dba_objects where status='INVALID' group by owner,object_type order by owner,object_type ;
##编译无效对象
sqlplus / as sysdba @?/rdbms/admin/utlrp.sql
3.删除原11GR2环境相关文件
rm -rf /home/oracle/.bash_profile_11G
rm -rf /u01/app/oracle/product/11.2.0/db
##关闭11G监听
ps -ef|grep tns
kill -9 $spid
4.修改19C监听端口号为1521
##修改LOCAL_LISTENER
alter system reset local_listener;
shutdown immediate
startup
##Notes:如果不将LOCAL_LISTENER设置为空,动态监听无法注册。
lsnrctl stop
cd $TNS_ADMIN
##修改listener.ora文件:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbua19c)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
lsnrctl start
5.配置sqlnet.ora
cd $TNS_ADMIN
cat <<EOF >>sqlnet.ora
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
EOF
6.检查所有组件
select substr(comp_id,1,15) comp_id,substr(comp_name,1,30) comp_name,substr(version,1,10) version,status
from dba_registry
order by modified;
7.修改COMPATIBLE参数
ALTER SYSTEM SET COMPATIBLE="19.0.0" SCOPE=SPFILE;
shutdown immediate
startup
转载至https://blog.csdn.net/m0_50546016/article/details/116991231?spm=1001.2014.3001.5501