# DBinfo.def: Collects Key Information about the Database # $Id: DBinfo.def,v 1.26 2008/02/25 17:32:54 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/DBinfo.def,v 1.26 2008/02/25 17:32:54 mschenke Exp $ # # Change History # 20080225 MSC Change the copyright notice. =head1 NAME DBinfo - Collects Key RDBMS Information =head1 DESCRIPTION This module collects key RDBMS information that is required for database-related modules. The following macros are available: =cut # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('find_dest','find_diag','get_alert_name','get_db_version',\ 'get_diag','get_bdump','get_cdump','get_udump','separator') # Initialisation keep $DB_FIND,$DB_INFO,$DB_VERSION,$BDUMP_DIR,$CDUMP_DIR,$UDUMP_DIR,$DIAG_DIR if !$DB_INFO {var $DB_INFO = true # Define some variables that are shared between macros var $DB_FIND var $DB_VERSION var $BDUMP_DIR var $CDUMP_DIR var $UDUMP_DIR var $DIAG_DIR } # Define the separator macro macro separator {var $cur = $arg[0] import $TOC,$TOP,$TTL,@DBG,@HDR,@TTL,@TXT keep $cur,$sep,$TOC,$TOP,$TTL,@DBG,@HDR,@TTL,@TXT if $cur {if hasOutput(true) write $TOP call resetSqlTimeout() var $sep = $cur if $DBG[$sep] debug $DBG[$sep] prefix {if !isCreated() {write $TTL write $TOC } if $TTL[$sep] write $TTL[$sep] if $TXT[$sep] write $TXT[$sep],'%BR% ' if $HDR[$sep] write $HDR[$sep] } } else {if getSqlMessage() write last,'%BR%' if hasOutput(true) write $TOP if isCreated() toc nvl($arg[2],2),':[[',getFile(),'][rda_report][',$arg[1],']]' } } =head2 find_dest() Determines the background, core, and user destinations. It checks v$parameter first. If the information is not available there, then the macro looks in pfile or in other known places. =cut # Define a macro to extract a parameter value macro get_param {import $ORACLE_HOME var $str = trim(field('\|',2,grepLastSql($arg[0],'f')),"'") var $str = replace($str,'\?',$ORACLE_HOME) var $str = replace($str,'\$ORACLE_HOME',$ORACLE_HOME) var $str = replace($str,'\${ORACLE_HOME}',$ORACLE_HOME) var $str = replace($str,'%ORACLE_HOME%',$ORACLE_HOME) return $str } # Get the dump directories macro find_dest {import $ORACLE_HOME,$ORACLE_SID,$DB_FIND,$BDUMP_DIR,$CDUMP_DIR,$UDUMP_DIR,\ $DIAG_DIR,$MACHINE_NAME var $DB_FIND = true debug ' Inside DBinfo, finding dump destinations' set $sql {SELECT '|' || p.name || '|' || p.value || '|' " FROM v$parameter p " WHERE p.name LIKE '%_dump_dest' OR " p.name = 'diagnostic_dest' OR " p.name = 'spfile'; } if loadSql($sql) {var $BDUMP_DIR = get_param('\|background_dump_dest\|') var $CDUMP_DIR = get_param('\|core_dump_dest\|') var $UDUMP_DIR = get_param('\|user_dump_dest\|') var $DIAG_DIR = get_param('\|diagnostic_dest\|') } #----------------------------------------------------------------------------- # If we do not have a dump directory yet, then it's because we either could # not read the vparameter outputfile, or we could not connect to the database. # Therefore, we should not have found the cdump or udump directories either. # Follow the same series of searches to get cdump and udump as we do for bdump. #----------------------------------------------------------------------------- if !$BDUMP_DIR {# Determine if pfile should be considered if grepLastSql($sql,'\|spfile\|','f') var $use = false elsif getSetting('PFILE_LOCAL') {var $fil = getSetting('PFILE_LOCATION') var $use = testFile('r',$fil) } else var $use = false # Look in pfile if $use {macro get_dump {var ($fil,$key) = @arg import $ORACLE_HOME var $str = trim(value(grepFile($fil,$key,'fi')),"'") var $str = replace($str,'\?',$ORACLE_HOME) var $str = replace($str,'\$ORACLE_HOME',$ORACLE_HOME) var $str = replace($str,'\${ORACLE_HOME}',$ORACLE_HOME) var $str = replace($str,'%ORACLE_HOME%',$ORACLE_HOME) return $str } # Check in the INIT.ORA file debug ' Inside DBinfo, looking for dump dir in ORACLE_HOME' var $BDUMP_DIR = get_dump($fil,'^[^#]*background_dump_dest') var $CDUMP_DIR = get_dump($fil,'^[^#]*core_dump_dest') var $UDUMP_DIR = get_dump($fil,'^[^#]*user_dump_dest') # If any directory is still empty, check for included file and scan it if !and($BDUMP_DIR,$CDUMP_DIR,$UDUMP_DIR) {var $treated{$fil} = 1 # Treat included file, ignoring comments debug ' Inside DBinfo, grepping for IFILE/SPFILE for dump directories' while value(grepFile($fil,'^[^#]*(i|sp)file','fi')) {var $fil = trim(last) var $fil = replace($fil,"'",'',true) var $fil = replace($fil,'\?',$ORACLE_HOME) var $fil = replace($fil,'\$ORACLE_HOME',$ORACLE_HOME) var $fil = replace($fil,'\${ORACLE_HOME}',$ORACLE_HOME) var $fil = replace($fil,'%ORACLE_HOME%',$ORACLE_HOME) break exists($treated{$fil}) if !$BDUMP_DIR var $BDUMP_DIR = get_dump($fil,'^[^#]*background_dump_dest') if !$CDUMP_DIR var $CDUMP_DIR = get_dump($fil,'^[^#]*core_dump_dest') if !$DDUMP_DIR var $UDUMP_DIR = get_dump($fil,'^[^#]*user_dump_dest') var $treated{$fil} = 1 } } } } # Determine the ORACLE_BASE var @dir = () if getEnv('ORACLE_BASE') var $ORACLE_BASE = last if isVms() {var $ORACLE_BASE = getEnv('ORA_ROOT') if getEnv('ORA_DUMP') var @dir = (last) elsif testDir('d',catDir($ORACLE_BASE,concat('db_',$ORACLE_SID),'trace')) var @dir = (lastDir()) } else {var $ORACLE_BASE = dirname($ORACLE_HOME) while true {break testDir('d',catDir($ORACLE_BASE,'admin')) var $dir = dirname($ORACLE_BASE) break compare('eq',$dir,$ORACLE_BASE) var $ORACLE_BASE = $dir } } # If we still do not have the directories, try some well known spots if !$BDUMP_DIR {debug ' Inside DBinfo, still no dump dir, look in basic spots' var $log = get_alert_name() loop $dir (catDir($ORACLE_BASE,'admin',$ORACLE_SID,'bdump'),\ catDir($ORACLE_HOME,'rdbms','log'),\ @dir) {if testFile('r',catFile($dir,$log)) {var $BDUMP_DIR = $dir break } } } if !$CDUMP_DIR {debug ' Inside DBinfo, still no core dump dir, look in basic spots' loop $dir (catDir($ORACLE_BASE,'admin',$ORACLE_SID,'cdump'),\ catDir($ORACLE_HOME,'dbs'),\ @dir) {if testDir('d',$dir) {var $CDUMP_DIR = $dir break } } } if !$UDUMP_DIR {debug ' Inside DBinfo, still no user dump dir, look in basic spots' loop $dir (catDir($ORACLE_BASE,'admin',$ORACLE_SID,'udump'),\ catDir($ORACLE_HOME,'rdbms','log'),\ @dir) {if testDir('d',$dir) {var $UDUMP_DIR = $dir break } } } if !$DIAG_DIR {debug ' Inside DBinfo, still no diagnostic dir, look in basic spots' if testDir('d',catDir($ORACLE_BASE,'diag')) var $DIAG_DIR = lastDir() } } =head2 find_diag() Finds the diagnostic directories. =cut macro find_diag {import $DB_FIND,$DIAG_DIR,$ORACLE_SID if !$DB_FIND call find_dest() if $DIAG_DIR {loop $dir (grepDir($DIAG_DIR,concat('^',quote($ORACLE_SID),'$'),'ir')) {if and(testFile('fr',catFile($dir,'alert','log.xml')),\ testDir('d',catDir($dir,'cdump')),\ testDir('d',catDir($dir,'trace'))) return $dir } } return undef } =head2 get_alert_name() Gets the name of the alert log. =cut macro get_alert_name {import $MACHINE_NAME,$ORACLE_SID if isVms() return concat($MACHINE_NAME,'_',$ORACLE_SID,'_alert.log') return concat('alert_',$ORACLE_SID,'.log') } =head2 get_bdump() Gets and returns the background dump destination. =cut macro get_bdump {import $DB_FIND,$BDUMP_DIR if !$DB_FIND call find_dest() return $BDUMP_DIR } =head2 get_cdump() Gets and returns the core dump destination. =cut macro get_cdump {import $DB_FIND,$CDUMP_DIR if !$DB_FIND call find_dest() return $CDUMP_DIR } =head2 get_diag() Gets and returns the diagnostic destination. =cut macro get_diag {import $DB_FIND,$DIAG_DIR if !$DB_FIND call find_dest() return $DIAG_DIR } =head2 get_udump() Gets and returns the user dump destination. =cut macro get_udump {import $DB_FIND,$UDUMP_DIR if !$DB_FIND call find_dest() return $UDUMP_DIR } =head2 get_db_version($flg,$dft) Determines the database version. When the flag is set, it forces a new detection but does not save the results. A default value can be provided as a second argument. =cut # Determine which version the database says we are dealing. macro get_db_version {var ($flg,$ver) = @arg debug ' Inside DBinfo, gathering product versions' # Determine the version from a previous detection if !$flg {import $DB_VERSION if $DB_VERSION return $DB_VERSION } # Determine the database version set $sql {SELECT '|' || v.banner || '|' " FROM v$version v; } call loadSql($sql) var ($lin) = grepLastSql('Oracle','f') var $ver = check($lin,'^\|Oracle7\s', '7',\ '^\|Oracle8\s', '80',\ '^\|Oracle8i\s', '81',\ '^\|Oracle9i\s', check($lin,'\s9\.2\.','92','90'),\ '^\|Oracle\s', check($lin,'\s11\.1\.','111',\ '\s10\.2\.','102',\ '\s10\.1\.','101',\ '10')) # Save the database version for a next call if !$flg var $DB_VERSION = $ver # Return the database version return $ver } =head1 SEE ALSO See also L, L, L, L, L, L, L, L, L, L, L. =head1 COPYRIGHT NOTICE Copyright (c) 2002-2008, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut