Apr 18, 2012

Using RDA 4.11 in a RAC Environment

RDA 4.11 is out, with a couple of new features. “Oracle Database Diagnostics Collector” (ORADDC) is one of those. It allows you to easily activate all kinds of traces, dumps, or stack collections.
Once RDA 4.11 installed, run ./rda.pl -T oraddc to collect whatever you need. The tool will guide you. To learn more about its features, you can display its man page: run ./rda.pl -M oraddc or ./rda.pl -M.
This may become one of the most used RDA modules for Oracle Support Services and Oracle database administrators stuck in different situations. For now, let’s start with a more basic question: “How to leverage RDA in a RAC environment ?”

About RDA

RDA (Remote Diagnostic Agent) is one of the primary tools used by Oracle Support Services to diagnose any problem related to the Oracle stacks (from the Virtual Machine to the CRM). You can leverage this tool for your own needs and to speed up your problem resolution.

Using RDA before you install the Clusterware

Installing the Oracle Clusterware is an error-prone process, and in most cases, the errors come from unmet prerequisites, Fortunately, the CVU (Cluster Verification Utility) helps diagnose any problem in the initial setup you’ve performed. The best way to use it is probably to download the latest version and to validate the prerequisites according to the release you want to install. Once you’ve downloaded and unzipped the latest release from OTN, you can for example check if the prerequisites are met before you install Clusterware, with a command like the one below:
$ su - oracle
$ mkdir cvu
$ cd cvu
$ # Change the URL accordingly to the CVU latest
$ # release and your platform
$ wget http://download.oracle.com/otndocs/products/clustering/cvu/cvu_linux_64_112007.zip
$ unzip cvu_*.zip
$ cd bin
$ ./cluvfy stage -pre crsinst    \
      -n node1,node2,node3,node4 \
      -r 10gR2 -verbose 
Using the latest CVU will reduce the number of errors, and the checks are more accurate with the latest releases. However, you can also use RDA on a per-node basis to check the Oracle prerequisites. In order to do that, use the HCVE (Health Check/Validation Engine) tool. Below is an example of this use of RDA HCVE:
$ su - oracle
$ mkdir rda-4.11
$ cd rda-4.11
$ # Change the distribution accordingly to the latest
$ # RDA release and platform. Use your Metalink Credentials
$ ftp updates.oracle.com
ftp> cd 6854532
ftp> ls
ftp> get p6854532_4110_Linux-x86.zip
ftp> bye
$ unzip 6854532*.zip
$ cd rda
$ ./rda.pl -T hcve

Processing HCVE tests ...
Available Pre-Installation Rule Sets:
   1. Oracle Database 10g R1 (10.1.0) PreInstall (Linux-x86)
   2. Oracle Database 10g R1 (10.1.0) PreInstall (Linux AMD64)
   3. Oracle Database 10g R1 (10.1.0) PreInstall (IA-64 Linux)
   4. Oracle Database 10g R2 (10.2.0) PreInstall (Linux AMD64)
   5. Oracle Database 10g R2 (10.2.0) PreInstall (IA-64 Linux)
   6. Oracle Database 10g R2 (10.2.0) PreInstall (Linux-x86)
   7. Oracle Database 11g R1 (11.1.0) PreInstall (Linux AMD64)
   8. Oracle Database 11g R1 (11.1.0) PreInstall (Linux-x86)
   9. Oracle Application Server 10g (9.0.4) PreInstall (Linux)
  10. Oracle Application Server 10g R2 (10.1.2) PreInstall (Linux)
  11. Oracle Application Server 10g R3 (10.1.3) PreInstall (Linux AMD64)
  12. Oracle Application Server 10g R3 (10.1.3) PreInstall (IA-64 Linux)
  13. Oracle Application Server 10g R3 (10.1.3) PreInstall (Linux-x86)
  14. Oracle Portal PreInstall (Generic)
Available Post-Installation Rule Sets:
  15. Oracle Portal PostInstall (generic)
  16. RAC 10G DB and OS Best Practices (Linux)
  17. Data Guard PostInstall (Generic)
Enter the HCVE rule set number
Hit 'Return' to accept the default (1)
> 4
Enter value for < Planned ORACLE_HOME location or if set >
Hit 'Return' to accept the default ($ORACLE_HOME)
>

Test "Oracle Database 10g R2 (10.2.0) PreInstall (Linux AMD64)" executed at Sat Mar 15 15:52:17 2008

Test Results
~~~~~~~~~~~~

   ID NAME                 RESULT VALUE
