日期:2014-05-16  浏览次数:20578 次

记一次数据库参数compatible降级
众所周知,Oracle参数compatible 主要用于启用Oracle针对某一版本的新特性。但此参数设置时,只能往上调,设置好之后不能往下降。
引用
You can advance the compatibility level of your database. If you do advance the compatibility of your database with the COMPATIBLE initialization parameter, there is no way to start the database using a lower compatibility level setting, except by doing a point-in-time recovery to a time before the compatibility was advanced.

The default value for the COMPATIBLE parameter is the release number of the most recent major release.

Note:For Oracle Database 10g Release 2 (10.2), the default value of the COMPATIBLE parameter is 10.2.0. The minimum value is 9.2.0. If you create an Oracle Database using the default value, you can immediately use all the new features in this release, and you can never downgrade the database.

比如可以将参数compatible从10.2.0.1.0设置成10.2.0.2.0,重启数据库后生效。
引用
SQL> alter system set compatible="10.2.0.2.0" scope=spfile;

System altered.

重启数据库后alert日志会有如下显示,从alert日志中可以明显的看出,compatible升级之后,Oracle会修改控制文件和redolog
引用
Fri May 13 11:59:11 2011
alter database mount
Fri May 13 11:59:15 2011
ALERT: Compatibility of the database is changed from 10.2.0.0.0 to 10.2.0.2.0.
Setting recovery target incarnation to 1
Fri May 13 11:59:15 2011
Successful mount of redo thread 1, with mount id 200680975
Fri May 13 11:59:15 2011
Database mounted in Exclusive Mode
Completed: alter database mount
Fri May 13 11:59:32 2011
alter database open
Fri May 13 11:59:32 2011
Switching redo format version from 10.2.0.0.0 to 10.2.0.2.0 at change 803371
Fri May 13 11:59:32 2011
Thread 1 opened at log sequence 10
  Current log# 1 seq# 10 mem# 0: /oradata/mynewdb/redo01.log
Successful open of redo thread 1

其实,Oracle还会修改数据文件头,从数据文件头的dump信息中可以看出存在compatible信息
引用
aux_file is NOT DEFINED
V10 STYLE FILE HEADER:
        Compatibility Vsn = 169869568=0xa200100
        Db ID=2596133541=0x9abddaa5, Db Name='XE'
        Activation ID=0=0x0
        Control Seq=198940=0x3091c, File size=142080=0x22b00
        File Number=1, Blksiz=8192, File Type=3 DATA


经过以上分析,要实现手工实现compatible降级,必须修改3个地方,即控制文件,数据文件头,redolog。
修改步骤如下,摸索着艰难前进,注意以下操作,除非特殊情况下,严禁在生产库操作
1、在参数文件中将compatible重设为10.2.0.1.0,重启数据后出现参数文件和控制文件不匹配
引用
SQL> startup force
ORACLE instance started.

Total System Global Area  524288000 bytes
Fixed Size                  1262716 bytes
Variable Size             159386500 bytes
Database Buffers          356515840 bytes
Redo Buffers                7122944 bytes
ORA-00201: control file version 10.2.0.2.0 incompatible with ORACLE version
10.2.0.1.0

ORA-00202: control file: '/oradata/mynewdb/control01.ctl'

于是尝试修改控制文件,由于控制文件compatible设置是从参数文件获取的,可以通过重建控制文件的方法,将compatible从10.2.0.2.0降为10.2.0.1.0。
重建控制文件分为noresetlogs和resetlogs两种。