前言
随着 Oracle 数据库的普遍应用,DataGuard 这个成员基本成为了数据库容灾环境的标配!
一、介绍
当需要升级 Oracle 数据库的同时,也需要考虑同时升级 DataGuard 数据库版本,那么如何快捷安全的升级?
推荐方案:
升级至NON-CDB模式:
首先关闭 ADG 同步,升级主库至 19C,备库以mount模式在 19C 下打开,开启 ADG 同步。
升级至CDB模式:
1、首先升级主库为 19C cdb+pdb 模式,备库重新搭建 ADG。
2、首先搭建一套 19C CDB 的主备 ADG 环境,关闭 ADG 同步,然后将主库升级并插入主库 CDB,开启 ADG 同步。
本文主要介绍 CDB 模式:首先升级主库为 19C cdb+pdb 模式,备库重新搭建 ADG。
二、环境准备
环境安装过程忽略,可参考:Oracle 数据库一键安装,从未如此简单!
本次测试尽量按照生产环境升级进行模拟:
???? 注意: 源库最好冷备拷贝到新机器进行升级,保留源库用于回退。
根据 MOS文档 2485457.1 可以获取 最新版 AutoUpgrade工具 下载地址:
The most recent version of AutoUpgrade can be downloaded via this link: version 20211115.
二、升级主库
用 AutoUpgrade 工具升级主库可参考:实战篇:AutoUpgrade 便捷高效的升级 Oracle 数据库
1、配置 config 文件
编辑 config 文件内容如下:
cat<<EOF >/soft/conifg.cfg # Global configurations global.autoupg_log_dir=/soft/uplogs global.raise_compatible=yes global.drop_grp_after_upgrade=yes # Database number 3 - Noncdb to PDB upgrade upg3.log_dir=/soft/logs upg3.sid=orcl upg3.source_home=/u01/app/oracle/product/11.2.0/db upg3.target_cdb=cdb19c upg3.target_home=/u01/app/oracle/product/19.3.0/db upg3.target_pdb_name=orcl upg3.target_pdb_copy_option=file_name_convert=('/oradata/orcl/', '/oradata/CDB19C/orcl/') upg3.start_time=NOW # Optional. 10 Minutes from now upg3.upgrade_node=orcl # Optional. To find out the name of your node, run the hostname utility. Default is 'localhost' upg3.run_utlrp=yes # Optional. Whether or not to run utlrp after upgrade upg3.timezone_upg=yes # Optional. Whether or not to run the timezone upgrade upg3.target_version=19 # Oracle version of the target ORACLE_HOME. Only required when the target Oracle database version is 12.2 upg3.remove_underscore_parameters=yes upg3.source_tns_admin_dir=/u01/app/oracle/product/11.2.0/db/network/admin upg3.target_tns_admin_dir=/u01/app/oracle/product/19.3.0/db/network/admin EOF
2、开始升级
具体升级命令可参考:实战篇:AutoUpgrade 便捷高效的升级 Oracle 数据库
至此,主库已升级完成!
3、升级后检查
设置 pdb 随 cdb 启动:
alter pluggable database all save state;
三、搭建ADG
升级好主库之后,开始搭建 ADG!
1、dbca 创建备库
备库使用 dbca 搭建 ADG:
dbca -silent -createDuplicateDB \ -gdbName cdb19c \ -sid cdb19c \ -sysPassword oracle \ -primaryDBConnectionString 10.211.55.100:1521/cdb19c \ -nodelist orcl_stby \ -databaseConfigType SINGLE \ -createAsStandby -dbUniqueName cdb19c_stby \ -datafileDestination '/oradata'
2、配置 ADG 参数
主库设置 DG 参数:
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(CDB19C,CDB19C_STBY)'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=CDB19C'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=CDB19C_stby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=CDB19C_STBY'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE; ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE; ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4; ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE; ALTER SYSTEM SET FAL_SERVER=CDB19C_STBY; ALTER SYSTEM SET FAL_CLIENT=CDB19C; ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/oradata/CDB19C','/oradata/CDB19C_STBY' SCOPE=SPFILE; ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/oradata/CDB19C','/oradata/CDB19C_STBY' SCOPE=SPFILE; ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
备库设置 DG 参数:
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(CDB19C_STBY,CDB19C)'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=CDB19C_STBY'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=CDB19C ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=CDB19C'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE; ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE; ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4; ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE; ALTER SYSTEM SET FAL_SERVER=CDB19C; ALTER SYSTEM SET FAL_CLIENT=CDB19C_STBY; ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/oradata/CDB19C_STBY','/oradata/CDB19C' SCOPE=SPFILE; ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/oradata/CDB19C_STBY','/oradata/CDB19C' SCOPE=SPFILE; ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
3、主备开启同步
##备库执行 alter database recover managed standby database using current logfile disconnect from session; ##主库执行 alter system set log_archive_dest_state_2=enable;
至此,ADG 已经搭建完成。
四、升级完测试
主库创建测试数据:
alter session set container=orcl;
sqlplus lucifer/lucifer@orcl
备库查看是否同步:
升级结束,ADG 同步正常!
参考文章:
- How to Upgrade with AutoUpgrade and Data Guard
- Upgrade Database to 12.2 with Physical Standby