===== ==================== ====== ========================================
   10 OS Certified?        FAILED Not certified [Red Hat version]
   20 User in /etc/passwd? PASSED userOK
   30 Group in /etc/group? PASSED GroupOK
   40 Input ORACLE_HOME    RECORD $ORACLE_HOME
   50 ORACLE_HOME Valid?   PASSED OHexists
   60 O_H Permissions OK?  FAILED NoWritePerm
   70 Umask Set to 022?    PASSED UmaskOK
   80 LDLIBRARYPATH Unset? FAILED IsSet
   90 JAVA_HOME Unset?     FAILED IsSet
  100 Other O_Hs in PATH?  FAILED OratabEntryInPath
  110 oraInventory Permiss PASSED oraInventoryOK
  120 /tmp Adequate?       PASSED TempSpaceOK
  130 Swap (in MB)         PASSED 3906
  140 RAM (in MB)          FAILED 1003
  150 Swap OK?             PASSED SwapToRAMOK
  160 Disk Space OK?       PASSED DiskSpaceOK
  170 Kernel Parameters OK PASSED KernelOK
  180 Got ld,nm,ar,make?   PASSED ld_nm_ar_make_found
  190 ulimits OK?          FAILED TimeNotDefined StackTooSmall NoFilesN..>
  200 EL4 RPMs OK?         PASSED NotEnterprise
  204 RHEL3 RPMs OK?       PASSED NotRHEL3
  205 RHEL4 RPMs OK?       PASSED NotRHEL4
  209 SUSE SLES9 RPMs OK?  PASSED NotSuSE
  210 SUSE SLES10 RPMs OK? PASSED NotSuSE
  214 ip_local_port_range  PASSED ip_local_port_rangeOK
  220 Tainted Kernel?      PASSED NotVerifiable
  230 Other OUI Up?        PASSED NoOtherOUI
Result file: /home/arkzoyd/Customers/TPG/rda/output/RDA_HCVE_A201DB10R2_lna_res.htm

Run an RDA collection once the Clusterware installed

Once the Clusterware correctly is installed and configured, RDA can easily be installed in the cluster (Check Metalink Note note 359395.1 for more details). It enables you to run a RDA collection cluster-wide. To proceed with such an installation, just run the command below, once the cluster is configured:
$ ./rda.pl -vX Remote setup_cluster
-----------------------------------------------------
Requesting common information
-----------------------------------------------------
Where RDA should be installed on the remote nodes?
Hit 'Return' to accept the default
(/home/oracle/rda-4.11/rda)
>

Where setup files and reports should be stored on the remote nodes?
Hit 'Return' to accept the default
(/home/oracle/rda-4.11/rda)
>

Should an alternate login be used to execute remote requests (Y/N)?
Hit 'Return' to accept the default (N)
>

Enter an Oracle User ID (userid only) to view DBA_ and V$ tables. If RDA will
be run under the Oracle software owner's ID, enter a '/' here, and select Y at
the SYSDBA prompt to avoid being prompted for the database password at
runtime.
Hit 'Return' to accept the default (system)
> /

Is '/' a sysdba user (will connect as sysdba) (Y/N)?
Hit 'Return' to accept the default (N)
> Y
-----------------------------------------------------
Requesting information for node node1
-----------------------------------------------------
Enter the Oracle Home to be analyzed on the node node1
Hit 'Return' to accept the default (/u01/app/oracle/product/10.2.0/db_1)
>

Enter the Oracle SID to be analyzed on the node node1
Hit 'Return' to accept the default (racdb1)
> racdb1
-----------------------------------------------------
Requesting information for node node2
-----------------------------------------------------

Enter the Oracle Home to be analyzed on the node node2
Hit 'Return' to accept the default (/u01/app/oracle/product/10.2.0/db_1)
>

Enter the Oracle SID to be analyzed on the node node2
Hit 'Return' to accept the default (racdb2)
> racdb2

-----------------------------------------------------
RAC Setup Summary
-----------------------------------------------------
Nodes:
. NOD001  node1/racdb1
. NOD002  node2/racdb2
2 nodes found
-----------------------------------------------------
S909RDSP: Produces the Remote Data Collection Reports
-----------------------------------------------------
        Updating the setup file ...
Once RDA is installed, you can run a cluster-wide collection with the command below:
$ ./rda.pl -v -e REMOTE_TRACE=1
The two options are used to display the progress of the various operations executed by RDA. Once the collection is done, you can get the .zip file to review the results. It contains a directory called remote, with the RDA collection for each one of the nodes. Here is an example of the output:
rda-rac.jpg

Use RDA to compare cluster nodes or node evolutions

RDA contains another useful tool that you can leverage with a cluster (see previous section to install RDA in a cluster). This tool is named diff. It allows you to collect Oracle-related system information for one or all the nodes of a cluster. When RDA is installed in the cluster, you can compare two nodes or one node at two different points in time. In order to use this tool, just run a collection. Here is an example of how to run a collection for a set named myset and for the sample 1 of it:
$ ./rda.pl -T diff:A:myset,1
You can also run it in interactive mode with the command below:
$ ./rda.pl -T diff
To generate the output, you can run ./rda.pl -T diff in interactive mode. The -C option will guide you through the process of generating the report you need.

