5

识别您的 Oracle 数据库软件版本中,Oracle 声明您可以通过查询PRODUCT_COMPONENT_VERSION找到您的“特定于平台的版本号”(补丁集) :

要确定当前安装的 Oracle 数据库版本并查看您正在使用的其他数据库组件的版本级别,请查询数据字典视图 PRODUCT_COMPONENT_VERSION。

据此,我们正在使用 11.2.0.3.0

SQL> select * from product_component_version;

PRODUCT                             VERSION         STATUS
----------------------------------- --------------- ---------------
NLSRTL                              11.2.0.3.0      Production
Oracle Database 11g                 11.2.0.3.0      64bit Production
PL/SQL                              11.2.0.3.0      Production
TNS for Linux:                      11.2.0.3.0      Production

V$VERSION 也会发生同样的情况(PRODUCT_COMPONENT_VERSION 是偶然的一个视图):

SQL> select * from v$version;

BANNER
---------------------------------------------------------

Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

但是,根据DBA_REGISTRY_HISTORY,数据库似乎在 11.2.0.3.5 1上:

SQL> select action, namespace, version, id, comments from dba_registry_history;

ACTION          NAMESPACE VERSION            ID COMMENTS
--------------- --------- ---------- ---------- ------------------------------
VIEW INVALIDATE                         8289601 view invalidation
UPGRADE         SERVER    11.2.0.3.0            Upgraded from 11.2.0.1.0
APPLY           SERVER    11.2.0.3            0 Patchset 11.2.0.2.0
APPLY           SERVER    11.2.0.3            5 PSU 11.2.0.3.5

DBA_REGISTRY_HISTORY 中不一定包含任何数据,因此我无法可靠地使用此视图。而且,Oracle 似乎没有提供填充评论字段的标准化方法,我似乎只能做以下事情,然后祈祷它可以工作。

select max(regexp_replace(comments, '[^[:digit:].]')) 
         keep (dense_rank first order by action_time desc)
  from dba_registry_history

是否有更简单、可靠的方法来以编程方式查找当前版本(包括补丁集)?

1.也可能:我完全误读了这个,人们忘记了他们修补了什么。

4

2 回答 2

3

由于我不能保证 DBA_REGISTRY_HISTORY 将被填充,即使它似乎提供了正确的补丁集,我最终会执行以下操作以从 V$VERSION 填充(如果没有的话)。

with drh as ( 
select max(regexp_replace(comments, '[^[:digit:].]')) 
            keep (dense_rank last order by action_time) as vers
  from dba_registry_history
       )
 , v$v as ( 
select regexp_substr(banner, '(\d+\.?){5}', 1) as vers
  from v$version 
 where lower(banner) like 'oracle%'
       )
select coalesce(drh.vers, v$v.vers) as patch_set
  from drh
 right outer join v$v
   on 1 = 1

这是可行的,因为这两个查询都只会返回一行,并且我已经在 10.2、11.2 和 12.1 上对其进行了测试

然而,这是荒谬和丑陋的。无法保证它不会中断,因为所有内容都是自由文本字段,并且 Oracle 似乎偶尔会更改在这些视图中显示数据的方式。此外,Oracle 在这些观点中甚至不一致。这是一个 12c 数据库,请注意评论字段在升级时神奇地恢复了补丁集,以及版本和评论如何不匹配。

SQL> select action, version, id, comments from dba_registry_history;

ACTION          VERSION          ID COMMENTS
--------------- ---------- -------- ------------------------
APPLY           11.2.0.3          0 Patchset 11.2.0.2.0
APPLY           11.2.0.3          0 Patchset 11.2.0.2.0
APPLY           11.2.0.3          5 PSU 11.2.0.3.5
VIEW INVALIDATE             8289601 view invalidation
UPGRADE         12.1.0.1.0          Upgraded from 11.2.0.3.0
APPLY           12.1.0.1          0 Patchset 12.1.0.0.0

6 rows selected.

因此,如果这些数据以易于使用的方式公开,那还是很好的。

于 2014-01-29T14:02:34.283 回答
-1

-- 使用 sqlplus 列出应用的补丁

SET linesize 200 pagesize 200
col action_time FOR a28
col version FOR a10
col comments FOR a35
col action FOR a25
col namespace FOR a12
SELECT * FROM registry$history;

-- 使用 opatch 列出应用的补丁

$ORACLE_HOME/OPatch/opatch lsinventory

$ORACLE_HOME/OPatch/opatch lsinventory|grep "补丁说明"

$ORACLE_HOME/OPatch/opatch lsinventory -details

于 2014-11-05T09:36:02.053 回答