Subject: | [PATCH] ora_server_version when database is not open |
I was recently using perl to monitor a Data Guard standby database.
I don't have an Active Data Guard licence, so my standby database
is mounted, but not open. (I was conected using
ora_session_mode=>ORA_SYSDBA.)
I noticed 'undefined value' warnings from Oracle.pm. These were caused by
the subroutine ora_server_version, which was attempting to fetch the
version numbers from the view product_component_version. This view
is only available if the database is open.
The view v$version provides the same data, in a slightly different
format. This view is available in mounted databases, whether open or
not. Here is a patch against the trunk (revision 15009) which changes
ora_server_version to use v$version instead of product_component_version.
P.S. v$version dates back at least to Oracle 7.3.4.
Subject: | server_version_patch.txt |
Index: Oracle.pm
===================================================================
--- Oracle.pm (revision 15009)
+++ Oracle.pm (working copy)
@@ -952,12 +952,15 @@
sub ora_server_version {
my $dbh = shift;
return $dbh->{ora_server_version} if defined $dbh->{ora_server_version};
- $dbh->{ora_server_version} =
- [ split /\./, $dbh->selectrow_array(<<'SQL', undef, 'Oracle%', 'Personal Oracle%') .''];
-SELECT version
- FROM product_component_version
- WHERE product LIKE ? or product LIKE ?
+ my $banner = $dbh->selectrow_array(<<'SQL', undef, 'Oracle%', 'Personal Oracle%');
+SELECT banner
+ FROM v$version
+ WHERE banner LIKE ? OR banner LIKE ?
SQL
+ if (defined $banner) {
+ $dbh->{ora_server_version} = [$1, $2, $3, $4, $5] if
+ $banner =~ /(?:^|\s)(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\d+)(?:\s|$)/;
+ }
}
sub ora_nls_parameters {