Use RDA to check the RAC database settings

Once the database software is installed and the database is created, you can check the RAC settings with the RDA HCVE tool. In order to proceed, you need to make sure you have the SYSTEM password and you’ve set the ORACLE_HOMEPATH, andORACLE_SID environment variables.
$ su - oracle
$ cd rda-4.11
$ . oraenv
ORACLE_SID = [RACDB] ?
$ export ORACLE_SID=RACDB1
$ ./rda.pl -T hcve
Processing HCVE tests ...
Available Pre-Installation Rule Sets:
   1. Oracle Database 10g R1 (10.1.0) PreInstall (Linux-x86)
   2. Oracle Database 10g R1 (10.1.0) PreInstall (Linux AMD64)
   3. Oracle Database 10g R1 (10.1.0) PreInstall (IA-64 Linux)
   4. Oracle Database 10g R2 (10.2.0) PreInstall (Linux AMD64)
   5. Oracle Database 10g R2 (10.2.0) PreInstall (IA-64 Linux)
   6. Oracle Database 10g R2 (10.2.0) PreInstall (Linux-x86)
   7. Oracle Database 11g R1 (11.1.0) PreInstall (Linux AMD64)
   8. Oracle Database 11g R1 (11.1.0) PreInstall (Linux-x86)
   9. Oracle Application Server 10g (9.0.4) PreInstall (Linux)
  10. Oracle Application Server 10g R2 (10.1.2) PreInstall (Linux)
  11. Oracle Application Server 10g R3 (10.1.3) PreInstall (Linux AMD64)
  12. Oracle Application Server 10g R3 (10.1.3) PreInstall (IA-64 Linux)
  13. Oracle Application Server 10g R3 (10.1.3) PreInstall (Linux-x86)
  14. Oracle Portal PreInstall (Generic)
Available Post-Installation Rule Sets:
  15. Oracle Portal PostInstall (generic)
  16. RAC 10G DB and OS Best Practices (Linux)
  17. Data Guard PostInstall (Generic)
Enter the HCVE rule set number
Hit 'Return' to accept the default (1)
> 16

Enter the password for 'SYSTEM':
Please re-enter it to confirm:

Test "RAC 10G DB and OS Best Practices (Linux)" executed at Sat Mar 15 16:08:08 2008

Test Results
~~~~~~~~~~~~

   ID NAME                 RESULT VALUE
