语言
<< 返回文章列表

Oracle 12.2 BigSCN新特性可能的DB Link兼容性问题

2019年4月23日
盖国强
1446

在《云和恩墨技术通讯》的3月刊中,我们再次强调了关于 SCN 问题的预警,提醒大家在2019年6月23日之前采取必要的措施。


下载链接:

https://cs.enmotech.com/docDownload

可是此前我忽略了一种特殊的情形,在这篇文章中必须明确一下。
由于 Oracle Database 12.2版本中引入了一个新特性:BigSCN

在 Oracle 12.2中,SCN 使用 8 Bytes 来记录,而此前是使用 6 Bytes。这就导致了一种情形:
如果Oracle 12.2中 SCN 的大小超过了 Power(2,48),那么12.2之前的所有版本都将无法通过 DB Link 访问 Oracle 12.2 的数据库。

这个问题是无解的。而且和 SCN 的增长率无关。只有将低版本的数据库升级为 12.2 才能够再次通过 DB Link 互联。

但是不要害怕:因为超越 6 Bytes 极限的 SCN 很难遇到,本文所描述的情形仅仅是一种可能性,并不代表大家会遇到。

我们看一下测试。首先在 Oracle 11.2.0.4 的环境,创建一个指向 12.2 的DB Link:


SQL> create database link yhem connect to eygle
2 identified by eygle using 'EYGLE';

Database link created.


众所周知,通过DB Link执行的查询会将两个数据库的SCN同步,这也是Oracle SCN 问题影响特别广泛的原因,以下测试展示了这个过程:


SQL> col scn for 999,999,999,999,999
SQL> select current_scn scn
from v$database;
 SCN
----------------------------
 167,129,852

SQL> select current_scn scn
from v$database@yhem;
 SCN
----------------------------
       4,294,967,074

SQL> select current_scn scn
from v$database;
 SCN
----------------------------
       4,294,967,083
SQL> select banner
from v$version@yhem where rownum < 2;
BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

我们知道,使用 6 Bytes 记录的 SCN,理论极限值是:


SQL> select power(2,48) scn from dual;
SCN
------------------------
281,474,976,710,656

在 Oracle 12.2中,如果 SCN 增进到超过 Power(2,48) 的大小(大幅度增进 SCN 是危险的,请谨慎),如下所示:


SQL> select current_scn scn
from v$database;
SCN
--------------------------------
4,519,057,215,000,399

SQL> oradebug setmypid
Statement processed.
SQL> oradebug dumpvar sga kcsgscn_
kcslf kcsgscn_ [0600113B8, 0600113E8) = 00050F5D 00100E0F

此时如果在 Oracle 11g 中向 12.2 发起通过 DB Link 的查询,就会遇到 ORA-24442错误:

SQL> select * from dual@yhem;
select * from dual@yhem

*
ERROR at line 1:
ORA-24442: SCN exceeds the capability
of the target OCI database or client

注意,ORA-24442 是一个新的错误号,这个错误不是说 SCN 非法、越界或者其他,而是提示“SCN 超过了客户端的能力”,也就是客户端不具备基本的功能性需求:


ORA-24442: SCN exceeds the capability
of the target OCI database or client

Cause: An attempt was made to transfer a system change number (SCN)
to an Oracle database or client that is older than Release 12.2 and
the SCN exceeds the maximum value that such a system can handle.

Action: If needed, update the target
database or client to Release 12.2 or higher.