数据库降级前:
SQL> select name from v$database;
NAME
------------------
TESTUP
SQL> select * from v$version;
BANNER
----------------------------------------------------------------------------
BANNER_FULL
----------------------------------------------------------------------------
BANNER_LEGACY
----------------------------------------------------------------------------
CON_ID
----------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
0
SQL> show parameter compatible
NAME TYPE VALUE
---------------------------- ------------------- -------------------------
compatible string 11.2.0.4.0
19c降级矩阵如下:
Downgrade Compatible Matrix |
Oracle Database release Downgradable | ( Yes / No ) |
18c | Yes |
12.2.0.1 | Yes |
12.1.0.2 | Yes |
11.2.0.4 | Yes for non-CDBs |
一、降级前检查1.1 如果数据库启用了 Oracle Database Vault, 则降级之前需要禁用 SQL> SELECT * FROM CDB_DV_STATUS;
如果输出为TRUE,则需要禁用,输出为FALSE则进行下一步。
1.2 如果数据库使用了 Oracle Label Security, 则需要在19c ORACLE_HOME下执行olspredowngrade.sql 脚本查询下面视图,查看Oracle Label Security是否使用,输出为FALSE则进行下一步。
SQL> SELECT VALUE FROM V$OPTION WHERE PARAMETER = 'Oracle Label Security';
如果返回TRUE,执行 olspredowngrade.sql 脚本:
SQL> @ORACLE_HOME/rdbms/admin/olspredowngrade.sql
1.3 如果数据库启用了 Unified Auditing, 建议备份和清除审计文件a . 查看是否有unified audit 记录,输出为0则进行下一步。
SQL> SELECT COUNT(*) FROM UNIFIED_AUDIT_TRAIL;
b. 备份现有的审计数据到表格中
SQL> CREATE TABLE UA_DATA AS (SELECT * FROM UNIFIED_AUDIT_TRAIL);
c. 清除审计记录
EXEC DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL(audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_UNIFIED, use_last_arch_timestamp => FALSE);
1.4 降级之前,确保目标数据库中有当前版本的timezone文件查询V$TIMEZONE_FILE视图,当前使用的timezone文件
SQL> select * from V$TIMEZONE_FILE;
FILENAME VERSION CON_ID
-------------------- ---------- ----------
timezlrg_32.dat 32 0
注: 需要将19c $ORACLE_HOME/oracore/zoneinfo 下的timezlrg_32.dat 文件拷贝到 11gR2 的$ORACLE_HOME/oracore/zoneinfo 目录下
cp /u01/app/oracle/product/19.0.0/db_1/oracore/zoneinfo/timezlrg_32.dat /u01/app/oracle/product/11.2.0/db_1/oracore/zoneinfo
1.5 如果配置了EM,则需要删掉sysman用户 ,重建EM 若没有配置EM,则进行下一步
DROP USER sysman CASCADE;
1.6 降级前11.2.0.4 需要安装的补丁Downgrade from 19c to 11.2.0.4.0
23054359: DATABASE PATCH SET UPDATE 11.2.0.4
20898997: XMLTYPESUP: QCTOXSNLB SHOULD NOT CHECK AGAINST SNAPSHOT SIZE
20348910: ALTER TYPE REPLACE IN PRVTAQJI.SQL TO BE REPLACE WITH CREATE OR REPLACE TYPE
[oracle@db-server ~]$ opatch lspatches
30670774;Database Patch Set Update : 11.2.0.4.200414 (30670774)
20898997;
20348910;
二、数据库降级从19c开始,oracle提供了dbdowngrade工具脚本,如有必要,也可使用和老版本一样的catdwgrd.sql脚本。
执行降级之前,建议数据库做个全备。
2.1 使用sqlplus 降级模式启动数据库,并且需要使用pfile 启动,然后执行dbdowngrade脚本。如果是RAC数据库,设置参数CLUSTER_DATABASE=FALSE,保留一个实例,关闭其它实例
sqlplus / as sysdba
SQL> alter system set CLUSTER_DATABASE=FALSE scope=spfile sid=’*’;
SQL> shutdown immediate;
以19c ORACLE_HOME 启动数据库
export ORACLE_HOME= /u01/app/oracle/product/19.0.0/db_1
sqlplus / as sysdba
SQL> startup downgrade;
$cd $ORACLE_HOME/bin
$ chmod +x dbdowngrade
$./dbdowngrade
或者手动跑脚本的方法
cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba
set echo on termout on serveroutput on timing on
SQL> SPOOL downgrade.log
SQL> @catdwgrd.sql
SQL> SPOOL off
2.2 关闭数据库实例SQL> SHUTDOWN IMMEDIATE;
2.3 修改环境变量指向11.2.0.4export ORACLE_HOME= /u01/app/oracle/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
2.4 执行catrelod.sql 重载组件版本sqlplus / as sysdba
SQL> STARTUP UPGRADE;
SQL> @$ORACLE_HOME/rdbms/admin/catrelod.sql
2.5 重启数据库,执行重新编译脚本SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
如果是RAC 数据库,则设回CLUSTER_DATABASE参数为TRUE
sqlplus / as sysdba
SQL> alter system set CLUSTER_DATABASE=TRUE scope=spfile sid=’*’;
更新CRS中注册的数据库版本信息
$ srvctl downgrade database -d db-unique-name -o oraclehome -t to_version
降级完成后结果:
SQL> select name from v$database;
NAME
------------------
TESTUP
1 row selected.
SQL> select * from v$version;
BANNER
----------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
5 rows selected.
三、降级后报错处理降级后 数据库alert 日志每隔5分钟就有报错:
ORA-1400 encountered when generating server alert SMG-4121
MOS 解决方案(ORA-1400 encountered when generating server alert SMG-4121 after downgrade from 12c to 11.2.0.4 (Doc ID 2169006.1))如下:
Recreate the the SYS.ALERT_QUE using the following steps:
1. Drop the alert_QT
sqlplus / as sysdba
alter system enable restricted session;
exec dbms_aqadm.drop_queue_table('ALERT_QT',true);
2. Drop tables wri$_alert_history and WRI$_ALERT_OUTSTANDING
drop table WRI$_ALERT_OUTSTANDING;
drop table WRI$_ALERT_HISTORY;
3. Recreate the alert_que and associated objects:
SQL>@$ORACLE_HOME/rdbms/admin/dbmsslrt.sql
SQL>@$ORACLE_HOME/rdbms/admin/catalrt.sql
SQL>@$ORACLE_HOME/rdbms/admin/catmwin.sql
SQL>@$ORACLE_HOME/rdbms/admin/exechae.sql
SQL>@$ORACLE_HOME/rdbms/admin/utlrp.sql
SQL>alter system disable restricted session;
经过验证,处理后alert日志不再有ORA-1400报错了。