===== ==================== ====== ========================================
   10 ORA_CRS_HOME         RECORD /u01/app/oracle/product/10.2.0/crs
  100 Database Name        RECORD RACDB
  102 Database Version     RECORD 10.2.0.3.0
  104 Interconnect Network RECORD
  106 DB Block Size        RECORD 8192
  108 DB File Multiblock R RECORD 16
  120 Max Commit Propagati PASSED 0
  130 SYS.AUDSES$ Cache Si PASSED 10000
  132 SYS.IDGEN1$ Cache Si FAILED 20
  140 Parallel Execution M FAILED 2152
  150 Min Parallel Servers RECORD 3
  152 Min Parallel Servers FAILED 0
  200 $ORA_CRS_HOME Define PASSED Found
  210 Remote Access        PASSED All loaded
  220 _USR_ORA_DEBUG / CRS FAILED node1:? node2:?
  230 _USR_ORA_DEBUG / ORA FAILED node1:? node2:?
  240 rmem_max             PASSED OK
  250 UDP Buffer Size      PASSED OK
  260 wmem_max             PASSED OK
  270 rmem_default         PASSED OK
  280 wmem_default         PASSED OK
  290 Sysrq Magic Keys     PASSED OK
  300 Oracle Executable Li PASSED linked
  310 hangcheck-timer      FAILED node1:Unknown node2:Unknown
  320 aio-max-size Setting FAILED node1:Unknown node2:Unknown
  330 Memory (32-bit)      PASSED OK
  340 Swap (32-bit)        PASSED OK
  350 Swap (64-bit)        FAILED [node1:]Swap<2RAM [node2:..>
  360 Patch List           PASSED Complete
Result file: /home/oracle/rda-4.11/rda/output/RDA_HCVE_P400RAC_lnx_res.htm
RDA can probably do much more for you, but this is another story.

Apr 9, 2012

Find component Version in Apps 11i/R12/12i

Q. How to find Apps Version (11i/R12/12i).
A.  Connect to database as user apps
SQL> select release_name from apps.fnd_product_groups;
Output like 12.0.4 or 11.5.10.2

Q. Web Server/Apache or Application Server in Apps 11i/R12A.
Log in as Application user, set environment variable and run below query
$IAS_ORACLE_HOME/Apache/Apache/bin/httpd -version
Output for 11i should be like
Server version: Oracle HTTP Server Powered by Apache/1.3.19 (Unix)
Server built:   Jan 26 2005 11:06:44 (iAS 1.0.2.2.2 rollup 5)
Output for R12 should be like
Server version: Oracle-Application-Server-10g/10.1.3.0.0Oracle-HTTP-Server
Server built:   Dec  4 2006 14:44:38

Q. Forms & Report version (aka developer 6i) in 11iA. 
Log in as Application user, set environment variable and run below query
$ORACLE_HOME/bin/f60run | grep Version | grep Forms
output like
Forms 6.0 (Forms Runtime) Version 6.0.8.25.2 (Production)
Check fourth character in version 25 which means Forms 6i patchset 16 (25-9)


Q. Forms & Report version in R12/12iA.
Log in as Application user, set environment variable and run below query
$ORACLE_HOME/bin/rwrun | grep Release
Output should be like
Report Builder: Release 10.1.2.2.0
You can safely ignore warnings

Q. Database Version in 11i/R12/12i
A. Go to database section below.

Q. Oracle Jinitiator in 11i/R12/12iA. 
Log in as Application user, set environment variable and run below query
grep jinit_ver_comma $CONTEXT_FILE
(Default is Java Plug-In for R12/12i )

Q. Oracle Java Plug-in in 11i/R12/12iA. Log in as Application user, set environment variable and run below query
grep plugin $CONTEXT_FILE


Q. File Version on file systemadident Header
or
strings | grep Header
Here adident is AD Utility (Oracle Apps) and strings is Unix utility

Q. Version of pld file*.pld are source code of *.pll which are inturn source of *.plx.  *.pll is in $AU_TOP/resource and to find its version check
adident Header $AU_TOP/resource/.pll
IGSAU012.pll:
$Header IGSAU012.pld 115.1.115100.1 2004/04/01 05:40:18 appldev ship $
or
strings $AU_TOP/resource/.pll | grep -i header
FDRCSID(‘$Header: IGSAU012.pld 115.1.115100.1 2004/04/01 05:40:18 appldev ship $’);

Q. OA Framework Version
A.http:// hostname.domainName:port/OA_HTML/OAInfo.jsp (Only for 11i)
A.  Log in as Application user, set environment variable and run below query
adident Header $FND_TOP/html/OA.jsp
adident Header $OA_HTML/OA.jsp
output for both should look like
$Header OA.jsp 115.60 2006/03/31 00:47:28 atgops1 noship $
120.21 means OA Framework Version (coming soon..)
115.60 means OA Framework Version (coming soon..)
115.56 means OA Framework Version (coming soon..)
115.36 means OA Framework Version 5.7
115.27 means OA Framework Version 5.6E
115.26 means OA Framework Version 5.5.2E

Q. Discoverer Version for 11i (3i or 4i)
A. Log in as Application user, set environment variable and run below query
$ORACLE_HOME/bin/disc4ws | grep -i Version

Q. Discoverer Version for 11i or R12 (10g AS)
Check under Application Server Section as 10g AS Discoverer is on standalone

Q. Workflow Version with AppsA. 
Connect to Database as apps user
SQL> select TEXT Version from   WF_RESOURCES where  NAME = ‘WF_VERSION’;
Output like 2.6.0 means workflow version 2.6.0

Version for Fusion Middleware Component
Identity Management component Version/Release Number
A. Oracle Single Sign OnConnect to database which holds SSO repository
SQL> select version from orasso.wwc_version$;
B. Oracle Internet Directory
There are two component in OID (Software/binaries & Schema/database)
To find software/binary version
$ORACLE_HOME/bin/oidldapd -version
output should look like
oidldapd: Release 10.1.4.0.1 – Production on mon jul 14 14:14:21 2008
Copyright (c) 1982, 2006 Oracle.  All rights reserved.
To find Schema Version/ database use
ldapsearch -h -p -D “cn=orcladmin” -w “” -b “” \
-s base “objectclass=*” orcldirectoryversion
and output should be like
version: 1
dn:
orcldirectoryversion: OID 10.1.4.0.1
or run following query in database
SQL> select attrval from ods.ds_attrstore where entryid = 1 and attrname = ‘orcldirectoryversion’;
Output should be like OID 10.1.4.0.1
C. Application Server
1. Oracle Application Server 10g Rel 3 (10.1.3.X)
cat $ORACLE_HOME/config/ias.properties | grep Version
Version=10.1.3.0.0
2. For Oracle Application Server 10.1.2 (Prior to Oracle WebLogic Server)
If application server is registered in database (Portal, Discoverer) check from database
SQL> select * from ias_versions;
or
SQL> select * from INTERNET_APPSERVER_REGISTRY.SCHEMA_VERSIONS;

D. AOC4J (Oracle Container for J2EE)Set ORACLE_HOME
cd $ORACLE_HOME/j2ee/home
java -jar oc4j.jar -version

E. Oracle PortalSQL> select version from portal.wwc_version$;

Database Component
I) Oracle Database
To find database version
SQL> select * from v$version;
or
All component version in database
$ORACLE_HOME/OPatch/opatch lsinventory -detail

