5

In Identifying Your Oracle Database Software Release Oracle states that you can find your "platform-specific release number" (patch set) by querying PRODUCT_COMPONENT_VERSION:

To identify the release of Oracle Database that is currently installed and to see the release levels of other database components you are using, query the data dictionary view PRODUCT_COMPONENT_VERSION.

According to this we are using 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

The same occurs with V$VERSION (which PRODUCT_COMPONENT_VERSION is a view of incidentally):

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

However, according to DBA_REGISTRY_HISTORY the database appears to be on 11.2.0.3.51:

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 doesn't necessarily have any data in it so I can't reliably use this view. And, Oracle doesn't seem to provide a standardised method of populating the comments field I seem to be left doing the following and then praying that it works.

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

Is there an easier, reliable, method of finding out the current version, including patch set, programmatically?

1. Also possible: I'm completely misreading this and people have forgotten what they patched.

Ben
  • 51,770
  • 36
  • 127
  • 149
  • Interesting - the banner shown when logging in with SQL/Plus and every single view or table in my database returns 0 for the last part of the version number, *except for* dba_registry_history. http://oracle-dba-yi.blogspot.de/2011/04/how-to-find-database-related-version.html claims that "Subsequent cumulative patch-sets installations, ... will not always be shown in the banner." and subsequently recommends selecting from dba_registry_history, so apparently, that's the way to go. Also note that the ID column seems to be identical to the patch version, but I got no idea how reliable that is. – Frank Schmitt Jan 20 '14 at 14:01

2 Answers2

3

As I cannot guarantee that DBA_REGISTRY_HISTORY will be populated even though it seems to give the correct patch set I've ended up doing the following to populate from V$VERSION if there is nothing.

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

This works because both queries will only return one row and I've tested it on 10.2, 11.2 and 12.1

It is, however, ridiculous and ugly. There's no guarantees that it won't break as everything's a free-text field and Oracle seems to change how it displays the data in these views occasionally. Also, Oracle isn't even consistent within these views. Here's a 12c database, notice the comments field magically reverts the patch set when being upgraded, and how the version and comments don't match.

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.

So, it'd still be nice if this data was exposed in a manner that's easy to use.

Ben
  • 51,770
  • 36
  • 127
  • 149
  • Since you have 12c you may want to take a look at [DBMS_QOPATCH](http://docs.oracle.com/cd/E16655_01/appdev.121/e17602/d_qopatch.htm#ARPLS74834). – Jon Heller Jul 11 '14 at 17:56
  • I also noticed that Windows Patch Bundles do not show up in the banner and not in the registry_history. And to just state the obvious, they do show up in `opatch lspatches` in the command line. Therefore [`select extract(sys.DBMS_QOPATCH.GET_OPATCH_LIST,'//patchDescription|//appliedDate|//patchID') from dual;`](http://docs.oracle.com/database/121/ARPLS/d_qopatch.htm#ARPLS74834) worked for me. – eckes Sep 13 '14 at 17:24
-1

-- list applied patches using 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;

-- list applied patches using opatch

$ORACLE_HOME/OPatch/opatch lsinventory

$ORACLE_HOME/OPatch/opatch lsinventory|grep "Patch description"

$ORACLE_HOME/OPatch/opatch lsinventory -details

pooh06
  • 111
  • 1
  • 3
  • `DBA_REGISTRY_HISTORY` is a straight select from `REGISTRY$HISTORY` without modification so all this does is force people to log in as SYS for no reason... it will provide identical results to that in my answer. – Ben Nov 05 '14 at 11:04
  • I'm aware of that @pooh06, I don't see how you're addressing the issue that I've already proved what you're suggesting doesn't work in the question... – Ben Nov 05 '14 at 18:34
  • I have added this for completeness. The DBA_REGISTRY_HISTORY is a View and SYS.REGISTRY$HISTORY is a Table. I prefer to use the view, because it is easy to remember and more handy. As far as I know a normal user would need some privileges anyway in order to select from the data dictionary. Important thing is that we should never try to modify this metadata. Otherwise we might broke the DB and the Oracle support license. – pooh06 Nov 05 '14 at 18:35
  • The v$version/product_component_version only displays the last full release installed, and it does not show patchsets and cumulative patch upgrades (CPU’s). Maybe there is a confusion between patches and releases. – pooh06 Nov 05 '14 at 18:43