Oracle Enterprise ManagerMetalink Note 605398.1  How to to find the version of the main EM components

Unix Operating System
Solaris $ cat /etc/release
Red Hat Linux $ cat /etc/redhat-release

How to check Oracle Apps/EBS version

Run following SQL from apps user ;
select RELEASE_NAME from fnd_product_groups; 
You should see output like
RELEASE_NAME
-----------------------
11.5.10.2

Top DBA Shell Scripts for Monitoring the Database


by Daniel T. Liu
Introduction
This article focuses on the DBA's daily responsibilities for monitoring  Oracle databases and provides tips and techniques on how DBAs can turn their  manual, reactive monitoring activities into a set of proactive shell scripts.  The article first reviews some commonly used Unix commands by DBAs. It explains  the Unix Cron jobs that are used as part of the scheduling mechanism to execute  DBA scripts. The article covers eight important scripts for monitoring Oracle  database:


UNIX Basics for the DBA
Basic UNIX Command
The following is a list of commonly used Unix command:
      • ps - Show process
      • grep - Search files for text patterns
      • mailx - Read or send mail
      • cat - Join files or display them
      • cut - Select columns for display
      • awk - Pattern-matching language
      • df - Show free disk space
Here are some examples of how the DBA uses these commands:

      • List available instances on a server:
$ ps -ef | grep smon
  oracle 21832     1  0   Feb 24 ?       19:05 ora_smon_oradb1
  oracle   898     1  0   Feb 15 ?        0:00 ora_smon_oradb2
    dliu 25199 19038  0 10:48:57 pts/6    0:00 grep smon
  oracle 27798     1  0 05:43:54 ?        0:00 ora_smon_oradb3
  oracle 28781     1  0   Mar 03 ?        0:01 ora_smon_oradb4

      • List available listeners on a server:
$ ps -ef | grep listener | grep -v grep
  oracle 23879    1  0   Feb 24 ?  33:36 /8.1.7/bin/tnslsnr listener_db1 -inherit
  oracle 27939    1  0 05:44:02 ?  0:00  /8.1.7/bin/tnslsnr listener_db2 -inherit
  oracle 23536    1  0   Feb 12 ?  4:19  /8.1.7/bin/tnslsnr listener_db3 -inherit
  oracle 28891    1  0   Mar 03 ?  0:01  /8.1.7/bin/tnslsnr listener_db4 -inherit

      • Find out file system usage for Oracle archive  destination:
$ df -k | grep oraarch
  /dev/vx/dsk/proddg/oraarch 71123968 4754872 65850768  7%  /u09/oraarch

      • List number of lines in the alert.log file:
$ cat alert.log | wc -l
   2984

      • List all Oracle error messages from the alert.log file:
$ grep ORA- alert.log
  ORA-00600: internal error code, arguments: [kcrrrfswda.1], [], [], [], [], []
  ORA-00600: internal error code, arguments: [1881], [25860496], [25857716], []
CRONTAB Basics
A crontab file is comprised of six fields:
       Minute0-59
       Hour0-23
       Day of month1-31
       Month1 - 12
       Day of Week0 - 6, with 0 = Sunday
       Unix Command or Shell Scripts
      • To edit a crontab file, type:
   Crontab -e

      • To view a crontab file, type:
                 Crontab -l
     0  4 * * 5       /dba/admin/analyze_table.ksh
     30 3  * * 3,6    /dba/admin/hotbackup.ksh /dev/null 2>&1

In the example above, the first entry shows that a script to analyze a table  runs every Friday at 4:00 a.m. The second entry shows that a script to perform a  hot backup runs every Wednesday and Saturday at 3:00 a.m.
Top DBA Shell Scripts for Monitoring the Database
The eight shell scripts provided below cover 90 percent of a DBA's daily  monitoring activities. You will need to modify the UNIX environment variables as  appropriate.
Check Oracle Instance Availability
The oratab file lists all the databases on a server:
$ cat /var/opt/oracle/oratab
###################################################################
## /var/opt/oracle/oratab                                        ##
###################################################################
oradb1:/u01/app/oracle/product/8.1.7:Y
oradb2:/u01/app/oracle/product/8.1.7:Y
oradb3:/u01/app/oracle/product/8.1.7:N
oradb4:/u01/app/oracle/product/8.1.7:Y

The following script checks all the databases listed in the oratab file, and  finds out the status (up or down) of databases:
################################################################### 
## ckinstance.ksh ## 
###################################################################
ORATAB=/var/opt/oracle/oratab
echo "`date`   "
echo  "Oracle Database(s) Status `hostname` :\n"
db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
pslist="`ps -ef | grep pmon`"
for i in $db ; do
  echo  "$pslist" | grep  "ora_pmon_$i"  > /dev/null 2>$1
  if (( $? )); then
        echo "Oracle Instance - $i:       Down"
  else
        echo "Oracle Instance - $i:       Up"
  fi
done     

Use the following to make sure the script is executable:
$ chmod 744 ckinstance.ksh
$ ls -l ckinstance.ksh
-rwxr--r--   1 oracle     dba     657 Mar  5 22:59 ckinstance.ksh*
Here is an instance availability report:
$ ckinstance.ksh
Mon Mar  4 10:44:12 PST 2002  
Oracle Database(s) Status for DBHOST server:
Oracle Instance - oradb1:   Up
Oracle Instance - oradb2:   Up
Oracle Instance - oradb3:   Down
Oracle Instance - oradb4:   Up        
Check Oracle Listener's Availability
A similar script checks for the Oracle listener. If the listener is down, the  script will restart the listener:
#######################################################################
## cklsnr.sh                                                         ##
#######################################################################
#!/bin/ksh
DBALIST="primary.dba@company.com,another.dba@company.com";export DBALIST
cd /var/opt/oracle
rm -f lsnr.exist 
ps -ef | grep mylsnr | grep -v grep  > lsnr.exist
if [ -s lsnr.exist ]
then
    echo 
else
echo "Alert" | mailx -s "Listener 'mylsnr' on `hostname` is down" $DBALIST 
    TNS_ADMIN=/var/opt/oracle; export TNS_ADMIN
    ORACLE_SID=db1; export ORACLE_SID   
    ORAENV_ASK=NO; export ORAENV_ASK
    PATH=$PATH:/bin:/usr/local/bin; export PATH
    . oraenv
    LD_LIBRARY_PATH=${ORACLE_HOME}/lib;export LD_LIBRARY_PATH
    lsnrctl start mylsnr
fi
Check Alert Logs (ORA-XXXXX)
Some of the environment variables used by each script can be put into one  profile:
#######################################################################
## oracle.profile ##
#######################################################################
EDITOR=vi;export EDITOR ORACLE_BASE=/u01/app/oracle; export
ORACLE_BASE ORACLE_HOME=$ORACLE_BASE/product/8.1.7; export
ORACLE_HOME LD_LIBRARY_PATH=$ORACLE_HOME/lib; export
LD_LIBRARY_PATH TNS_ADMIN=/var/opt/oracle;export
TNS_ADMIN NLS_LANG=american; export
NLS_LANG NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'; export
NLS_DATE_FORMAT ORATAB=/var/opt/oracle/oratab;export
ORATAB PATH=$PATH:$ORACLE_HOME:$ORACLE_HOME/bin:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/
sbin:/usr/openwin/bin:/opt/bin:.; export
PATH DBALIST="primary.dba@company.com,another.dba@company.com";export
DBALIST
The following script first calls oracle.profile to set up all the environment  variables. The script also sends the DBA a warning e-mail if it finds any Oracle  errors:
####################################################################
## ckalertlog.sh                                                  ##
####################################################################
#!/bin/ksh
. /etc/oracle.profile
for SID in `cat $ORACLE_HOME/sidlist`
do
    cd $ORACLE_BASE/admin/$SID/bdump
    if [ -f alert_${SID}.log ]
    then
        mv alert_${SID}.log alert_work.log
        touch alert_${SID}.log
        cat alert_work.log >> alert_${SID}.hist
        grep ORA- alert_work.log > alert.err
    fi
    if [ `cat alert.err|wc -l` -gt 0 ]
    then
        mailx -s "${SID} ORACLE ALERT ERRORS" $DBALIST < alert.err
    fi
    rm -f alert.err
    rm -f alert_work.log
done
Clean Up Old Archived Logs
The following script cleans up old archive logs if the log file system  reaches 90-percent capacity:
$ df -k | grep arch
Filesystem                kbytes   used     avail    capacity  Mounted on
/dev/vx/dsk/proddg/archive 71123968 30210248 40594232   43%  /u08/archive
#######################################################################
## clean_arch.ksh                                                    ##
#######################################################################
#!/bin/ksh
df -k | grep arch > dfk.result
archive_filesystem=`awk  -F" "  '{ print $6 }' dfk.result`
archive_capacity=`awk  -F" "  '{ print $5 }' dfk.result`

if [[ $archive_capacity > 90% ] ]
then
    echo "Filesystem ${archive_filesystem} is ${archive_capacity} filled"
    # try one of the following option depend on your need
    find $archive_filesystem -type f -mtime +2 -exec rm -r {} \;    
    tar 
    rman
fi
Analyze Tables and Indexes (for Better Performance)
Below, I have shown an example on how to pass parameters to a script:
####################################################################
## analyze_table.sh ##
#################################################################### 
#!/bin/ksh #
input parameter: 1: password # 2: SID if (($#<1)) then echo "Please enter 
'oracle'
user password as the first parameter !" exit 0 fi if (($#<2)) then echo 
"Please enter
instance name as the second parameter!" exit 0 fi
To execute the script with parameters, type:
$ analyze_table.sh manager oradb1

The first part of script generates a file analyze.sql, which contains the  syntax for analyzing table. The second part of script analyzes all the  tables:
#####################################################################
## analyze_table.sh ##
#####################################################################
sqlplus -s <oracle/$1@$2
set heading off
set feed off
set pagesize 200
set linesize 100
spool analyze_table.sql
select 'ANALYZE TABLE ' || owner || '.' || segment_name || 
       ' ESTIMATE STATISTICS SAMPLE 10 PERCENT;'
from dba_segments
where segment_type = 'TABLE'
and owner not in ('SYS', 'SYSTEM');
spool off
exit
!
sqlplus -s <oracle/$1@$2
@./analyze_table.sql
exit
!
  

Here is an example of analyze.sql:
$ cat analyze.sql
ANALYZE TABLE HIRWIN.JANUSAGE_SUMMARY ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE HIRWIN.JANUSER_PROFILE ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE APPSSYS.HIST_SYSTEM_ACTIVITY ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE HTOMEH.QUEST_IM_VERSION ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE JSTENZEL.HIST_SYS_ACT_0615 ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE JSTENZEL.HISTORY_SYSTEM_0614 ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE JSTENZEL.CALC_SUMMARY3 ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE IMON.QUEST_IM_LOCK_TREE ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE APPSSYS.HIST_USAGE_SUMMARY ESTIMATE STATISTICS SAMPLE 10 PERCENT;
ANALYZE TABLE PATROL.P$LOCKCONFLICTTX ESTIMATE STATISTICS SAMPLE 10 PERCENT;
Check Tablespace Usage
This scripts checks for tablespace usage. If tablespace is 10 percent free,  it will send an alert e-mail.
#####################################################################
## ck_tbsp.sh ##
#####################################################################
#!/bin/ksh
sqlplus -s <oracle/$1@$2
set feed off
set linesize 100
set pagesize 200
spool tablespace.alert
SELECT F.TABLESPACE_NAME,
       TO_CHAR ((T.TOTAL_SPACE - F.FREE_SPACE),'999,999') "USED (MB)",
       TO_CHAR (F.FREE_SPACE, '999,999') "FREE (MB)",
       TO_CHAR (T.TOTAL_SPACE, '999,999') "TOTAL (MB)",
       TO_CHAR ((ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)),'999')||' %' PER_FREE
FROM   (
       SELECT       TABLESPACE_NAME, 
                    ROUND (SUM (BLOCKS*(SELECT VALUE/1024
                                        FROM V\$PARAMETER 
                                        WHERE NAME = 'db_block_size')/1024)
                           ) FREE_SPACE
       FROM DBA_FREE_SPACE
       GROUP BY TABLESPACE_NAME
       ) F,
       (
       SELECT TABLESPACE_NAME,
       ROUND (SUM (BYTES/1048576)) TOTAL_SPACE
       FROM DBA_DATA_FILES
       GROUP BY TABLESPACE_NAME
       ) T
WHERE F.TABLESPACE_NAME = T.TABLESPACE_NAME
AND (ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)) < 10;
spool off
exit
!
if [ `cat tablespace.alert|wc -l` -gt 0 ]
then
          cat tablespace.alert -l tablespace.alert > tablespace.tmp
          mailx -s "TABLESPACE ALERT for ${2}" $DBALIST < tablespace.tmp
fi

An example of the alert mail output is as follows:
TABLESPACE_NAME     USED (MB)   FREE (MB)         TOTAL (MB)            PER_FREE 
------------------- --------- ----------- ------------------- ------------------
SYSTEM              2,047             203               2,250                9 %
STBS01                302              25                327                 8 %          
STBS02                241              11                252                 4 % 
STBS03                233              19                252                 8 %
Find Out Invalid Database Objects
The following finds out invalid database objects:
#####################################################################          
## invalid_object_alert.sh ## 
#####################################################################          
#!/bin/ksh 
. /etc/oracle.profile 
sqlplus -s <oracle/$1@$2 
set          feed off 
set heading off 
column object_name format a30 
spool invalid_object.alert          
SELECT  OWNER, OBJECT_NAME, OBJECT_TYPE, STATUS 
FROM    DBA_OBJECTS 
WHERE   STATUS = 'INVALID' 
ORDER BY OWNER, OBJECT_TYPE, OBJECT_NAME; 
spool off          
exit 

if [ `cat invalid_object.alert|wc -l` -gt 0 ] 
then 
    mailx -s "INVALID OBJECTS for ${2}" $DBALIST < invalid_object.alert 
fi
$ cat invalid_object.alert
OWNER        OBJECT_NAME           OBJECT_TYPE          STATUS
----------------------------------------------------------------------
HTOMEH       DBMS_SHARED_POOL            PACKAGE BODY          INVALID
HTOMEH       X_$KCBFWAIT                 VIEW                  INVALID
IMON         IW_MON                      PACKAGE               INVALID
IMON         IW_MON                      PACKAGE BODY          INVALID
IMON         IW_ARCHIVED_LOG             VIEW                  INVALID
IMON         IW_FILESTAT                 VIEW                  INVALID
IMON         IW_SQL_FULL_TEXT            VIEW                  INVALID
IMON         IW_SYSTEM_EVENT1            VIEW                  INVALID
IMON         IW_SYSTEM_EVENT_CAT         VIEW                  INVALID
LBAILEY      CHECK_TABLESPACE_USAGE      PROCEDURE             INVALID
PATROL       P$AUTO_EXTEND_TBSP          VIEW                  INVALID
SYS          DBMS_CRYPTO_TOOLKIT         PACKAGE               INVALID
SYS          DBMS_CRYPTO_TOOLKIT         PACKAGE BODY          INVALID
SYS          UPGRADE_SYSTEM_TYPES_TO_816 PROCEDURE             INVALID
SYS          AQ$_DEQUEUE_HISTORY_T       TYPE                  INVALID
SYS          HS_CLASS_CAPS               VIEW                  INVALID 
SYS          HS_CLASS_DD                 VIEW                  INVALID
Monitor Users and Transactions (Dead Locks, et al)
This script sends out an alert e-mail if dead lock occurs:
###################################################################
## deadlock_alert.sh ##
###################################################################
#!/bin/ksh
. /etc/oracle.profile
sqlplus -s <oracle/$1@$2
set feed off
set heading off
spool deadlock.alert
SELECT   SID, DECODE(BLOCK, 0, 'NO', 'YES' ) BLOCKER,
              DECODE(REQUEST, 0, 'NO','YES' ) WAITER
FROM     V$LOCK 
WHERE    REQUEST > 0 OR BLOCK > 0 
ORDER BY block DESC; 
spool off
exit
!
if [ `cat deadlock.alert|wc -l` -gt 0 ]
then
    mailx -s "DEADLOCK ALERT for ${2}" $DBALIST < deadlock.alert
fi
Conclusion
0,20,40 7-17 * * 1-5 /dba/scripts/ckinstance.sh > /dev/null 2>&1
0,20,40 7-17 * * 1-5 /dba/scripts/cklsnr.sh > /dev/null 2>&1
0,20,40 7-17 * * 1-5 /dba/scripts/ckalertlog.sh > /dev/null 2>&1
30         * * * 0-6 /dba/scripts/clean_arch.sh > /dev/null 2>&1
*          5 * * 1,3 /dba/scripts/analyze_table.sh > /dev/null 2>&1
*          5 * * 0-6 /dba/scripts/ck_tbsp.sh > /dev/null 2>&1
*          5 * * 0-6 /dba/scripts/invalid_object_alert.sh > /dev/null 2>&1
0,20,40 7-17 * * 1-5 /dba/scripts/deadlock_alert.sh > /dev/null 2>&1
Now my DBA friends, you can have more uninterrupted sleep at night. You may  also have time for more important things such as performance tuning.
References
  • Unix in a Nutshell, O'Reilly & Associates, Inc.;
  • “Using  Oracle9i Application Server to Build Your Web-Based Database Monitoring Tool,”  Daniel T. Liu; Select Magazine - November 2001 Volume 8, No. 1;
  • “Net8:  A Step-by-Step Setup of Oracle Names Server,” Daniel T. Liu; Oracle  Open World 2000, Paper#271.
I would also like to acknowledge the assistance of Johnny Wedekind of  ADP, Ann Collins, Larry Bailey, Husam Tomeh and Archana Sharma of  FARES.
--
Daniel Liu is a  senior Oracle Database Administrator at First American Real Estate Solutions in  Anaheim, CA, and co-author of Oracle  Database 10g New Features. His expertise includes Oracle  database administration, performance tuning, Oracle networking, and Oracle  Application Server. As an Oracle Certified Professional, he taught Oracle  certified DBA classes and IOUG University Seminar. Daniel has published articles  with DBAzine, Oracle Internals, and SELECT Journal. Daniel holds a Master of  Science degree in computer science from Northern Illinois University.

All companies and product names are trademarks or registered  trademarks of the respective owners. Please report errors in this article to the  author. Neither FARES nor the author warrants that this document is  error-free.